Skip to content

Commit

Permalink
Merge pull request #11 from zsigmond-czine-everit/master
Browse files Browse the repository at this point in the history
Update OSS parent version. Code format. Fixed checkstyle problems.
  • Loading branch information
erosb committed Nov 10, 2015
2 parents fe36798 + 7312b3e commit feb466e
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.settings
.classpath
target
.checkstyle
.fbExcludeFilterFile
.pmd
.pmdruleset.xml
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
<parent>
<groupId>org.everit.config</groupId>
<artifactId>org.everit.config.oss</artifactId>
<version>7.0.1</version>
<version>7.2.0</version>
</parent>

<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.0.1</version>

<packaging>bundle</packaging>

<properties>
<projectpath>json-schema-validator</projectpath>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
Expand All @@ -57,7 +57,7 @@
<name>Everit Kft.</name>
<url>http://www.everit.org</url>
</organization>

<scm>
<connection>scm:git:git://github.com/everit-org/${projectpath}.git</connection>
<developerConnection>scm:git:https://github.com/everit-org/${projectpath}.git</developerConnection>
Expand Down
29 changes: 14 additions & 15 deletions core/src/main/java/org/everit/json/schema/EnumSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static class Builder extends Schema.Builder<EnumSchema> {

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

@Override
public EnumSchema build() {
return new EnumSchema(this);
}

public Builder possibleValue(final Object possibleValue) {
possibleValues.add(possibleValue);
return this;
Expand All @@ -41,18 +46,21 @@ public Builder possibleValues(final Set<Object> possibleValues) {
this.possibleValues = possibleValues;
return this;
}
}

@Override
public EnumSchema build() {
return new EnumSchema(this);
}
public static Builder builder() {
return new Builder();
}

private final Set<Object> possibleValues;

public EnumSchema(final Builder builder) {
super(builder);
this.possibleValues = Collections.unmodifiableSet(new HashSet<>(builder.possibleValues));
possibleValues = Collections.unmodifiableSet(new HashSet<>(builder.possibleValues));
}

public Set<Object> getPossibleValues() {
return possibleValues;
}

@Override
Expand All @@ -61,16 +69,7 @@ public void validate(final Object subject) {
.filter(val -> ObjectComparator.deepEquals(val, subject))
.findAny()
.orElseThrow(
() -> new ValidationException(String.format("%s is not a valid enum value",
subject)));
}

public Set<Object> getPossibleValues() {
return possibleValues;
}

public static Builder builder() {
return new Builder();
() -> new ValidationException(String.format("%s is not a valid enum value", subject)));
}

}
42 changes: 24 additions & 18 deletions core/src/main/java/org/everit/json/schema/loader/SchemaLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class SchemaLoader {
/**
* Created and used by {@link TypeBasedMultiplexer} to set actions (consumers) for matching
* classes.
*
* @param <E>
* the type of the input to the operation.
*/
@FunctionalInterface
interface OnTypeConsumer<E> {
Expand Down Expand Up @@ -88,7 +91,7 @@ class TypeBasedMultiplexer {
*/
private class IdModifyingTypeConsumerImpl extends OnTypeConsumerImpl<JSONObject> {

public IdModifyingTypeConsumerImpl(final Class<?> key) {
IdModifyingTypeConsumerImpl(final Class<?> key) {
super(key);
}

Expand Down Expand Up @@ -118,12 +121,15 @@ public TypeBasedMultiplexer then(final Consumer<JSONObject> consumer) {
/**
* Default implementation of {@link OnTypeConsumer}, instantiated by
* {@link TypeBasedMultiplexer#ifIs(Class)}.
*
* @param <E>
* the type of the input to the operation.
*/
private class OnTypeConsumerImpl<E> implements OnTypeConsumer<E> {

protected final Class<?> key;

public OnTypeConsumerImpl(final Class<?> key) {
OnTypeConsumerImpl(final Class<?> key) {
this.key = key;
}

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

}

private final Map<Class<?>, Consumer<?>> actions = new HashMap<>();

private final String keyOfObj;

private final Object obj;

private final Map<Class<?>, Consumer<?>> actions = new HashMap<>();

/**
* Constructor with {@code null} {@code keyOfObj}.
*/
public TypeBasedMultiplexer(final Object obj) {
TypeBasedMultiplexer(final Object obj) {
this(null, obj);
}

Expand All @@ -158,7 +164,7 @@ public TypeBasedMultiplexer(final Object obj) {
* the object which' class is matched against the classes defined by
* {@link #ifIs(Class)} (or {@link #ifObject()}) calls.
*/
public TypeBasedMultiplexer(final String keyOfObj, final Object obj) {
TypeBasedMultiplexer(final String keyOfObj, final Object obj) {
this.keyOfObj = keyOfObj;
this.obj = obj;
}
Expand Down Expand Up @@ -227,22 +233,22 @@ public void requireAny() {
"maxItems",
"uniqueItems");

private static final Map<String, Function<Collection<Schema>, CombinedSchema.Builder>> COMBINED_SUBSCHEMA_PROVIDERS = // CS_DISABLE_LINE_LENGTH
new HashMap<>(3);

private static final List<String> NUMBER_SCHEMA_PROPS = Arrays.asList("minimum", "maximum",
"minimumExclusive", "maximumExclusive", "multipleOf");

private static final List<String> OBJECT_SCHEMA_PROPS = Arrays.asList("properties", "required",
"minProperties",
"maxProperties",
"dependencies",
"patternProperties",
"additionalProperties");

private static final List<String> NUMBER_SCHEMA_PROPS = Arrays.asList("minimum", "maximum",
"minimumExclusive", "maximumExclusive", "multipleOf");

private static final List<String> STRING_SCHEMA_PROPS = Arrays.asList("minLength", "maxLength",
"pattern");

private static final Map<String, Function<Collection<Schema>, CombinedSchema.Builder>> //
COMBINED_SUBSCHEMA_PROVIDERS = new HashMap<>(3);

static {
COMBINED_SUBSCHEMA_PROVIDERS.put("allOf", CombinedSchema::allOf);
COMBINED_SUBSCHEMA_PROVIDERS.put("anyOf", CombinedSchema::anyOf);
Expand All @@ -258,7 +264,7 @@ public void requireAny() {
* @return the schema validator object
*/
public static Schema load(final JSONObject schemaJson) {
return load(schemaJson, new DefaultSchemaClient());
return SchemaLoader.load(schemaJson, new DefaultSchemaClient());
}

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

private final SchemaClient httpClient;

private String id = null;

private final JSONObject schemaJson;
private final Map<String, ReferenceSchema.Builder> pointerSchemas;

private final JSONObject rootSchemaJson;

private final SchemaClient httpClient;

private final Map<String, ReferenceSchema.Builder> pointerSchemas;
private final JSONObject schemaJson;

/**
* Constructor.
Expand Down Expand Up @@ -405,7 +411,7 @@ private ObjectSchema.Builder buildObjectSchema() {
}
}
}
ifPresent("dependencies", JSONObject.class, deps -> this.addDependencies(builder, deps));
ifPresent("dependencies", JSONObject.class, deps -> addDependencies(builder, deps));
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class QueryResult {

/**
* Constructor.
*
*
* @param containingDocument
* the JSON document which contains the query result.
* @param queryResult
Expand All @@ -61,7 +61,7 @@ public QueryResult(final JSONObject containingDocument, final JSONObject queryRe

/**
* Getter for {@link #containingDocument}.
*
*
* @return the JSON document which contains the query result.
*/
public JSONObject getContainingDocument() {
Expand All @@ -70,7 +70,7 @@ public JSONObject getContainingDocument() {

/**
* Getter for {@link #queryResult}.
*
*
* @return the JSON object being the result of the query execution.
*/
public JSONObject getQueryResult() {
Expand Down Expand Up @@ -138,7 +138,7 @@ public static final JSONPointer forURL(final SchemaClient schemaClient, final St
fragment = url.substring(poundIdx);
toBeQueried = url.substring(0, poundIdx);
}
return new JSONPointer(() -> executeWith(schemaClient, toBeQueried), fragment);
return new JSONPointer(() -> JSONPointer.executeWith(schemaClient, toBeQueried), fragment);
}

private final Supplier<JSONObject> documentProvider;
Expand All @@ -153,17 +153,18 @@ public JSONPointer(final Supplier<JSONObject> documentProvider, final String fra
/**
* Queries from {@code document} based on this pointer.
*
* @return a DTO containing the query result and the root document containing the query result.
*
* @throws IllegalArgumentException
* if the pointer does not start with {@code '#'}.
* @return a DTO containing the query result and the root document containing the query result
*/
public QueryResult query() {
JSONObject document = documentProvider.get();
if (fragment.isEmpty()) {
return new QueryResult(document, document);
}
String[] path = fragment.split("/");
if (path[0] == null || !path[0].startsWith("#")) {
if ((path[0] == null) || !path[0].startsWith("#")) {
throw new IllegalArgumentException("JSON pointers must start with a '#'");
}
Object current = document;
Expand Down
40 changes: 20 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.everit.config</groupId>
<artifactId>org.everit.config.oss</artifactId>
<version>7.0.1</version>
</parent>
<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema.parent</artifactId>
<version>1.0.1</version>
<packaging>pom</packaging>
<modules>
<module>core</module>
<module>tests</module>
</modules>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.everit.config</groupId>
<artifactId>org.everit.config.oss</artifactId>
<version>7.2.0</version>
</parent>

<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema.parent</artifactId>
<version>1.0.1</version>

<packaging>pom</packaging>

<modules>
<module>core</module>
<module>tests</module>
</modules>

</project>
Loading

0 comments on commit feb466e

Please sign in to comment.