Package com.norconex.commons.lang.map
Enum PropertySetter
- java.lang.Object
-
- java.lang.Enum<PropertySetter>
-
- com.norconex.commons.lang.map.PropertySetter
-
- All Implemented Interfaces:
Serializable
,Comparable<PropertySetter>
public enum PropertySetter extends Enum<PropertySetter>
Convenient way of handling the different ways a value (or values) can be set on a
Properties
instance.XML configuration usage:
onSet="[append|prepend|replace|optional]"
The above is the recommended attribute for consuming classes to use in XML configuration.
- Since:
- 2.0.0
- Author:
- Pascal Essiembre
-
-
Enum Constant Summary
Enum Constants Enum Constant Description APPEND
Inserts supplied value(s) at the end of an existing list of values associated with the supplied key.OPTIONAL
Only set supplied value(s) if the supplied key does not exist or if it does not have any values associated.PREPEND
Inserts supplied value(s) at the beginning of an existing list of values.REPLACE
Replaces all value(s) already existing for a matching key with the supplied one(s).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(Properties properties, String key, Object value)
Applies thePropertySetter
strategy on the supplied properties with the given key and value.static PropertySetter
from(String name)
static PropertySetter
from(String name, PropertySetter defaultSetter)
static PropertySetter
fromXML(XML xml, PropertySetter defaultValue)
static PropertySetter
orAppend(PropertySetter setter)
static PropertySetter
orOptional(PropertySetter setter)
static PropertySetter
orPrepend(PropertySetter setter)
static PropertySetter
orReplace(PropertySetter setter)
static void
toXML(XML xml, PropertySetter setter)
static PropertySetter
valueOf(String name)
Returns the enum constant of this type with the specified name.static PropertySetter[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
APPEND
public static final PropertySetter APPEND
Inserts supplied value(s) at the end of an existing list of values associated with the supplied key. If there are no matching keys or the key has no associated value(s), the supplied value(s) are set like a normal list addition.
-
PREPEND
public static final PropertySetter PREPEND
Inserts supplied value(s) at the beginning of an existing list of values. If there are no matching keys or the key has no associated value(s), the supplied value(s) are set like a normal list addition.
-
REPLACE
public static final PropertySetter REPLACE
Replaces all value(s) already existing for a matching key with the supplied one(s). If there are no matching keys or the key has no associated value(s), the supplied value(s) are set like a normal list addition.
-
OPTIONAL
public static final PropertySetter OPTIONAL
Only set supplied value(s) if the supplied key does not exist or if it does not have any values associated.
-
-
Method Detail
-
values
public static PropertySetter[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (PropertySetter c : PropertySetter.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static PropertySetter valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
apply
public void apply(Properties properties, String key, Object value)
Applies thePropertySetter
strategy on the supplied properties with the given key and value. Supplying anull
properties argument as no effect.- Parameters:
properties
- the properties to possibly add a key/value tokey
- the key on which we set valuevalue
- the value to possibly set
-
from
public static PropertySetter from(String name, PropertySetter defaultSetter)
-
from
public static PropertySetter from(String name)
-
orAppend
public static PropertySetter orAppend(PropertySetter setter)
-
orOptional
public static PropertySetter orOptional(PropertySetter setter)
-
orPrepend
public static PropertySetter orPrepend(PropertySetter setter)
-
orReplace
public static PropertySetter orReplace(PropertySetter setter)
-
fromXML
public static PropertySetter fromXML(XML xml, PropertySetter defaultValue)
-
toXML
public static void toXML(XML xml, PropertySetter setter)
-
-