Skip to content

Commit 1df3038

Browse files
committed
null cleanup
1 parent d6d6bad commit 1df3038

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/main/java/com/saasquatch/jsonschemainferrer/JsonSchemaInferrerBuilder.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Objects;
88
import java.util.Set;
99
import javax.annotation.Nonnull;
10-
import javax.annotation.Nullable;
1110
import javax.annotation.concurrent.NotThreadSafe;
1211
import com.saasquatch.jsonschemainferrer.annotations.Beta;
1312

@@ -23,11 +22,9 @@ public final class JsonSchemaInferrerBuilder {
2322
private SpecVersion specVersion = SpecVersion.DRAFT_04;
2423
private IntegerTypePreference integerTypePreference = IntegerTypePreference.IF_ALL;
2524
private IntegerTypeCriterion integerTypeCriterion = IntegerTypeCriteria.nonFloatingPoint();
26-
@Nullable
27-
private List<EnumExtractor> enumExtractors;
25+
private List<EnumExtractor> enumExtractors = Collections.emptyList();
2826
private TitleDescriptionGenerator titleDescriptionGenerator = TitleDescriptionGenerators.noOp();
29-
@Nullable
30-
private List<FormatInferrer> formatInferrers;
27+
private List<FormatInferrer> formatInferrers = Collections.emptyList();
3128
private AdditionalPropertiesPolicy additionalPropertiesPolicy =
3229
AdditionalPropertiesPolicies.noOp();
3330
private RequiredPolicy requiredPolicy = RequiredPolicies.noOp();
@@ -38,8 +35,7 @@ public final class JsonSchemaInferrerBuilder {
3835
private Set<ArrayLengthFeature> arrayLengthFeatures = Collections.emptySet();
3936
private Set<StringLengthFeature> stringLengthFeatures = Collections.emptySet();
4037
private Set<NumberRangeFeature> numberRangeFeatures = Collections.emptySet();
41-
@Nullable
42-
private List<GenericSchemaFeature> genericSchemaFeatures;
38+
private List<GenericSchemaFeature> genericSchemaFeatures = Collections.emptyList();
4339

4440
JsonSchemaInferrerBuilder() {}
4541

@@ -84,7 +80,7 @@ public JsonSchemaInferrerBuilder setIntegerTypeCriterion(
8480
*/
8581
@Beta
8682
public JsonSchemaInferrerBuilder addEnumExtractors(@Nonnull EnumExtractor... enumExtractors) {
87-
if (this.enumExtractors == null) {
83+
if (this.enumExtractors.isEmpty()) {
8884
this.enumExtractors = new ArrayList<>();
8985
}
9086
for (EnumExtractor enumExtractor : enumExtractors) {
@@ -119,7 +115,7 @@ public JsonSchemaInferrerBuilder setTitleDescriptionGenerator(
119115
* @see FormatInferrers
120116
*/
121117
public JsonSchemaInferrerBuilder addFormatInferrers(@Nonnull FormatInferrer... formatInferrers) {
122-
if (this.formatInferrers == null) {
118+
if (this.formatInferrers.isEmpty()) {
123119
this.formatInferrers = new ArrayList<>();
124120
}
125121
for (FormatInferrer formatInferrer : formatInferrers) {
@@ -226,7 +222,7 @@ public JsonSchemaInferrerBuilder setNumberRangeFeatures(
226222
*/
227223
public JsonSchemaInferrerBuilder addGenericSchemaFeatures(
228224
@Nonnull GenericSchemaFeature... features) {
229-
if (this.genericSchemaFeatures == null) {
225+
if (this.genericSchemaFeatures.isEmpty()) {
230226
this.genericSchemaFeatures = new ArrayList<>();
231227
}
232228
for (GenericSchemaFeature feature : features) {
@@ -237,17 +233,11 @@ public JsonSchemaInferrerBuilder addGenericSchemaFeatures(
237233

238234
@Nonnull
239235
private EnumExtractor getCombinedEnumExtractor() {
240-
if (enumExtractors == null) {
241-
return EnumExtractors.noOp();
242-
}
243236
return EnumExtractors.chained(enumExtractors.toArray(new EnumExtractor[0]));
244237
}
245238

246239
@Nonnull
247240
private FormatInferrer getCombinedFormatInferrer() {
248-
if (formatInferrers == null) {
249-
return FormatInferrers.noOp();
250-
}
251241
return FormatInferrers.chained(formatInferrers.toArray(new FormatInferrer[0]));
252242
}
253243

@@ -273,9 +263,7 @@ private GenericSchemaFeature getCombinedGenericSchemaFeature() {
273263
features.addAll(arrayLengthFeatures);
274264
features.addAll(stringLengthFeatures);
275265
features.addAll(numberRangeFeatures);
276-
if (genericSchemaFeatures != null) {
277-
features.addAll(genericSchemaFeatures);
278-
}
266+
features.addAll(genericSchemaFeatures);
279267
return GenericSchemaFeatures.chained(features.toArray(new GenericSchemaFeature[0]));
280268
}
281269

0 commit comments

Comments
 (0)