Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package graphql;
import graphql.language.BooleanValue;
import graphql.language.FloatValue;
import graphql.language.IntValue;
import graphql.language.StringValue;
import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
import graphql.schema.CoercingParseValueException;
import graphql.schema.CoercingSerializeException;
import graphql.schema.GraphQLScalarType;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.UUID;
import static graphql.Assert.assertShouldNeverHappen;
/**
* This contains the implementations of the Scalar types that ship with graphql-java. Some are proscribed
* by the graphql specification (Int, Float, String, Boolean and ID) while others are offer because they are common on
* Java platforms.
*
* For more info see http://graphql.org/learn/schema/#scalar-types and more specifically http://facebook.github.io/graphql/#sec-Scalars
*/
public class Scalars {
private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
private static final BigInteger LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE);
private static final BigInteger INT_MAX = BigInteger.valueOf(Integer.MAX_VALUE);
private static final BigInteger INT_MIN = BigInteger.valueOf(Integer.MIN_VALUE);
private static final BigInteger BYTE_MAX = BigInteger.valueOf(Byte.MAX_VALUE);
private static final BigInteger BYTE_MIN = BigInteger.valueOf(Byte.MIN_VALUE);
private static final BigInteger SHORT_MAX = BigInteger.valueOf(Short.MAX_VALUE);
private static final BigInteger SHORT_MIN = BigInteger.valueOf(Short.MIN_VALUE);
private static boolean isNumberIsh(Object input) {
return input instanceof Number || input instanceof String;
}
private static String typeName(Object input) {
if (input == null) {
return "null";
}
return input.getClass().getSimpleName();
}
/**
* This represents the "Int" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-Int
*
* The Int scalar type represents a signed 32‐bit numeric non‐fractional value.
*/
public static final GraphQLScalarType GraphQLInt = new GraphQLScalarType("Int", "Built-in Int", new Coercing() {
private Integer convertImpl(Object input) {
if (input instanceof Integer) {
return (Integer) input;
} else if (isNumberIsh(input)) {
BigDecimal value;
try {
value = new BigDecimal(input.toString());
} catch (NumberFormatException e) {
return null;
}
try {
return value.intValueExact();
} catch (ArithmeticException e) {
return null;
}
} else {
return null;
}
}
@Override
public Integer serialize(Object input) {
Integer result = convertImpl(input);
if (result == null) {
throw new CoercingSerializeException(
"Expected type 'Int' but was '" + typeName(input) + "'."
);
}
return result;
}
@Override
public Integer parseValue(Object input) {
Integer result = convertImpl(input);
if (result == null) {
throw new CoercingParseValueException(
"Expected type 'Int' but was '" + typeName(input) + "'."
);
}
return result;
}
@Override
public Integer parseLiteral(Object input) {
if (!(input instanceof IntValue)) {
throw new CoercingParseLiteralException(
"Expected AST type 'IntValue' but was '" + typeName(input) + "'."
);
}
BigInteger value = ((IntValue) input).getValue();
if (value.compareTo(INT_MIN) < 0 || value.compareTo(INT_MAX) > 0) {
throw new CoercingParseLiteralException(
"Expected value to be in the Integer range but it was '" + value.toString() + "'"
);
}
return value.intValue();
}
});
/**
* This represents the "Float" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-Float
*
* Note: The Float type in GraphQL is equivalent to Double in Java. (double precision IEEE 754)
*/
public static final GraphQLScalarType GraphQLFloat = new GraphQLScalarType("Float", "Built-in Float", new Coercing() {
private Double convertImpl(Object input) {
if (isNumberIsh(input)) {
BigDecimal value;
try {
value = new BigDecimal(input.toString());
} catch (NumberFormatException e) {
return null;
}
return value.doubleValue();
} else {
return null;
}
}
@Override
public Double serialize(Object input) {
Double result = convertImpl(input);
if (result == null) {
throw new CoercingSerializeException(
"Expected type 'Float' but was '" + typeName(input) + "'."
);
}
return result;
}
@Override
public Double parseValue(Object input) {
Double result = convertImpl(input);
if (result == null) {
throw new CoercingParseValueException(
"Expected type 'Float' but was '" + typeName(input) + "'."
);
}
return result;
}
@Override
public Double parseLiteral(Object input) {
if (input instanceof IntValue) {
return ((IntValue) input).getValue().doubleValue();
} else if (input instanceof FloatValue) {
return ((FloatValue) input).getValue().doubleValue();
} else {
throw new CoercingParseLiteralException(
"Expected AST type 'IntValue' or 'FloatValue' but was '" + typeName(input) + "'."
);
}
}
});
/**
* This represents the "String" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-String
*/
public static final GraphQLScalarType GraphQLString = new GraphQLScalarType("String", "Built-in String", new Coercing() {
@Override
public String serialize(Object input) {
return input.toString();
}
@Override
public String parseValue(Object input) {
return serialize(input);
}
@Override
public String parseLiteral(Object input) {
if (!(input instanceof StringValue)) {
throw new CoercingParseLiteralException(
"Expected AST type 'StringValue' but was '" + typeName(input) + "'."
);
}
return ((StringValue) input).getValue();
}
});
/**
* This represents the "Boolean" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-Boolean
*/
public static final GraphQLScalarType GraphQLBoolean = new GraphQLScalarType("Boolean", "Built-in Boolean", new Coercing() {
private Boolean convertImpl(Object input) {
if (input instanceof Boolean) {
return (Boolean) input;
} else if (input instanceof String) {
return Boolean.parseBoolean((String) input);
} else if (isNumberIsh(input)) {
BigDecimal value;
try {
value = new BigDecimal(input.toString());
} catch (NumberFormatException e) {
// this should never happen because String is handled above
return assertShouldNeverHappen();
}
return value.compareTo(BigDecimal.ZERO) != 0;
} else {
return null;
}
}
@Override
public Boolean serialize(Object input) {
Boolean result = convertImpl(input);
if (result == null) {
throw new CoercingSerializeException(
"Expected type 'Boolean' but was '" + typeName(input) + "'."
);
}
return result;
}
@Override
public Boolean parseValue(Object input) {
Boolean result = convertImpl(input);
if (result == null) {
throw new CoercingParseValueException(
"Expected type 'Boolean' but was '" + typeName(input) + "'."
);
}
return result;
}
@Override
public Boolean parseLiteral(Object input) {
if (!(input instanceof BooleanValue)) {
throw new CoercingParseLiteralException(
"Expected AST type 'BooleanValue' but was '" + typeName(input) + "'."
);
}
return ((BooleanValue) input).isValue();
}
});
/**
* This represents the "ID" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-ID
*
* The ID scalar type represents a unique identifier, often used to re-fetch an object or as the key for a cache. The
* ID type is serialized in the same way as a String; however, it is not intended to be human‐readable. While it is
* often numeric, it should always serialize as a String.
*/
public static final GraphQLScalarType GraphQLID = new GraphQLScalarType("ID", "Built-in ID", new Coercing