Package org.seedstack.seed
Class ClassConfiguration<T>
- java.lang.Object
-
- org.seedstack.seed.ClassConfiguration<T>
-
- Type Parameters:
T- the type of the target object.
public abstract class ClassConfiguration<T> extends Object
A key/value based configuration object for a specific target class. TheApplication.getConfiguration(Class)method returns such objects as a way to find properties attached to particular classes.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,String>asMap()Returns the class configuration as an unmodifiable map.booleancontainsKey(String key)Returns if the class configuration contains a particular key.static <T> ClassConfiguration<T>empty(Class<T> targetClass)Create an empty class configuration for the specified class.Set<Map.Entry<String,String>>entrySet()Returns an unmodifiable set of the key/value pairs as map entries.voidforEach(BiConsumer<? super String,? super String> action)Walks the key/value pairs and provides them to the specifiedBiConsumer.Stringget(String key)Returns the value of a particular key (or null of the key doesn't exist).String[]getArray(String key)Returns the value of a particular key (or null of the key doesn't exist).StringgetOrDefault(String key, String defaultValue)Returns the value of a particular key (or the default value of the key doesn't exist).Class<T>getTargetClass()booleanisEmpty()Returns if the class configuration is empty or not.Set<String>keySet()Returns an unmodifiable set of all the keys.ClassConfiguration<T>merge(ClassConfiguration<T> other)Merge the class configuration with another one, overriding the existing values having an identical key.static <T> ClassConfiguration<T>of(Class<T> targetClass, String... keyValuePairs)Create a class configuration for the specified class, with the specified properties.static <T> ClassConfiguration<T>of(Class<T> targetClass, Map<String,String> source)Create a class configuration for the specified class, with the specified properties.intsize()Returns the number of key/value pairs.Collection<String>values()Returns an unmodifiable collection of all the values.
-
-
-
Method Detail
-
of
public static <T> ClassConfiguration<T> of(Class<T> targetClass, Map<String,String> source)
Create a class configuration for the specified class, with the specified properties.- Type Parameters:
T- the type of the target object.- Parameters:
targetClass- the class this configuration refers to.source- the source properties.- Returns:
- the class configuration object.
-
of
public static <T> ClassConfiguration<T> of(Class<T> targetClass, String... keyValuePairs)
Create a class configuration for the specified class, with the specified properties.- Type Parameters:
T- the type of the target object.- Parameters:
targetClass- the class this configuration refers to.keyValuePairs- key/value pairs forming properties .- Returns:
- the class configuration object.
-
empty
public static <T> ClassConfiguration<T> empty(Class<T> targetClass)
Create an empty class configuration for the specified class.- Type Parameters:
T- the type of the target object.- Parameters:
targetClass- the class this configuration refers to.- Returns:
- the class configuration object.
-
size
public int size()
Returns the number of key/value pairs.- Returns:
- the size of the class configuration.
-
isEmpty
public boolean isEmpty()
Returns if the class configuration is empty or not.- Returns:
- true if empty, false otherwise.
-
containsKey
public boolean containsKey(String key)
Returns if the class configuration contains a particular key.- Parameters:
key- the key to check for.- Returns:
- true if the key is present, false otherwise.
-
get
public String get(String key)
Returns the value of a particular key (or null of the key doesn't exist).- Parameters:
key- the key to retrieve the value of.- Returns:
- the value or null.
-
getArray
public String[] getArray(String key)
Returns the value of a particular key (or null of the key doesn't exist). Should the value contain comma (,) separators, it is split into an array of values. Each array item is trimmed usingString.trim().- Parameters:
key- the key to retrieve the value of.- Returns:
- the split value or null.
-
keySet
public Set<String> keySet()
Returns an unmodifiable set of all the keys.- Returns:
- the unmodifiable set.
-
values
public Collection<String> values()
Returns an unmodifiable collection of all the values.- Returns:
- the unmodifiable collection.
-
entrySet
public Set<Map.Entry<String,String>> entrySet()
Returns an unmodifiable set of the key/value pairs as map entries.- Returns:
- the unmodifiable set.
-
getOrDefault
public String getOrDefault(String key, String defaultValue)
Returns the value of a particular key (or the default value of the key doesn't exist).- Parameters:
key- the key to retrieve the value of.defaultValue- the default value.- Returns:
- the value or the default value.
-
forEach
public void forEach(BiConsumer<? super String,? super String> action)
Walks the key/value pairs and provides them to the specifiedBiConsumer.- Parameters:
action- theBiConsumerthat is invoked with each key/value pair.
-
asMap
public Map<String,String> asMap()
Returns the class configuration as an unmodifiable map.- Returns:
- the unmodifiable map.
-
merge
public ClassConfiguration<T> merge(ClassConfiguration<T> other)
Merge the class configuration with another one, overriding the existing values having an identical key. If a key with a null value is merged, the key is completely removed from the resulting configuration.- Parameters:
other- the other class configuration.- Returns:
- the merge class configuration.
-
-