package graphql.schema.idl;

import graphql.Directives;
import graphql.PublicApi;
import graphql.schema.GraphQLDirective;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
 * Info on all the directives provided by graphql specification
 */
@PublicApi
public class DirectiveInfo {

    /**
     * A set of directives which provided by graphql specification
     */
    public static final Set<GraphQLDirective> GRAPHQL_SPECIFICATION_DIRECTIVES = new LinkedHashSet<>();

    /**
     * A map from directive name to directive which provided by specification
     */
    public static final Map<String, GraphQLDirective> GRAPHQL_SPECIFICATION_DIRECTIVE_MAP = new LinkedHashMap<>();

    static {
        GRAPHQL_SPECIFICATION_DIRECTIVES.add(Directives.IncludeDirective);
        GRAPHQL_SPECIFICATION_DIRECTIVES.add(Directives.SkipDirective);
        GRAPHQL_SPECIFICATION_DIRECTIVES.add(Directives.DeprecatedDirective);
        GRAPHQL_SPECIFICATION_DIRECTIVES.add(Directives.SpecifiedByDirective);
    }

    static {
        GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(Directives.IncludeDirective.getName(), Directives.IncludeDirective);
        GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(Directives.SkipDirective.getName(), Directives.SkipDirective);
        GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(Directives.DeprecatedDirective.getName(), Directives.DeprecatedDirective);
        GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(Directives.SpecifiedByDirective.getName(), Directives.SpecifiedByDirective);
    }


    /**
     * Returns true if a directive with provided directiveName has been defined in graphql specification
     *
     * @param directiveName the name of directive in question
     *
     * @return true if the directive provided by graphql specification, and false otherwise
     */
    public static boolean isGraphqlSpecifiedDirective(String directiveName) {
        return GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.containsKey(directiveName);
    }

    /**
     * Returns true if the provided directive has been defined in graphql specification
     *
     * @param graphQLDirective the directive in question
     *
     * @return true if the directive provided by graphql specification, and false otherwise
     */
    public static boolean isGraphqlSpecifiedDirective(GraphQLDirective graphQLDirective) {
        return isGraphqlSpecifiedDirective(graphQLDirective.getName());
    }


}

@@ -22,16 +22,110 @@
 a.idl;%0A%0A
+import com.google.common.collect.ImmutableMap;%0Aimport com.google.common.collect.ImmutableSet;%0A
 import g
@@ -214,72 +214,8 @@
 e;%0A%0A
-import java.util.LinkedHashMap;%0Aimport java.util.LinkedHashSet;%0A
 impo
@@ -536,300 +536,116 @@
 S = 
-new LinkedHashSet%3C%3E();%0A
+ImmutableSet.of(
 %0A    
-/**%0A
      
-* A map from directive name to directive which provided by specification%0A     */%0A    public static final Map%3CString, GraphQLDirective%3E GRAPHQL_SPECIFICATION_DIRECTIVE_MAP = new LinkedHashMap%3C%3E();%0A%0A    static %7B%0A        GRAPHQL_SPECIFICATION_DIRECTIVES.add(
+   Directives.IncludeDirective,%0A            Directives.SkipDirective,%0A            
 Dire
@@ -643,39 +643,42 @@
      Directives.
-Include
+Deprecated
 Directive);%0A    
@@ -662,34 +662,33 @@
 recatedDirective
-);
+,
 %0A        GRAPHQL
@@ -684,45 +684,12 @@
     
-GRAPHQL_SPECIFICATION_DIRECTIVES.add(
+    
 Dire
@@ -688,35 +688,42 @@
     Directives.S
-kip
+pecifiedBy
 Directive);%0A    
@@ -722,192 +722,156 @@
 e);%0A
+%0A
     
-    GRAPHQL_SPECIFICATION_DIRECTIVES.add(Directives.DeprecatedDirective);%0A        GRAPHQL_SPECIFICATION_DIRECTIVES.add(Directives.SpecifiedByDirective);
+/**%0A     * A map from directive name to directive which provided by specification
 %0A    
-%7D%0A
+ */
 %0A    
-static %7B%0A       
+public static final Map%3CString, GraphQLDirective%3E
  GRA
@@ -894,37 +894,64 @@
 ON_DIRECTIVE_MAP
-.put(
+ = ImmutableMap.of(%0A            
 Directives.Inclu
@@ -992,34 +992,33 @@
 IncludeDirective
-);
+,
 %0A        GRAPHQL
@@ -1014,48 +1014,12 @@
     
-GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(
+    
 Dire
@@ -1066,34 +1066,33 @@
 es.SkipDirective
-);
+,
 %0A        GRAPHQL
@@ -1088,48 +1088,12 @@
     
-GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(
+    
 Dire
@@ -1156,26 +1156,25 @@
 tedDirective
-);
+,
 %0A        GRA
@@ -1174,48 +1174,12 @@
     
-GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.put(
+    
 Dire
@@ -1251,23 +1251,16 @@
 ctive);%0A
-    %7D%0A%0A
 %0A    /**

Make public static fields immutable in DirectiveInfo (#2781)