Skip to content

Commit 20ac321

Browse files
committed
Constants and instantiation problems fix
1 parent c2e844f commit 20ac321

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
@@ -40,7 +40,7 @@ public class ExtendedScalars {
4040
* @see java.time.OffsetDateTime
4141
* @see java.time.ZonedDateTime
4242
*/
43-
public static GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;
43+
public static final GraphQLScalarType DateTime = DateTimeScalar.INSTANCE;
4444

4545
/**
4646
* An RFC-3339 compliant date scalar that accepts string values like `1996-12-19` and produces
@@ -53,7 +53,7 @@ public class ExtendedScalars {
5353
*
5454
* @see java.time.LocalDate
5555
*/
56-
public static GraphQLScalarType Date = DateScalar.INSTANCE;
56+
public static final GraphQLScalarType Date = DateScalar.INSTANCE;
5757
/**
5858
* An RFC-3339 compliant time scalar that accepts string values like `6:39:57-08:00` and produces
5959
* `java.time.OffsetTime` objects at runtime.
@@ -65,7 +65,7 @@ public class ExtendedScalars {
6565
*
6666
* @see java.time.OffsetTime
6767
*/
68-
public static GraphQLScalarType Time = TimeScalar.INSTANCE;
68+
public static final GraphQLScalarType Time = TimeScalar.INSTANCE;
6969

7070
/**
7171
* A 24-hour local time scalar that accepts strings like `hh:mm:ss` and `hh:mm:ss.sss` and produces
@@ -76,7 +76,7 @@ public class ExtendedScalars {
7676
*
7777
* @see java.time.LocalTime
7878
*/
79-
public static GraphQLScalarType LocalTime = GraphQLScalarType.newScalar()
79+
public static final GraphQLScalarType LocalTime = GraphQLScalarType.newScalar()
8080
.name("LocalTime")
8181
.description("24-hour clock time value string in the format `hh:mm:ss` or `hh:mm:ss.sss`.")
8282
.coercing(new LocalTimeCoercing())
@@ -105,7 +105,7 @@ public class ExtendedScalars {
105105
*
106106
* @see #Json
107107
*/
108-
public static GraphQLScalarType Object = ObjectScalar.INSTANCE;
108+
public static final GraphQLScalarType Object = ObjectScalar.INSTANCE;
109109

110110
/**
111111
* A synonym class for the {@link #Object} scalar, since some people prefer their SDL to look like the following :
@@ -122,68 +122,68 @@ public class ExtendedScalars {
122122
*
123123
* @see graphql.scalars.ExtendedScalars#Object
124124
*/
125-
public static GraphQLScalarType Json = JsonScalar.INSTANCE;
125+
public static final GraphQLScalarType Json = JsonScalar.INSTANCE;
126126

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

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

138138
/**
139139
* An `Int` scalar that MUST be greater than zero
140140
*
141141
* @see graphql.Scalars#GraphQLInt
142142
*/
143-
public static GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
143+
public static final GraphQLScalarType PositiveInt = PositiveIntScalar.INSTANCE;
144144
/**
145145
* An `Int` scalar that MUST be less than zero
146146
*
147147
* @see graphql.Scalars#GraphQLInt
148148
*/
149-
public static GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
149+
public static final GraphQLScalarType NegativeInt = NegativeIntScalar.INSTANCE;
150150
/**
151151
* An `Int` scalar that MUST be less than or equal to zero
152152
*
153153
* @see graphql.Scalars#GraphQLInt
154154
*/
155-
public static GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
155+
public static final GraphQLScalarType NonPositiveInt = NonPositiveIntScalar.INSTANCE;
156156
/**
157157
* An `Int` scalar that MUST be greater than or equal to zero
158158
*
159159
* @see graphql.Scalars#GraphQLInt
160160
*/
161-
public static GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;
161+
public static final GraphQLScalarType NonNegativeInt = NonNegativeIntScalar.INSTANCE;
162162

163163
/**
164164
* An `Float` scalar that MUST be greater than zero
165165
*
166166
* @see graphql.Scalars#GraphQLFloat
167167
*/
168-
public static GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
168+
public static final GraphQLScalarType PositiveFloat = PositiveFloatScalar.INSTANCE;
169169
/**
170170
* An `Float` scalar that MUST be less than zero
171171
*
172172
* @see graphql.Scalars#GraphQLFloat
173173
*/
174-
public static GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
174+
public static final GraphQLScalarType NegativeFloat = NegativeFloatScalar.INSTANCE;
175175
/**
176176
* An `Float` scalar that MUST be less than or equal to zero
177177
*
178178
* @see graphql.Scalars#GraphQLFloat
179179
*/
180-
public static GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
180+
public static final GraphQLScalarType NonPositiveFloat = NonPositiveFloatScalar.INSTANCE;
181181
/**
182182
* An `Float` scalar that MUST be greater than or equal to zero
183183
*
184184
* @see graphql.Scalars#GraphQLFloat
185185
*/
186-
public static GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;
186+
public static final GraphQLScalarType NonNegativeFloat = NonNegativeFloatScalar.INSTANCE;
187187

188188

189189
/**

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)