Skip to content

Commit

Permalink
upgrade to 1.0.34 and update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Mar 12, 2020
1 parent cb338c5 commit 55794b4
Show file tree
Hide file tree
Showing 24 changed files with 791 additions and 498 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

## 1.0.34 - 2020-03-12

### Added

### Changed

- fixes #268 Collector Context changes to handle simple Objects. Thanks @prashanthjos
- fixes #266 reformat the code and resolve javadoc warnnings

## 1.0.33 - 2020-03-09

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ Maven:
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.0.33</version>
<version>1.0.34</version>
</dependency>
```

Gradle:

```
dependencies {
compile(group: "com.networknt", name: "json-schema-validator", version: "1.0.33");
compile(group: "com.networknt", name: "json-schema-validator", version: "1.0.34");
}
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.0.33</version>
<version>1.0.34</version>
<packaging>bundle</packaging>
<description>A json schema validator that supports draft v4, v6, v7 and v2019-09</description>
<url>https://github.com/networknt/json-schema-validator</url>
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/com/networknt/schema/AbstractCollector.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
/*
* Copyright (c) 2020 Network New Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.networknt.schema;

public abstract class AbstractCollector<E> implements Collector<E>{
public abstract class AbstractCollector<E> implements Collector<E> {

@Override
public void combine(Object object) {
// Do nothing. This is the default Implementation.
}
@Override
public void combine(Object object) {
// Do nothing. This is the default Implementation.
}
}
44 changes: 31 additions & 13 deletions src/main/java/com/networknt/schema/Collector.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2020 Network New Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.networknt.schema;

/**
Expand All @@ -9,20 +25,22 @@
public interface Collector<E> {


/**
* This method should be called by the intermediate touch points that want to
* combine the data being collected by this collector. This is an optional
* method and could be used when the same collector is used for collecting data
* at multiple touch points or accumulating data at same touch point.
*/
public void combine(Object object);
/**
* This method should be called by the intermediate touch points that want to
* combine the data being collected by this collector. This is an optional
* method and could be used when the same collector is used for collecting data
* at multiple touch points or accumulating data at same touch point.
* @param object Object
*/
public void combine(Object object);

/**
* Final method called by the framework that returns the actual collected data.
* If the collector is not accumulating data or being used to collect data at
* multiple touch points, only this method can be implemented.
*/
public E collect();
/**
* Final method called by the framework that returns the actual collected data.
* If the collector is not accumulating data or being used to collect data at
* multiple touch points, only this method can be implemented.
* @return E element
*/
public E collect();


}
192 changes: 102 additions & 90 deletions src/main/java/com/networknt/schema/CollectorContext.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2020 Network New Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.networknt.schema;

import java.util.HashMap;
Expand All @@ -11,105 +26,102 @@
*/
public class CollectorContext {

// Using a namespace string as key in ThreadLocal so that it is unique in
// ThreadLocal.
static final String COLLECTOR_CONTEXT_THREAD_LOCAL_KEY = "com.networknt.schema.CollectorKey";
// Using a namespace string as key in ThreadLocal so that it is unique in
// ThreadLocal.
static final String COLLECTOR_CONTEXT_THREAD_LOCAL_KEY = "com.networknt.schema.CollectorKey";

// Get an instance from thread info (which uses ThreadLocal).
public static CollectorContext getInstance() {
return (CollectorContext) ThreadInfo.get(COLLECTOR_CONTEXT_THREAD_LOCAL_KEY);
}
// Get an instance from thread info (which uses ThreadLocal).
public static CollectorContext getInstance() {
return (CollectorContext) ThreadInfo.get(COLLECTOR_CONTEXT_THREAD_LOCAL_KEY);
}

/**
* Map for holding the name and {@link Collector} or a simple Object.
*/
private Map<String, Object> collectorMap = new HashMap<String, Object>();
/**
* Map for holding the name and {@link Collector} or a simple Object.
*/
private Map<String, Object> collectorMap = new HashMap<String, Object>();

/**
* Map for holding the name and {@link Collector} class collect method output.
*/
private Map<String, Object> collectorLoadMap = new HashMap<String, Object>();
/**
* Map for holding the name and {@link Collector} class collect method output.
*/
private Map<String, Object> collectorLoadMap = new HashMap<String, Object>();

/**
*
* Adds a collector with give name. Preserving this method for backward
* compatibility.
*
* @param <E>
* @param name
* @param collector
*/
public <E> void add(String name, Collector<E> collector) {
collectorMap.put(name, collector);
}
/**
* Adds a collector with give name. Preserving this method for backward
* compatibility.
*
* @param <E> element
* @param name String
* @param collector Collector
*/
public <E> void add(String name, Collector<E> collector) {
collectorMap.put(name, collector);
}

/**
*
* Adds a collector or a simple object with give name.
*
* @param <E>
* @param name
* @param collector
*/
public <E> void add(String name, Object object) {
collectorMap.put(name, object);
}
/**
* Adds a collector or a simple object with give name.
*
* @param <E> element
* @param object Object
* @param name String
*
*/
public <E> void add(String name, Object object) {
collectorMap.put(name, object);
}

/**
*
* Gets the data associated with a given name. Please note if you are using a
* Collector you should wait till the validation is complete to gather all data.
*
* For a Collector, this method will return the collector as long as load method
* is not called. Once the load method is called this method will return the
* actual data collected by collector.
*
* @param name
* @return
*/
public Object get(String name) {
Object object = collectorMap.get(name);
if (object instanceof Collector<?> && (collectorLoadMap.get(name) != null)) {
return collectorLoadMap.get(name);
}
return collectorMap.get(name);
}
/**
* Gets the data associated with a given name. Please note if you are using a
* Collector you should wait till the validation is complete to gather all data.
* <p>
* For a Collector, this method will return the collector as long as load method
* is not called. Once the load method is called this method will return the
* actual data collected by collector.
*
* @param name String
* @return Object
*/
public Object get(String name) {
Object object = collectorMap.get(name);
if (object instanceof Collector<?> && (collectorLoadMap.get(name) != null)) {
return collectorLoadMap.get(name);
}
return collectorMap.get(name);
}

/**
*
* Combines data with Collector identified by the given name.
*
* @param name
* @param data
*/
public void combineWithCollector(String name, Object data) {
Object object = collectorMap.get(name);
if (object instanceof Collector<?>) {
Collector<?> collector = (Collector<?>) object;
collector.combine(data);
}
}
/**
* Combines data with Collector identified by the given name.
*
* @param name String
* @param data Object
*/
public void combineWithCollector(String name, Object data) {
Object object = collectorMap.get(name);
if (object instanceof Collector<?>) {
Collector<?> collector = (Collector<?>) object;
collector.combine(data);
}
}

/**
* Reset the context
*/
void reset() {
this.collectorMap = new HashMap<String, Object>();
this.collectorLoadMap = new HashMap<String, Object>();
}
/**
* Reset the context
*/
void reset() {
this.collectorMap = new HashMap<String, Object>();
this.collectorLoadMap = new HashMap<String, Object>();
}

/**
* Loads data from all collectors.
*/
void loadCollectors() {
Set<Entry<String, Object>> entrySet = collectorMap.entrySet();
for (Entry<String, Object> entry : entrySet) {
if (entry.getValue() instanceof Collector<?>) {
Collector<?> collector = (Collector<?>) entry.getValue();
collectorLoadMap.put(entry.getKey(), collector.collect());
}
}
/**
* Loads data from all collectors.
*/
void loadCollectors() {
Set<Entry<String, Object>> entrySet = collectorMap.entrySet();
for (Entry<String, Object> entry : entrySet) {
if (entry.getValue() instanceof Collector<?>) {
Collector<?> collector = (Collector<?>) entry.getValue();
collectorLoadMap.put(entry.getKey(), collector.collect());
}
}

}
}

}
15 changes: 15 additions & 0 deletions src/main/java/com/networknt/schema/ConstValidator.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2020 Network New Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/networknt/schema/FalseValidator.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2020 Network New Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down
Loading

0 comments on commit 55794b4

Please sign in to comment.