public final class PropertyStore extends Object
The general idea behind a property store is to serve as a reusable configuration of an artifact (e.g. a Serializer) such that the artifact can be cached and reused if the property stores are 'equal'.
For example, two serializers of the same type created with the same configuration will always end up being the same serializer:
WriterSerializer s1 = JsonSerializer.
This has the effect of significantly improving performance, especially if you're creating many Serializers and Parsers.
The PropertyStoreBuilder
class is used to build up and instantiate immutable PropertyStore
objects.
In the example above, the property store being built looks like the following:
PropertyStore ps = PropertyStore
.
Property stores are immutable, comparable, and their hashcodes are calculated exactly one time. That makes them particularly suited for use as hashmap keys, and thus for caching reusable serializers and parsers.
Property names must have the following format...
...where the parts consist of the following...
String
Boolean
Integer
Class
Object
TreeSet<String>
TreeSet<Integer>
TreeSet<Class>
Linkedlist<String>
Linkedlist<Integer>
Linkedlist<Class>
Linkedlist<Object>
TreeMap<String,String>
TreeMap<String,Integer>
TreeMap<String,Class>
TreeMap<String,Object>
LinkedHashMap<String,String>
LinkedHashMap<String,Integer>
LinkedHashMap<String,Class>
LinkedHashMap<String,Object>
For example, BeanContext
class
called pojoSwaps
that has a data type of List<Class>
.
Property values get 'normalized' when they get set.
For example, calling propertyStore.set(
will cause the property
value to be converted to a boolean.
The
Use these for collections of objects where the order is not important.
Internally, a TreeSet
is used so that the order in which you add elements does not affect the
resulting order of the property.
The
Use these in cases where the order in which entries are added is important.
Adding to a list property will cause the new entries to be added to the BEGINNING of the list.
This ensures that the resulting order of the list is in most-to-least importance.
For example, multiple calls to pojoSwaps()
causes new entries to be added to the beginning of the list
so that previous values can be 'overridden':
Note that the order is different when passing multiple values into the pojoSwaps()
method, in which
case the order should be first-match-wins:
Combined, the results look like this:
The
Set and list properties have the additional convenience 'command' names for adding and removing entries:
Map properties have the additional convenience property name for adding and removing map entries:
TODO
TODO
Modifier and Type | Field and Description |
---|---|
static PropertyStore |
DEFAULT
A default empty property store.
|
Modifier and Type | Method and Description |
---|---|
PropertyStoreBuilder |
builder()
Creates a new property store builder initialized with the values in this property store.
|
static PropertyStoreBuilder |
create()
Creates a new empty builder for a property store.
|
boolean |
equals(Object o) |
boolean |
equals(PropertyStore ps,
String... groups)
Compares two property stores, but only based on the specified group names.
|
<T> T[] |
getArrayProperty(String key,
Class<T> eType)
Returns the array property value with the specified name.
|
<T> T[] |
getArrayProperty(String key,
Class<T> eType,
T[] def)
Returns the array property value with the specified name.
|
Class<?>[] |
getClassArrayProperty(String key)
Returns the class array property with the specified name.
|
Class<?>[] |
getClassArrayProperty(String key,
Class<?>[] def)
Returns the class array property with the specified name.
|
<T> Class<T>[] |
getClassArrayProperty(String key,
Class<T> eType)
Returns the class array property with the specified name.
|
List<Class<?>> |
getClassListProperty(String key)
Returns the class list property with the specified name.
|
<T> List<Class<T>> |
getClassListProperty(String key,
Class<T> eType)
Returns the class list property with the specified name.
|
Map<String,Class<?>> |
getClassMapProperty(String key)
Returns the class map property with the specified name.
|
<T> Map<String,Class<T>> |
getClassMapProperty(String key,
Class<T> eType)
Returns the class map property with the specified name.
|
<T> Class<? extends T> |
getClassProperty(String key,
Class<T> type,
Class<? extends T> def)
Returns the class property with the specified name.
|
Set<Class<?>> |
getClassSetProperty(String key)
Returns the class set property with the specified name.
|
<T> Set<Class<T>> |
getClassSetProperty(String key,
Class<T> eType)
Returns the class set property with the specified name.
|
<T> T[] |
getInstanceArrayProperty(String key,
Class<T> type,
T[] def)
Returns the specified property as an array of instantiated objects.
|
<T> T[] |
getInstanceArrayProperty(String key,
Class<T> type,
T[] def,
boolean fuzzyArgs,
Object... args)
Returns the specified property as an array of instantiated objects.
|
<T> T[] |
getInstanceArrayProperty(String key,
Object outer,
Class<T> type,
T[] def,
boolean fuzzyArgs,
Object... args)
Returns the specified property as an array of instantiated objects.
|
<T> T |
getInstanceProperty(String key,
Class<T> type,
Object def)
Returns an instance of the specified class, string, or object property.
|
<T> T |
getInstanceProperty(String key,
Class<T> type,
Object def,
boolean fuzzyArgs,
Object... args)
Returns an instance of the specified class, string, or object property.
|
<T> T |
getInstanceProperty(String key,
Object outer,
Class<T> type,
Object def,
boolean fuzzyArgs,
Object... args)
Returns an instance of the specified class, string, or object property.
|
<T> List<T> |
getListProperty(String key,
Class<T> eType)
Returns the list property with the specified name.
|
<T> List<T> |
getListProperty(String key,
Class<T> eType,
List<T> def)
Returns the list property with the specified name.
|
<T> Map<String,T> |
getMapProperty(String key,
Class<T> eType)
Returns the map property with the specified name.
|
Object |
getProperty(String key)
Returns the raw property value with the specified name.
|
<T> T |
getProperty(String key,
Class<T> c,
T def)
Returns the property value with the specified name.
|
Set<String> |
getPropertyKeys(String group)
Returns the keys found in the specified property group.
|
<T> Set<T> |
getSetProperty(String key,
Class<T> eType)
Returns the set property with the specified name.
|
<T> Set<T> |
getSetProperty(String key,
Class<T> eType,
Set<T> def)
Returns the set property with the specified name.
|
int |
hashCode() |
Integer |
hashCode(String... groups)
Returns a hashcode of this property store using only the specified group names.
|
Map<String,org.apache.juneau.PropertyStore.PropertyGroup> |
swap(BeanSession beanSession)
Used for debugging.
|
String |
toString() |
public static PropertyStore DEFAULT
public static PropertyStoreBuilder create()
public PropertyStoreBuilder builder()
public Object getProperty(String key)
key
- The property name.public <T> T getProperty(String key, Class<T> c, T def)
key
- The property name.c
- The class to cast or convert the value to.def
- The default value.public <T> Class<? extends T> getClassProperty(String key, Class<T> type, Class<? extends T> def)
key
- The property name.type
- The class type of the property.def
- The default value.public <T> T[] getArrayProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.public <T> T[] getArrayProperty(String key, Class<T> eType, T[] def)
key
- The property name.eType
- The class type of the elements in the property.def
- The default value.public Class<?>[] getClassArrayProperty(String key)
key
- The property name.public Class<?>[] getClassArrayProperty(String key, Class<?>[] def)
key
- The property name.def
- The default value.public <T> Class<T>[] getClassArrayProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.public <T> Set<T> getSetProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashSet
, or an empty set if it doesn't exist.public <T> Set<T> getSetProperty(String key, Class<T> eType, Set<T> def)
key
- The property name.eType
- The class type of the elements in the property.def
- The default value if the property doesn't exist or is empty.LinkedHashSet
, or the default value if it doesn't exist or is empty.public Set<Class<?>> getClassSetProperty(String key)
key
- The property name.LinkedHashSet
, or an empty set if it doesn't exist.public <T> Set<Class<T>> getClassSetProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashSet
, or an empty set if it doesn't exist.public <T> List<T> getListProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.ArrayList
, or an empty list if it doesn't exist.public <T> List<T> getListProperty(String key, Class<T> eType, List<T> def)
key
- The property name.eType
- The class type of the elements in the property.def
- The default value if the property doesn't exist or is empty.ArrayList
, or the default value if it doesn't exist or is empty.public List<Class<?>> getClassListProperty(String key)
key
- The property name.ArrayList
, or an empty list if it doesn't exist.public <T> List<Class<T>> getClassListProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.ArrayList
, or an empty list if it doesn't exist.public <T> Map<String,T> getMapProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashMap
, or an empty map if it doesn't exist.public Map<String,Class<?>> getClassMapProperty(String key)
key
- The property name.LinkedHashMap
, or an empty map if it doesn't exist.public <T> Map<String,Class<T>> getClassMapProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashMap
, or an empty map if it doesn't exist.public <T> T getInstanceProperty(String key, Class<T> type, Object def)
If instantiating a class, assumes the class has a no-arg constructor. Otherwise, throws a runtime exception.
key
- The property name.type
- The class type of the property.def
- The default value if the property doesn't exist.
T
, or a Class<? extends T>
, or public <T> T getInstanceProperty(String key, Class<T> type, Object def, boolean fuzzyArgs, Object... args)
key
- The property name.type
- The class type of the property.def
- The default value if the property doesn't exist.
T
, or a Class<? extends T>
.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public <T> T getInstanceProperty(String key, Object outer, Class<T> type, Object def, boolean fuzzyArgs, Object... args)
key
- The property name.outer
- The outer object if the class we're instantiating is an inner class.type
- The class type of the property.def
- The default value if the property doesn't exist.
T
, or a Class<? extends T>
.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public <T> T[] getInstanceArrayProperty(String key, Class<T> type, T[] def)
key
- The property name.type
- The class type of the property.def
- The default object to return if the property doesn't exist.public <T> T[] getInstanceArrayProperty(String key, Class<T> type, T[] def, boolean fuzzyArgs, Object... args)
key
- The property name.type
- The class type of the property.def
- The default object to return if the property doesn't exist.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public <T> T[] getInstanceArrayProperty(String key, Object outer, Class<T> type, T[] def, boolean fuzzyArgs, Object... args)
key
- The property name.outer
- The outer object if the class we're instantiating is an inner class.type
- The class type of the property.def
- The default object to return if the property doesn't exist.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public Set<String> getPropertyKeys(String group)
The keys are NOT prefixed with group names.
group
- The group name.public Integer hashCode(String... groups)
groups
- The names of the property groups to use in the calculation.public boolean equals(PropertyStore ps, String... groups)
ps
- The property store to compare to.groups
- The groups to compare.public Map<String,org.apache.juneau.PropertyStore.PropertyGroup> swap(BeanSession beanSession)
Allows property stores to be serialized to easy-to-read JSON objects.
beanSession
- The bean session.Copyright © 2018 Apache. All rights reserved.