Skip to content

Commit

Permalink
Merge pull request #53 from rabbitvirus/constants-fix
Browse files Browse the repository at this point in the history
Constants and instantiation problems fix
  • Loading branch information
bbakerman committed Apr 14, 2022
2 parents a70541e + 20ac321 commit ff3865b
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 66 deletions.
32 changes: 16 additions & 16 deletions src/main/java/graphql/scalars/ExtendedScalars.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ExtendedScalars {
* @see java.time.OffsetDateTime
* @see java.time.ZonedDateTime
*/
public static GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;
public static final GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;

/**
* An RFC-3339 compliant date scalar that accepts string values like `1996-12-19` and produces
Expand All @@ -56,7 +56,7 @@ public class ExtendedScalars {
*
* @see java.time.LocalDate
*/
public static GraphQLScalarType Date = DateScalar.INSTANCE;
public static final GraphQLScalarType Date = DateScalar.INSTANCE;
/**
* An RFC-3339 compliant time scalar that accepts string values like `6:39:57-08:00` and produces
* `java.time.OffsetTime` objects at runtime.
Expand All @@ -68,7 +68,7 @@ public class ExtendedScalars {
*
* @see java.time.OffsetTime
*/
public static GraphQLScalarType Time = TimeScalar.INSTANCE;
public static final GraphQLScalarType Time = TimeScalar.INSTANCE;

/**
* A 24-hour local time scalar that accepts strings like `hh:mm:ss` and `hh:mm:ss.sss` and produces
Expand All @@ -79,7 +79,7 @@ public class ExtendedScalars {
*
* @see java.time.LocalTime
*/
public static GraphQLScalarType LocalTime = GraphQLScalarType.newScalar()
public static final GraphQLScalarType LocalTime = GraphQLScalarType.newScalar()
.name("LocalTime")
.description("24-hour clock time value string in the format `hh:mm:ss` or `hh:mm:ss.sss`.")
.coercing(new LocalTimeCoercing())
Expand Down Expand Up @@ -108,7 +108,7 @@ public class ExtendedScalars {
*
* @see #Json
*/
public static GraphQLScalarType Object = ObjectScalar.INSTANCE;
public static final GraphQLScalarType Object = ObjectScalar.INSTANCE;

/**
* A synonym class for the {@link #Object} scalar, since some people prefer their SDL to look like the following :
Expand All @@ -125,18 +125,18 @@ public class ExtendedScalars {
*
* @see graphql.scalars.ExtendedScalars#Object
*/
public static GraphQLScalarType Json = JsonScalar.INSTANCE;
public static final GraphQLScalarType Json = JsonScalar.INSTANCE;

/**
* A URL scalar that accepts URL strings and produces {@link java.net.URL} objects at runtime
*/
public static GraphQLScalarType Url = UrlScalar.INSTANCE;
public static final GraphQLScalarType Url = UrlScalar.INSTANCE;

/**
* A Locale scalar that accepts a IETF BCP 47 language tag string and produces {@link
* java.util.Locale} objects at runtime.
*/
public static GraphQLScalarType Locale = LocaleScalar.INSTANCE;
public static final GraphQLScalarType Locale = LocaleScalar.INSTANCE;

/**
* A UUID scalar that accepts a universally unique identifier and produces {@link
Expand All @@ -149,50 +149,50 @@ public class ExtendedScalars {
*
* @see graphql.Scalars#GraphQLInt
*/
public static GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
public static final GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
/**
* An `Int` scalar that MUST be less than zero
*
* @see graphql.Scalars#GraphQLInt
*/
public static GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
public static final GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
/**
* An `Int` scalar that MUST be less than or equal to zero
*
* @see graphql.Scalars#GraphQLInt
*/
public static GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
public static final GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
/**
* An `Int` scalar that MUST be greater than or equal to zero
*
* @see graphql.Scalars#GraphQLInt
*/
public static GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;
public static final GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;

/**
* An `Float` scalar that MUST be greater than zero
*
* @see graphql.Scalars#GraphQLFloat
*/
public static GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
public static final GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
/**
* An `Float` scalar that MUST be less than zero
*
* @see graphql.Scalars#GraphQLFloat
*/
public static GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
public static final GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
/**
* An `Float` scalar that MUST be less than or equal to zero
*
* @see graphql.Scalars#GraphQLFloat
*/
public static GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
public static final GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
/**
* An `Float` scalar that MUST be greater than or equal to zero
*
* @see graphql.Scalars#GraphQLFloat
*/
public static GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;
public static final GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;


/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/graphql/scalars/alias/AliasedScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
* Access this via {@link graphql.scalars.ExtendedScalars#newAliasedScalar(String)}
*/
@Internal
public class AliasedScalar {
public final class AliasedScalar {

private AliasedScalar() {}

/**
* A builder for {@link graphql.scalars.alias.AliasedScalar}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/graphql/scalars/datetime/DateScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
* Access this via {@link graphql.scalars.ExtendedScalars#Date}
*/
@Internal
public class DateScalar {
public final class DateScalar {

private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");

public static GraphQLScalarType INSTANCE;
public static final GraphQLScalarType INSTANCE;

private DateScalar() {}

static {
Coercing<LocalDate, String> coercing = new Coercing<LocalDate, String>() {
Expand All @@ -43,7 +45,7 @@ public String serialize(Object input) throws CoercingSerializeException {
);
}
try {
return dateFormatter.format(temporalAccessor);
return DATE_FORMATTER.format(temporalAccessor);
} catch (DateTimeException e) {
throw new CoercingSerializeException(
"Unable to turn TemporalAccessor into full date because of : '" + e.getMessage() + "'."
Expand Down Expand Up @@ -90,7 +92,7 @@ public Value<?> valueToLiteral(Object input) {

private LocalDate parseLocalDate(String s, Function<String, RuntimeException> exceptionMaker) {
try {
TemporalAccessor temporalAccessor = dateFormatter.parse(s);
TemporalAccessor temporalAccessor = DATE_FORMATTER.parse(s);
return LocalDate.from(temporalAccessor);
} catch (DateTimeParseException e) {
throw exceptionMaker.apply("Invalid RFC3339 full date value : '" + s + "'. because of : '" + e.getMessage() + "'");
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/graphql/scalars/datetime/DateTimeScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
* Access this via {@link graphql.scalars.ExtendedScalars#DateTime}
*/
@Internal
public class DateTimeScalar {
public final class DateTimeScalar {

public static GraphQLScalarType INSTANCE;
public static final GraphQLScalarType INSTANCE;

private DateTimeScalar() {}

static {
Coercing<OffsetDateTime, String> coercing = new Coercing<OffsetDateTime, String>() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/graphql/scalars/datetime/LocalTimeCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class LocalTimeCoercing implements Coercing<LocalTime, String> {

private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_LOCAL_TIME;
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ISO_LOCAL_TIME;

@Override
public String serialize(final Object input) throws CoercingSerializeException {
Expand All @@ -32,7 +32,7 @@ public String serialize(final Object input) throws CoercingSerializeException {
);
}
try {
return dateFormatter.format(temporalAccessor);
return DATE_FORMATTER.format(temporalAccessor);
} catch (DateTimeException e) {
throw new CoercingSerializeException(
"Unable to turn TemporalAccessor into full time because of : '" + e.getMessage() + "'."
Expand Down Expand Up @@ -73,7 +73,7 @@ public LocalTime parseLiteral(final Object input) throws CoercingParseLiteralExc

private static LocalTime parseTime(String s, Function<String, RuntimeException> exceptionMaker) {
try {
TemporalAccessor temporalAccessor = dateFormatter.parse(s);
TemporalAccessor temporalAccessor = DATE_FORMATTER.parse(s);
return LocalTime.from(temporalAccessor);
} catch (DateTimeParseException e) {
throw exceptionMaker.apply("Invalid local time value : '" + s + "'. because of : '" + e.getMessage() + "'");
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/graphql/scalars/datetime/TimeScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
* Access this via {@link graphql.scalars.ExtendedScalars#Time}
*/
@Internal
public class TimeScalar {
public final class TimeScalar {

private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_OFFSET_TIME;
private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_OFFSET_TIME;

public static GraphQLScalarType INSTANCE;
public static final GraphQLScalarType INSTANCE;

private TimeScalar() {}

static {
Coercing<OffsetTime, String> coercing = new Coercing<OffsetTime, String>() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/graphql/scalars/java/JavaPrimitives.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* Access these via {@link graphql.scalars.ExtendedScalars}
*/
@Internal
public class JavaPrimitives {
public final class JavaPrimitives {

private JavaPrimitives() {}

private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
private static final BigInteger LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/graphql/scalars/locale/LocaleScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
* Access this via {@link graphql.scalars.ExtendedScalars#Locale}
*/
@Internal
public class LocaleScalar {
public final class LocaleScalar {

public static GraphQLScalarType INSTANCE;
private LocaleScalar() {}

public static final GraphQLScalarType INSTANCE;

static {
Coercing<Locale, String> coercing = new Coercing<Locale, String>() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/scalars/numeric/FloatCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Internal
abstract class FloatCoercing implements Coercing<Double, Double> {

abstract protected Double check(Double d, Function<String, RuntimeException> exceptionMaker);
protected abstract Double check(Double d, Function<String, RuntimeException> exceptionMaker);

@Override
public Double serialize(Object input) throws CoercingSerializeException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/scalars/numeric/IntCoercing.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Internal
abstract class IntCoercing implements Coercing<Integer, Integer> {

abstract protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker);
protected abstract Integer check(Integer i, Function<String, RuntimeException> exceptionMaker);

@Override
public Integer serialize(Object input) throws CoercingSerializeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
* Access this via {@link graphql.scalars.ExtendedScalars#NegativeFloat}
*/
@Internal
public class NegativeFloatScalar {
public final class NegativeFloatScalar {

public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
private NegativeFloatScalar() {}

public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
.name("NegativeFloat")
.description("An Float scalar that must be a negative value")
.coercing(new FloatCoercing() {
@Override
protected Double check(Double d, Function<String, RuntimeException> exceptionMaker) {
if (!(d < 0)) {
if (d >= 0.0d) {
throw exceptionMaker.apply("The value must be a negative value");
}
return d;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/graphql/scalars/numeric/NegativeIntScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
* Access this via {@link graphql.scalars.ExtendedScalars#NegativeInt}
*/
@Internal
public class NegativeIntScalar {
public final class NegativeIntScalar {

public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
private NegativeIntScalar() {}

public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
.name("NegativeInt")
.description("An Int scalar that must be a negative value")
.coercing(new IntCoercing() {
@Override
protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker) {
if (!(i < 0)) {
if (i >= 0) {
throw exceptionMaker.apply("The value must be a negative integer");
}
return i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
* Access this via {@link graphql.scalars.ExtendedScalars#NonNegativeFloat}
*/
@Internal
public class NonNegativeFloatScalar {
public final class NonNegativeFloatScalar {

public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
private NonNegativeFloatScalar() {}

public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
.name("NonNegativeFloat")
.description("An Float scalar that must be greater than or equal to zero")
.coercing(new FloatCoercing() {
@Override
protected Double check(Double d, Function<String, RuntimeException> exceptionMaker) {
if (!(d >= 0)) {
if (d < 0.0d) {
throw exceptionMaker.apply("The value must be greater than or equal to zero");
}
return d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
* Access this via {@link graphql.scalars.ExtendedScalars#NonNegativeInt}
*/
@Internal
public class NonNegativeIntScalar {
public final class NonNegativeIntScalar {

public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
private NonNegativeIntScalar() {}

public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
.name("NonNegativeInt")
.description("An Int scalar that must be greater than or equal to zero")
.coercing(new IntCoercing() {
@Override
protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker) {
if (!(i >= 0)) {
if (i < 0) {
throw exceptionMaker.apply("The value must be greater than or equal to zero");
}
return i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
* Access this via {@link graphql.scalars.ExtendedScalars#NonPositiveFloat}
*/
@Internal
public class NonPositiveFloatScalar {
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
public final class NonPositiveFloatScalar {

private NonPositiveFloatScalar() {}

public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
.name("NonPositiveFloat").description("An Float scalar that must be less than or equal to zero")
.coercing(new FloatCoercing() {
@Override
protected Double check(Double d, Function<String, RuntimeException> exceptionMaker) {
if (!(d <= 0)) {
if (d > 0) {
throw exceptionMaker.apply("The value must be less than or equal to zero");
}
return d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
* Access this via {@link graphql.scalars.ExtendedScalars#NonPositiveInt}
*/
@Internal
public class NonPositiveIntScalar {
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
public final class NonPositiveIntScalar {

private NonPositiveIntScalar() {}

public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
.name("NonPositiveInt")
.description("An Int scalar that must be less than or equal to zero")
.coercing(new IntCoercing() {
@Override
protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker) {
if (!(i <= 0)) {
if (i > 0) {
throw exceptionMaker.apply("The value must be less than or equal to zero");
}
return i;
Expand Down
Loading

0 comments on commit ff3865b

Please sign in to comment.