Skip to content

Commit ba503b3

Browse files
committed
Rename SchemaValidatorsConfig to SchemaRegistryConfig and move from ValidationContext to SchemaRegistry and refactor
Rename JsonSchemaWalkerListener to SchemaWalkerListener Rename DefaultItemWalkListenerRunner to ItemWalkListenerRunner Rename DefaultKeywordWalkListenerRunner to KeywordWalkListenerRunner Rename DefaultPropertyWalkListenerRunner to PropertyWalkListenerRunner Shift walk configuration to WalkConfig
1 parent 1e365d9 commit ba503b3

File tree

174 files changed

+2856
-3682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+2856
-3682
lines changed

src/main/java/com/networknt/schema/AbstractCollector.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/com/networknt/schema/ApplyDefaultsStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.networknt.schema;
22

33
public class ApplyDefaultsStrategy {
4-
static final ApplyDefaultsStrategy EMPTY_APPLY_DEFAULTS_STRATEGY = new ApplyDefaultsStrategy(false, false, false);
4+
public static final ApplyDefaultsStrategy EMPTY_APPLY_DEFAULTS_STRATEGY = new ApplyDefaultsStrategy(false, false, false);
55

66
private final boolean applyPropertyDefaults;
77
private final boolean applyPropertyDefaultsIfNull;

src/main/java/com/networknt/schema/Collector.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/main/java/com/networknt/schema/CollectorContext.java

Lines changed: 48 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -17,136 +17,86 @@
1717

1818
import java.util.HashMap;
1919
import java.util.Map;
20-
import java.util.Map.Entry;
21-
import java.util.Set;
20+
import java.util.function.Function;
2221

2322
/**
24-
* Context for holding the output returned by the {@link Collector}
25-
* implementations.
23+
* Context for holding data which can be set by custom walkers or validators and
24+
* can be retrieved later from the execution context.
2625
*/
2726
public class CollectorContext {
2827
/**
29-
* Map for holding the name and {@link Collector} or a simple Object.
28+
* Map for the data.
3029
*/
31-
private final Map<String, Object> collectorMap;
32-
33-
/**
34-
* Map for holding the name and {@link Collector} class collect method output.
35-
*/
36-
private final Map<String, Object> collectorLoadMap;
30+
private final Map<Object, Object> data;
3731

3832
/**
3933
* Default constructor will use an unsynchronized HashMap to store data. This is
4034
* suitable if the collector context is not shared with multiple threads.
4135
*/
4236
public CollectorContext() {
43-
this(new HashMap<>(), new HashMap<>());
37+
this(new HashMap<>());
4438
}
4539

46-
/**
47-
* Constructor that creates the context using the specified instances to store
48-
* data.
49-
* <p>
50-
* If for instance the collector context needs to be shared with multiple
51-
* threads a ConcurrentHashMap can be used.
52-
*
53-
* @param collectorMap the collector map
54-
* @param collectorLoadMap the collector load map
55-
*/
56-
public CollectorContext(Map<String, Object> collectorMap, Map<String, Object> collectorLoadMap) {
57-
this.collectorMap = collectorMap;
58-
this.collectorLoadMap = collectorLoadMap;
59-
}
60-
61-
/**
62-
* Adds a collector with give name. Preserving this method for backward
63-
* compatibility.
64-
*
65-
* @param <E> element
66-
* @param name String
67-
* @param collector Collector
68-
*/
69-
public <E> void add(String name, Collector<E> collector) {
70-
this.collectorMap.put(name, collector);
40+
/**
41+
* Constructor that creates the context using the specified instances to store
42+
* data.
43+
* <p>
44+
* If for instance the collector context needs to be shared with multiple
45+
* threads a ConcurrentHashMap can be used.
46+
* <p>
47+
* It is however more likely that the data will only be used after the walk or
48+
* validation is complete rather then during processing.
49+
*
50+
* @param data the data map
51+
*/
52+
public CollectorContext(Map<Object, Object> data) {
53+
this.data = data;
7154
}
7255

7356
/**
74-
* Adds a collector or a simple object with give name.
57+
* Sets data associated with a given key.
7558
*
76-
* @param <E> element
77-
* @param object Object
78-
* @param name String
59+
* @param <T> the return type
60+
* @param key the key
61+
* @param value the value
62+
* @return the previous value
7963
*/
80-
public <E> void add(String name, Object object) {
81-
this.collectorMap.put(name, object);
64+
@SuppressWarnings("unchecked")
65+
public <T> T put(Object key, Object value) {
66+
return (T) this.data.put(key, value);
8267
}
8368

8469
/**
85-
* Gets the data associated with a given name. Please note if you are collecting
86-
* {@link Collector} instances you should wait till the validation is complete
87-
* to gather all data.
88-
* <p>
89-
* When {@link CollectorContext} is used to collect {@link Collector} instances
90-
* for a particular key, this method will return the {@link Collector} instance
91-
* as long as {@link #loadCollectors} method is not called. Once
92-
* the {@link #loadCollectors} method is called this method will
93-
* return the actual data collected by collector.
94-
*
95-
* @param name String
96-
* @return Object
97-
*/
98-
public Object get(String name) {
99-
Object object = this.collectorMap.get(name);
100-
if (object instanceof Collector<?> && (this.collectorLoadMap.get(name) != null)) {
101-
return this.collectorLoadMap.get(name);
102-
}
103-
return this.collectorMap.get(name);
104-
}
105-
106-
/**
107-
* Gets the collector map.
70+
* Gets the data associated with a given key.
10871
*
109-
* @return the collector map
72+
* @param <T> the return type
73+
* @param key the key
74+
* @return the value
11075
*/
111-
public Map<String, Object> getCollectorMap() {
112-
return this.collectorMap;
76+
@SuppressWarnings("unchecked")
77+
public <T> T get(Object key) {
78+
return (T) this.data.get(key);
11379
}
11480

11581
/**
116-
* Returns all the collected data. Please look into {@link #get(String)} method for more details.
117-
* @return Map
118-
*/
119-
public Map<String, Object> getAll() {
120-
Map<String, Object> mergedMap = new HashMap<>();
121-
mergedMap.putAll(this.collectorMap);
122-
mergedMap.putAll(this.collectorLoadMap);
123-
return mergedMap;
124-
}
125-
126-
/**
127-
* Combines data with Collector identified by the given name.
82+
* Computes the value if absent.
12883
*
129-
* @param name String
130-
* @param data Object
84+
* @param <T>
85+
* @param key the key
86+
* @param mappingFunction the mapping function
87+
* @return the value
13188
*/
132-
public void combineWithCollector(String name, Object data) {
133-
Object object = this.collectorMap.get(name);
134-
if (object instanceof Collector<?>) {
135-
Collector<?> collector = (Collector<?>) object;
136-
collector.combine(data);
137-
}
89+
@SuppressWarnings("unchecked")
90+
public <T> T computeIfAbsent(Object key, Function<Object,Object> mappingFunction) {
91+
return (T) this.data.computeIfAbsent(key, mappingFunction);
13892
}
13993

14094
/**
141-
* Loads data from all collectors.
95+
* Gets the data map.
96+
*
97+
* @return the data map
14298
*/
143-
public void loadCollectors() {
144-
Set<Entry<String, Object>> entrySet = this.collectorMap.entrySet();
145-
for (Entry<String, Object> entry : entrySet) {
146-
if (entry.getValue() instanceof Collector<?>) {
147-
Collector<?> collector = (Collector<?>) entry.getValue();
148-
this.collectorLoadMap.put(entry.getKey(), collector.collect());
149-
}
150-
}
99+
public Map<Object, Object> getData() {
100+
return this.data;
151101
}
152102
}

0 commit comments

Comments
 (0)