package graphql.schema.idl;

import graphql.PublicApi;
import graphql.Scalars;
import graphql.language.ScalarTypeDefinition;
import graphql.schema.GraphQLScalarType;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Info on all the standard scalar objects provided by graphql-java
 */
@PublicApi
public class ScalarInfo {

    /**
     * A list of the built-in scalar types as defined by the graphql specification
     */
    public static final List<GraphQLScalarType> GRAPHQL_SPECIFICATION_SCALARS = new ArrayList<>();

    /**
     * A map of scalar type definitions provided by graphql-java
     */
    public static final Map<String, ScalarTypeDefinition> GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS = new LinkedHashMap<>();

    static {
        GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLInt);
        GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLFloat);
        GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLString);
        GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLBoolean);
        GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLID);
    }

    static {
        // graphql standard scalars
        GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put("Int", ScalarTypeDefinition.newScalarTypeDefinition().name("Int").build());
        GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put("Float", ScalarTypeDefinition.newScalarTypeDefinition().name("Float").build());
        GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put("String", ScalarTypeDefinition.newScalarTypeDefinition().name("String").build());
        GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put("Boolean", ScalarTypeDefinition.newScalarTypeDefinition().name("Boolean").build());
        GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put("ID", ScalarTypeDefinition.newScalarTypeDefinition().name("ID").build());

    }

    /**
     * Returns true if the scalar type is a scalar that is specified by the graphql specification
     *
     * @param scalarTypeName the name of the scalar type in question
     *
     * @return true if the scalar type is specified by the graphql specification
     */
    public static boolean isGraphqlSpecifiedScalar(String scalarTypeName) {
        return inList(GRAPHQL_SPECIFICATION_SCALARS, scalarTypeName);
    }

    /**
     * Returns true if the scalar type is a scalar that is specified by the graphql specification
     *
     * @param scalarType the type in question
     *
     * @return true if the scalar type is specified by the graphql specification
     */
    public static boolean isGraphqlSpecifiedScalar(GraphQLScalarType scalarType) {
        return inList(GRAPHQL_SPECIFICATION_SCALARS, scalarType.getName());
    }

    private static boolean inList(List<GraphQLScalarType> scalarList, String scalarTypeName) {
        return scalarList.stream().anyMatch(sc -> sc.getName().equals(scalarTypeName));
    }

}

@@ -22,16 +22,111 @@
 a.idl;%0A%0A
+import com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0A
 import g
@@ -259,68 +259,8 @@
 e;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.LinkedHashMap;%0A
 impo
@@ -598,290 +598,38 @@
 S = 
-new ArrayList%3C%3E();%0A%0A    /**%0A     * A map of scalar type definitions provided by graphql-java%0A     */%0A    public static final Map%3CString, ScalarTypeDefinition%3E GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS = new LinkedHashMap%3C%3E();%0A%0A    static %7B%0A        GRAPHQL_SPECIFICATION_SCALARS.add(
+ImmutableList.of(%0A            
 Scal
@@ -642,18 +642,17 @@
 aphQLInt
-);
+,
 %0A       
@@ -656,42 +656,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS.add(
+    
 Scal
@@ -676,18 +676,17 @@
 hQLFloat
-);
+,
 %0A       
@@ -690,42 +690,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS.add(
+    
 Scal
@@ -711,18 +711,17 @@
 QLString
-);
+,
 %0A       
@@ -725,42 +725,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS.add(
+    
 Scal
@@ -747,18 +747,17 @@
 LBoolean
-);
+,
 %0A       
@@ -761,42 +761,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS.add(
+    
 Scal
@@ -785,71 +785,147 @@
 D);%0A
+%0A
     
-%7D%0A%0A    static %7B%0A        // graphql standard scalars%0A       
+/**%0A     * A map of scalar type definitions provided by graphql-java%0A     */%0A    public static final Map%3CString, ScalarTypeDefinition%3E
  GRA
@@ -962,21 +962,48 @@
 INITIONS
-.put(
+ = ImmutableMap.of(%0A            
 %22Int%22, S
@@ -1059,34 +1059,33 @@
 e(%22Int%22).build()
-);
+,
 %0A        GRAPHQL
@@ -1081,54 +1081,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put(
+    
 %22Flo
@@ -1150,34 +1150,33 @@
 %22Float%22).build()
-);
+,
 %0A        GRAPHQL
@@ -1172,54 +1172,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put(
+    
 %22Str
@@ -1243,34 +1243,33 @@
 String%22).build()
-);
+,
 %0A        GRAPHQL
@@ -1265,54 +1265,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put(
+    
 %22Boo
@@ -1346,18 +1346,17 @@
 .build()
-);
+,
 %0A       
@@ -1360,54 +1360,12 @@
     
-GRAPHQL_SPECIFICATION_SCALARS_DEFINITIONS.put(
+    
 %22ID%22
@@ -1435,23 +1435,16 @@
 ld());%0A%0A
-    %7D%0A%0A
     /**%0A

Make public static fields immutable in ScalarInfo (#2770)