Skip to content

Commit 193cc1c

Browse files
committed
2 parents fe36798 + 7312b3e commit 193cc1c

File tree

7 files changed

+130
-120
lines changed

7 files changed

+130
-120
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
.settings
33
.classpath
44
target
5+
.checkstyle
6+
.fbExcludeFilterFile
7+
.pmd
8+
.pmdruleset.xml

core/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424
<parent>
2525
<groupId>org.everit.config</groupId>
2626
<artifactId>org.everit.config.oss</artifactId>
27-
<version>7.0.1</version>
27+
<version>7.2.0</version>
2828
</parent>
2929

3030
<groupId>org.everit.json</groupId>
3131
<artifactId>org.everit.json.schema</artifactId>
3232
<version>1.0.1</version>
3333

3434
<packaging>bundle</packaging>
35-
35+
3636
<properties>
3737
<projectpath>json-schema-validator</projectpath>
3838
<maven.compiler.source>1.8</maven.compiler.source>
3939
<maven.compiler.target>1.8</maven.compiler.target>
4040
</properties>
41-
41+
4242
<licenses>
4343
<license>
4444
<name>Apache License, Version 2.0</name>
@@ -57,7 +57,7 @@
5757
<name>Everit Kft.</name>
5858
<url>http://www.everit.org</url>
5959
</organization>
60-
60+
6161
<scm>
6262
<connection>scm:git:git://github.com/everit-org/${projectpath}.git</connection>
6363
<developerConnection>scm:git:https://github.com/everit-org/${projectpath}.git</developerConnection>

core/src/main/java/org/everit/json/schema/EnumSchema.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static class Builder extends Schema.Builder<EnumSchema> {
3232

3333
private Set<Object> possibleValues = new HashSet<>();
3434

35+
@Override
36+
public EnumSchema build() {
37+
return new EnumSchema(this);
38+
}
39+
3540
public Builder possibleValue(final Object possibleValue) {
3641
possibleValues.add(possibleValue);
3742
return this;
@@ -41,18 +46,21 @@ public Builder possibleValues(final Set<Object> possibleValues) {
4146
this.possibleValues = possibleValues;
4247
return this;
4348
}
49+
}
4450

45-
@Override
46-
public EnumSchema build() {
47-
return new EnumSchema(this);
48-
}
51+
public static Builder builder() {
52+
return new Builder();
4953
}
5054

5155
private final Set<Object> possibleValues;
5256

5357
public EnumSchema(final Builder builder) {
5458
super(builder);
55-
this.possibleValues = Collections.unmodifiableSet(new HashSet<>(builder.possibleValues));
59+
possibleValues = Collections.unmodifiableSet(new HashSet<>(builder.possibleValues));
60+
}
61+
62+
public Set<Object> getPossibleValues() {
63+
return possibleValues;
5664
}
5765

5866
@Override
@@ -61,16 +69,7 @@ public void validate(final Object subject) {
6169
.filter(val -> ObjectComparator.deepEquals(val, subject))
6270
.findAny()
6371
.orElseThrow(
64-
() -> new ValidationException(String.format("%s is not a valid enum value",
65-
subject)));
66-
}
67-
68-
public Set<Object> getPossibleValues() {
69-
return possibleValues;
70-
}
71-
72-
public static Builder builder() {
73-
return new Builder();
72+
() -> new ValidationException(String.format("%s is not a valid enum value", subject)));
7473
}
7574

7675
}

core/src/main/java/org/everit/json/schema/loader/SchemaLoader.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public class SchemaLoader {
5858
/**
5959
* Created and used by {@link TypeBasedMultiplexer} to set actions (consumers) for matching
6060
* classes.
61+
*
62+
* @param <E>
63+
* the type of the input to the operation.
6164
*/
6265
@FunctionalInterface
6366
interface OnTypeConsumer<E> {
@@ -88,7 +91,7 @@ class TypeBasedMultiplexer {
8891
*/
8992
private class IdModifyingTypeConsumerImpl extends OnTypeConsumerImpl<JSONObject> {
9093

91-
public IdModifyingTypeConsumerImpl(final Class<?> key) {
94+
IdModifyingTypeConsumerImpl(final Class<?> key) {
9295
super(key);
9396
}
9497

@@ -118,12 +121,15 @@ public TypeBasedMultiplexer then(final Consumer<JSONObject> consumer) {
118121
/**
119122
* Default implementation of {@link OnTypeConsumer}, instantiated by
120123
* {@link TypeBasedMultiplexer#ifIs(Class)}.
124+
*
125+
* @param <E>
126+
* the type of the input to the operation.
121127
*/
122128
private class OnTypeConsumerImpl<E> implements OnTypeConsumer<E> {
123129

124130
protected final Class<?> key;
125131

126-
public OnTypeConsumerImpl(final Class<?> key) {
132+
OnTypeConsumerImpl(final Class<?> key) {
127133
this.key = key;
128134
}
129135

@@ -135,16 +141,16 @@ public TypeBasedMultiplexer then(final Consumer<E> consumer) {
135141

136142
}
137143

144+
private final Map<Class<?>, Consumer<?>> actions = new HashMap<>();
145+
138146
private final String keyOfObj;
139147

140148
private final Object obj;
141149

142-
private final Map<Class<?>, Consumer<?>> actions = new HashMap<>();
143-
144150
/**
145151
* Constructor with {@code null} {@code keyOfObj}.
146152
*/
147-
public TypeBasedMultiplexer(final Object obj) {
153+
TypeBasedMultiplexer(final Object obj) {
148154
this(null, obj);
149155
}
150156

@@ -158,7 +164,7 @@ public TypeBasedMultiplexer(final Object obj) {
158164
* the object which' class is matched against the classes defined by
159165
* {@link #ifIs(Class)} (or {@link #ifObject()}) calls.
160166
*/
161-
public TypeBasedMultiplexer(final String keyOfObj, final Object obj) {
167+
TypeBasedMultiplexer(final String keyOfObj, final Object obj) {
162168
this.keyOfObj = keyOfObj;
163169
this.obj = obj;
164170
}
@@ -227,22 +233,22 @@ public void requireAny() {
227233
"maxItems",
228234
"uniqueItems");
229235

236+
private static final Map<String, Function<Collection<Schema>, CombinedSchema.Builder>> COMBINED_SUBSCHEMA_PROVIDERS = // CS_DISABLE_LINE_LENGTH
237+
new HashMap<>(3);
238+
239+
private static final List<String> NUMBER_SCHEMA_PROPS = Arrays.asList("minimum", "maximum",
240+
"minimumExclusive", "maximumExclusive", "multipleOf");
241+
230242
private static final List<String> OBJECT_SCHEMA_PROPS = Arrays.asList("properties", "required",
231243
"minProperties",
232244
"maxProperties",
233245
"dependencies",
234246
"patternProperties",
235247
"additionalProperties");
236248

237-
private static final List<String> NUMBER_SCHEMA_PROPS = Arrays.asList("minimum", "maximum",
238-
"minimumExclusive", "maximumExclusive", "multipleOf");
239-
240249
private static final List<String> STRING_SCHEMA_PROPS = Arrays.asList("minLength", "maxLength",
241250
"pattern");
242251

243-
private static final Map<String, Function<Collection<Schema>, CombinedSchema.Builder>> //
244-
COMBINED_SUBSCHEMA_PROVIDERS = new HashMap<>(3);
245-
246252
static {
247253
COMBINED_SUBSCHEMA_PROVIDERS.put("allOf", CombinedSchema::allOf);
248254
COMBINED_SUBSCHEMA_PROVIDERS.put("anyOf", CombinedSchema::anyOf);
@@ -258,7 +264,7 @@ public void requireAny() {
258264
* @return the schema validator object
259265
*/
260266
public static Schema load(final JSONObject schemaJson) {
261-
return load(schemaJson, new DefaultSchemaClient());
267+
return SchemaLoader.load(schemaJson, new DefaultSchemaClient());
262268
}
263269

264270
/**
@@ -276,15 +282,15 @@ public static Schema load(final JSONObject schemaJson, final SchemaClient httpCl
276282
.load().build();
277283
}
278284

285+
private final SchemaClient httpClient;
286+
279287
private String id = null;
280288

281-
private final JSONObject schemaJson;
289+
private final Map<String, ReferenceSchema.Builder> pointerSchemas;
282290

283291
private final JSONObject rootSchemaJson;
284292

285-
private final SchemaClient httpClient;
286-
287-
private final Map<String, ReferenceSchema.Builder> pointerSchemas;
293+
private final JSONObject schemaJson;
288294

289295
/**
290296
* Constructor.
@@ -405,7 +411,7 @@ private ObjectSchema.Builder buildObjectSchema() {
405411
}
406412
}
407413
}
408-
ifPresent("dependencies", JSONObject.class, deps -> this.addDependencies(builder, deps));
414+
ifPresent("dependencies", JSONObject.class, deps -> addDependencies(builder, deps));
409415
return builder;
410416
}
411417

core/src/main/java/org/everit/json/schema/loader/internal/JSONPointer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static class QueryResult {
4747

4848
/**
4949
* Constructor.
50-
*
50+
*
5151
* @param containingDocument
5252
* the JSON document which contains the query result.
5353
* @param queryResult
@@ -61,7 +61,7 @@ public QueryResult(final JSONObject containingDocument, final JSONObject queryRe
6161

6262
/**
6363
* Getter for {@link #containingDocument}.
64-
*
64+
*
6565
* @return the JSON document which contains the query result.
6666
*/
6767
public JSONObject getContainingDocument() {
@@ -70,7 +70,7 @@ public JSONObject getContainingDocument() {
7070

7171
/**
7272
* Getter for {@link #queryResult}.
73-
*
73+
*
7474
* @return the JSON object being the result of the query execution.
7575
*/
7676
public JSONObject getQueryResult() {
@@ -138,7 +138,7 @@ public static final JSONPointer forURL(final SchemaClient schemaClient, final St
138138
fragment = url.substring(poundIdx);
139139
toBeQueried = url.substring(0, poundIdx);
140140
}
141-
return new JSONPointer(() -> executeWith(schemaClient, toBeQueried), fragment);
141+
return new JSONPointer(() -> JSONPointer.executeWith(schemaClient, toBeQueried), fragment);
142142
}
143143

144144
private final Supplier<JSONObject> documentProvider;
@@ -153,17 +153,18 @@ public JSONPointer(final Supplier<JSONObject> documentProvider, final String fra
153153
/**
154154
* Queries from {@code document} based on this pointer.
155155
*
156+
* @return a DTO containing the query result and the root document containing the query result.
157+
*
156158
* @throws IllegalArgumentException
157159
* if the pointer does not start with {@code '#'}.
158-
* @return a DTO containing the query result and the root document containing the query result
159160
*/
160161
public QueryResult query() {
161162
JSONObject document = documentProvider.get();
162163
if (fragment.isEmpty()) {
163164
return new QueryResult(document, document);
164165
}
165166
String[] path = fragment.split("/");
166-
if (path[0] == null || !path[0].startsWith("#")) {
167+
if ((path[0] == null) || !path[0].startsWith("#")) {
167168
throw new IllegalArgumentException("JSON pointers must start with a '#'");
168169
}
169170
Object current = document;

pom.xml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@
1717
1818
-->
1919
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21-
22-
<modelVersion>4.0.0</modelVersion>
23-
24-
<parent>
25-
<groupId>org.everit.config</groupId>
26-
<artifactId>org.everit.config.oss</artifactId>
27-
<version>7.0.1</version>
28-
</parent>
29-
30-
<groupId>org.everit.json</groupId>
31-
<artifactId>org.everit.json.schema.parent</artifactId>
32-
<version>1.0.1</version>
33-
34-
<packaging>pom</packaging>
35-
36-
<modules>
37-
<module>core</module>
38-
<module>tests</module>
39-
</modules>
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>org.everit.config</groupId>
26+
<artifactId>org.everit.config.oss</artifactId>
27+
<version>7.2.0</version>
28+
</parent>
29+
30+
<groupId>org.everit.json</groupId>
31+
<artifactId>org.everit.json.schema.parent</artifactId>
32+
<version>1.0.1</version>
33+
34+
<packaging>pom</packaging>
35+
36+
<modules>
37+
<module>core</module>
38+
<module>tests</module>
39+
</modules>
4040

4141
</project>

0 commit comments

Comments
 (0)