Skip to content

Commit ff3865b

Browse files
authored
Merge pull request #53 from rabbitvirus/constants-fix
Constants and instantiation problems fix
2 parents a70541e + 20ac321 commit ff3865b

22 files changed

+105
-66
lines changed

src/main/java/graphql/scalars/ExtendedScalars.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class ExtendedScalars {
4343
* @see java.time.OffsetDateTime
4444
* @see java.time.ZonedDateTime
4545
*/
46-
public static GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;
46+
public static final GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;
4747

4848
/**
4949
* An RFC-3339 compliant date scalar that accepts string values like `1996-12-19` and produces
@@ -56,7 +56,7 @@ public class ExtendedScalars {
5656
*
5757
* @see java.time.LocalDate
5858
*/
59-
public static GraphQLScalarType Date = DateScalar.INSTANCE;
59+
public static final GraphQLScalarType Date = DateScalar.INSTANCE;
6060
/**
6161
* An RFC-3339 compliant time scalar that accepts string values like `6:39:57-08:00` and produces
6262
* `java.time.OffsetTime` objects at runtime.
@@ -68,7 +68,7 @@ public class ExtendedScalars {
6868
*
6969
* @see java.time.OffsetTime
7070
*/
71-
public static GraphQLScalarType Time = TimeScalar.INSTANCE;
71+
public static final GraphQLScalarType Time = TimeScalar.INSTANCE;
7272

7373
/**
7474
* A 24-hour local time scalar that accepts strings like `hh:mm:ss` and `hh:mm:ss.sss` and produces
@@ -79,7 +79,7 @@ public class ExtendedScalars {
7979
*
8080
* @see java.time.LocalTime
8181
*/
82-
public static GraphQLScalarType LocalTime = GraphQLScalarType.newScalar()
82+
public static final GraphQLScalarType LocalTime = GraphQLScalarType.newScalar()
8383
.name("LocalTime")
8484
.description("24-hour clock time value string in the format `hh:mm:ss` or `hh:mm:ss.sss`.")
8585
.coercing(new LocalTimeCoercing())
@@ -108,7 +108,7 @@ public class ExtendedScalars {
108108
*
109109
* @see #Json
110110
*/
111-
public static GraphQLScalarType Object = ObjectScalar.INSTANCE;
111+
public static final GraphQLScalarType Object = ObjectScalar.INSTANCE;
112112

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

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

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

141141
/**
142142
* A UUID scalar that accepts a universally unique identifier and produces {@link
@@ -149,50 +149,50 @@ public class ExtendedScalars {
149149
*
150150
* @see graphql.Scalars#GraphQLInt
151151
*/
152-
public static GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
152+
public static final GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
153153
/**
154154
* An `Int` scalar that MUST be less than zero
155155
*
156156
* @see graphql.Scalars#GraphQLInt
157157
*/
158-
public static GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
158+
public static final GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
159159
/**
160160
* An `Int` scalar that MUST be less than or equal to zero
161161
*
162162
* @see graphql.Scalars#GraphQLInt
163163
*/
164-
public static GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
164+
public static final GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
165165
/**
166166
* An `Int` scalar that MUST be greater than or equal to zero
167167
*
168168
* @see graphql.Scalars#GraphQLInt
169169
*/
170-
public static GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;
170+
public static final GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;
171171

172172
/**
173173
* An `Float` scalar that MUST be greater than zero
174174
*
175175
* @see graphql.Scalars#GraphQLFloat
176176
*/
177-
public static GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
177+
public static final GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
178178
/**
179179
* An `Float` scalar that MUST be less than zero
180180
*
181181
* @see graphql.Scalars#GraphQLFloat
182182
*/
183-
public static GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
183+
public static final GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
184184
/**
185185
* An `Float` scalar that MUST be less than or equal to zero
186186
*
187187
* @see graphql.Scalars#GraphQLFloat
188188
*/
189-
public static GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
189+
public static final GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
190190
/**
191191
* An `Float` scalar that MUST be greater than or equal to zero
192192
*
193193
* @see graphql.Scalars#GraphQLFloat
194194
*/
195-
public static GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;
195+
public static final GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;
196196

197197

198198
/**

src/main/java/graphql/scalars/alias/AliasedScalar.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
* Access this via {@link graphql.scalars.ExtendedScalars#newAliasedScalar(String)}
1616
*/
1717
@Internal
18-
public class AliasedScalar {
18+
public final class AliasedScalar {
19+
20+
private AliasedScalar() {}
1921

2022
/**
2123
* A builder for {@link graphql.scalars.alias.AliasedScalar}

src/main/java/graphql/scalars/datetime/DateScalar.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
* Access this via {@link graphql.scalars.ExtendedScalars#Date}
2323
*/
2424
@Internal
25-
public class DateScalar {
25+
public final class DateScalar {
2626

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

29-
public static GraphQLScalarType INSTANCE;
29+
public static final GraphQLScalarType INSTANCE;
30+
31+
private DateScalar() {}
3032

3133
static {
3234
Coercing<LocalDate, String> coercing = new Coercing<LocalDate, String>() {
@@ -43,7 +45,7 @@ public String serialize(Object input) throws CoercingSerializeException {
4345
);
4446
}
4547
try {
46-
return dateFormatter.format(temporalAccessor);
48+
return DATE_FORMATTER.format(temporalAccessor);
4749
} catch (DateTimeException e) {
4850
throw new CoercingSerializeException(
4951
"Unable to turn TemporalAccessor into full date because of : '" + e.getMessage() + "'."
@@ -90,7 +92,7 @@ public Value<?> valueToLiteral(Object input) {
9092

9193
private LocalDate parseLocalDate(String s, Function<String, RuntimeException> exceptionMaker) {
9294
try {
93-
TemporalAccessor temporalAccessor = dateFormatter.parse(s);
95+
TemporalAccessor temporalAccessor = DATE_FORMATTER.parse(s);
9496
return LocalDate.from(temporalAccessor);
9597
} catch (DateTimeParseException e) {
9698
throw exceptionMaker.apply("Invalid RFC3339 full date value : '" + s + "'. because of : '" + e.getMessage() + "'");

src/main/java/graphql/scalars/datetime/DateTimeScalar.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
* Access this via {@link graphql.scalars.ExtendedScalars#DateTime}
2323
*/
2424
@Internal
25-
public class DateTimeScalar {
25+
public final class DateTimeScalar {
2626

27-
public static GraphQLScalarType INSTANCE;
27+
public static final GraphQLScalarType INSTANCE;
28+
29+
private DateTimeScalar() {}
2830

2931
static {
3032
Coercing<OffsetDateTime, String> coercing = new Coercing<OffsetDateTime, String>() {

src/main/java/graphql/scalars/datetime/LocalTimeCoercing.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class LocalTimeCoercing implements Coercing<LocalTime, String> {
1919

20-
private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_LOCAL_TIME;
20+
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ISO_LOCAL_TIME;
2121

2222
@Override
2323
public String serialize(final Object input) throws CoercingSerializeException {
@@ -32,7 +32,7 @@ public String serialize(final Object input) throws CoercingSerializeException {
3232
);
3333
}
3434
try {
35-
return dateFormatter.format(temporalAccessor);
35+
return DATE_FORMATTER.format(temporalAccessor);
3636
} catch (DateTimeException e) {
3737
throw new CoercingSerializeException(
3838
"Unable to turn TemporalAccessor into full time because of : '" + e.getMessage() + "'."
@@ -73,7 +73,7 @@ public LocalTime parseLiteral(final Object input) throws CoercingParseLiteralExc
7373

7474
private static LocalTime parseTime(String s, Function<String, RuntimeException> exceptionMaker) {
7575
try {
76-
TemporalAccessor temporalAccessor = dateFormatter.parse(s);
76+
TemporalAccessor temporalAccessor = DATE_FORMATTER.parse(s);
7777
return LocalTime.from(temporalAccessor);
7878
} catch (DateTimeParseException e) {
7979
throw exceptionMaker.apply("Invalid local time value : '" + s + "'. because of : '" + e.getMessage() + "'");

src/main/java/graphql/scalars/datetime/TimeScalar.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
* Access this via {@link graphql.scalars.ExtendedScalars#Time}
2323
*/
2424
@Internal
25-
public class TimeScalar {
25+
public final class TimeScalar {
2626

27-
private final static DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_OFFSET_TIME;
27+
private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_OFFSET_TIME;
2828

29-
public static GraphQLScalarType INSTANCE;
29+
public static final GraphQLScalarType INSTANCE;
30+
31+
private TimeScalar() {}
3032

3133
static {
3234
Coercing<OffsetTime, String> coercing = new Coercing<OffsetTime, String>() {

src/main/java/graphql/scalars/java/JavaPrimitives.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
* Access these via {@link graphql.scalars.ExtendedScalars}
2020
*/
2121
@Internal
22-
public class JavaPrimitives {
22+
public final class JavaPrimitives {
23+
24+
private JavaPrimitives() {}
2325

2426
private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
2527
private static final BigInteger LONG_MIN = BigInteger.valueOf(Long.MIN_VALUE);

src/main/java/graphql/scalars/locale/LocaleScalar.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
* Access this via {@link graphql.scalars.ExtendedScalars#Locale}
1818
*/
1919
@Internal
20-
public class LocaleScalar {
20+
public final class LocaleScalar {
2121

22-
public static GraphQLScalarType INSTANCE;
22+
private LocaleScalar() {}
23+
24+
public static final GraphQLScalarType INSTANCE;
2325

2426
static {
2527
Coercing<Locale, String> coercing = new Coercing<Locale, String>() {

src/main/java/graphql/scalars/numeric/FloatCoercing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@Internal
1515
abstract class FloatCoercing implements Coercing<Double, Double> {
1616

17-
abstract protected Double check(Double d, Function<String, RuntimeException> exceptionMaker);
17+
protected abstract Double check(Double d, Function<String, RuntimeException> exceptionMaker);
1818

1919
@Override
2020
public Double serialize(Object input) throws CoercingSerializeException {

src/main/java/graphql/scalars/numeric/IntCoercing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@Internal
1515
abstract class IntCoercing implements Coercing<Integer, Integer> {
1616

17-
abstract protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker);
17+
protected abstract Integer check(Integer i, Function<String, RuntimeException> exceptionMaker);
1818

1919
@Override
2020
public Integer serialize(Object input) throws CoercingSerializeException {

src/main/java/graphql/scalars/numeric/NegativeFloatScalar.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
* Access this via {@link graphql.scalars.ExtendedScalars#NegativeFloat}
1010
*/
1111
@Internal
12-
public class NegativeFloatScalar {
12+
public final class NegativeFloatScalar {
1313

14-
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
14+
private NegativeFloatScalar() {}
15+
16+
public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
1517
.name("NegativeFloat")
1618
.description("An Float scalar that must be a negative value")
1719
.coercing(new FloatCoercing() {
1820
@Override
1921
protected Double check(Double d, Function<String, RuntimeException> exceptionMaker) {
20-
if (!(d < 0)) {
22+
if (d >= 0.0d) {
2123
throw exceptionMaker.apply("The value must be a negative value");
2224
}
2325
return d;

src/main/java/graphql/scalars/numeric/NegativeIntScalar.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
* Access this via {@link graphql.scalars.ExtendedScalars#NegativeInt}
1010
*/
1111
@Internal
12-
public class NegativeIntScalar {
12+
public final class NegativeIntScalar {
1313

14-
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
14+
private NegativeIntScalar() {}
15+
16+
public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
1517
.name("NegativeInt")
1618
.description("An Int scalar that must be a negative value")
1719
.coercing(new IntCoercing() {
1820
@Override
1921
protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker) {
20-
if (!(i < 0)) {
22+
if (i >= 0) {
2123
throw exceptionMaker.apply("The value must be a negative integer");
2224
}
2325
return i;

src/main/java/graphql/scalars/numeric/NonNegativeFloatScalar.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
* Access this via {@link graphql.scalars.ExtendedScalars#NonNegativeFloat}
1010
*/
1111
@Internal
12-
public class NonNegativeFloatScalar {
12+
public final class NonNegativeFloatScalar {
1313

14-
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
14+
private NonNegativeFloatScalar() {}
15+
16+
public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
1517
.name("NonNegativeFloat")
1618
.description("An Float scalar that must be greater than or equal to zero")
1719
.coercing(new FloatCoercing() {
1820
@Override
1921
protected Double check(Double d, Function<String, RuntimeException> exceptionMaker) {
20-
if (!(d >= 0)) {
22+
if (d < 0.0d) {
2123
throw exceptionMaker.apply("The value must be greater than or equal to zero");
2224
}
2325
return d;

src/main/java/graphql/scalars/numeric/NonNegativeIntScalar.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
* Access this via {@link graphql.scalars.ExtendedScalars#NonNegativeInt}
1010
*/
1111
@Internal
12-
public class NonNegativeIntScalar {
12+
public final class NonNegativeIntScalar {
1313

14-
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
14+
private NonNegativeIntScalar() {}
15+
16+
public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
1517
.name("NonNegativeInt")
1618
.description("An Int scalar that must be greater than or equal to zero")
1719
.coercing(new IntCoercing() {
1820
@Override
1921
protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker) {
20-
if (!(i >= 0)) {
22+
if (i < 0) {
2123
throw exceptionMaker.apply("The value must be greater than or equal to zero");
2224
}
2325
return i;

src/main/java/graphql/scalars/numeric/NonPositiveFloatScalar.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
* Access this via {@link graphql.scalars.ExtendedScalars#NonPositiveFloat}
1010
*/
1111
@Internal
12-
public class NonPositiveFloatScalar {
13-
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
12+
public final class NonPositiveFloatScalar {
13+
14+
private NonPositiveFloatScalar() {}
15+
16+
public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
1417
.name("NonPositiveFloat").description("An Float scalar that must be less than or equal to zero")
1518
.coercing(new FloatCoercing() {
1619
@Override
1720
protected Double check(Double d, Function<String, RuntimeException> exceptionMaker) {
18-
if (!(d <= 0)) {
21+
if (d > 0) {
1922
throw exceptionMaker.apply("The value must be less than or equal to zero");
2023
}
2124
return d;

src/main/java/graphql/scalars/numeric/NonPositiveIntScalar.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
* Access this via {@link graphql.scalars.ExtendedScalars#NonPositiveInt}
1010
*/
1111
@Internal
12-
public class NonPositiveIntScalar {
13-
public static GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
12+
public final class NonPositiveIntScalar {
13+
14+
private NonPositiveIntScalar() {}
15+
16+
public static final GraphQLScalarType INSTANCE = GraphQLScalarType.newScalar()
1417
.name("NonPositiveInt")
1518
.description("An Int scalar that must be less than or equal to zero")
1619
.coercing(new IntCoercing() {
1720
@Override
1821
protected Integer check(Integer i, Function<String, RuntimeException> exceptionMaker) {
19-
if (!(i <= 0)) {
22+
if (i > 0) {
2023
throw exceptionMaker.apply("The value must be less than or equal to zero");
2124
}
2225
return i;

0 commit comments

Comments
 (0)