com.github.fge.jsonschema.core.util
Class Registry<K,V>

java.lang.Object
  extended by com.github.fge.jsonschema.core.util.Registry<K,V>
Type Parameters:
K - type of the keys
V - type of the values

@Beta
public abstract class Registry<K,V>
extends Object

A registry builder with key/value/pair normalization and checking

Note that null keys or values are not allowed.

Since:
1.1.9

Field Summary
protected static MessageBundle BUNDLE
           
 
Constructor Summary
protected Registry(Function<K,K> keyNormalizer, ArgumentChecker<K> keyChecker, Function<V,V> valueNormalizer, ArgumentChecker<V> valueChecker)
          Protected constructor
 
Method Summary
 Map<K,V> build()
          Build the map
protected abstract  void checkEntry(K key, V value)
          Check the validity of the entry before submitting it
 Registry<K,V> clear()
          Clear all entries from this registry
 Registry<K,V> put(K key, V value)
          Add a key/value pair in this registry
 Registry<K,V> putAll(Map<K,V> otherMap)
          Put the contents from another map into this map builder
 Registry<K,V> remove(K key)
          Remove one key and its associated value from the registry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUNDLE

protected static final MessageBundle BUNDLE
Constructor Detail

Registry

protected Registry(Function<K,K> keyNormalizer,
                   ArgumentChecker<K> keyChecker,
                   Function<V,V> valueNormalizer,
                   ArgumentChecker<V> valueChecker)
Protected constructor

Parameters:
keyNormalizer - the key normalizer
keyChecker - the key checker
valueNormalizer - the value normalizer
valueChecker - the value checker
Throws:
NullPointerException - one normalizer or checker is null
Method Detail

put

public final Registry<K,V> put(K key,
                               V value)
Add a key/value pair in this registry

Both the keys and values are first normalized, then checked; finally, before insertion, the key/value pair is checked.

Parameters:
key - the key
value - the value
Returns:
this
Throws:
NullPointerException - the key or value is null
IllegalArgumentException - see ArgumentChecker

putAll

public final Registry<K,V> putAll(Map<K,V> otherMap)
Put the contents from another map into this map builder

This calls put(Object, Object) on each key/value pair in the map.

Parameters:
otherMap - the map
Returns:
this
Throws:
NullPointerException - map is null

remove

public final Registry<K,V> remove(K key)
Remove one key and its associated value from the registry

Parameters:
key - the key to remove
Returns:
this

clear

public final Registry<K,V> clear()
Clear all entries from this registry

Returns:
this

build

public final Map<K,V> build()
Build the map

The returned map is immutable.

Returns:
a map
See Also:
ImmutableMap

checkEntry

protected abstract void checkEntry(K key,
                                   V value)
Check the validity of the entry before submitting it

Note that the key and value are normalized when entering this method, and that they cannot be null.

Parameters:
key - the normalized key
value - the normalized value