@NotThreadSafe
public class KeyedValues
extends Object
implements Serializable
Keyed values may hold any number of entries. Each entry is a key associated with one value or more. The order of entries within the dictionary and of values within entry are in the order of their initial insertion.
| Modifier and Type | Field and Description |
|---|---|
static String |
ANONYMOUS
Anonymous entry.
|
static float |
HASH_LOAD_FACTOR
Hash load factor.
|
protected static Comparator<Map.Entry<String,List<Object>>> |
MAP_ENTRY_COMPARATOR
Map entry comparator.
|
| Modifier | Constructor and Description |
|---|---|
|
KeyedValues()
Constructs an instance.
|
protected |
KeyedValues(KeyedValues other)
Constructs an instance from an other.
|
|
KeyedValues(String type)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(String key,
Object value)
Adds a keyed value.
|
void |
addAll(KeyedValues keyedValues)
Adds all entries from an other keyed values.
|
protected void |
addObject(String key,
Object object)
Adds a keyed object.
|
boolean |
areValuesHidden(String key)
Asks if the values for a key are hidden.
|
protected void |
checkNotFrozen()
Checks that this is not frozen.
|
void |
clear()
Clears the dictionary.
|
boolean |
containsValueKey(String key)
Asks if the key is associated with a value.
|
KeyedValues |
copy()
Creates a copy of this.
|
boolean |
equals(Object other) |
KeyedValues |
freeze()
Freezes this.
|
KeyedValues |
frozen()
Returns a frozen copy of this.
|
boolean |
getBoolean(String key)
Gets a boolean value for a key, defaulting to false.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Gets a boolean value for a key, providing a default.
|
Optional<Boolean> |
getBoolean(String key,
Optional<Boolean> defaultValue)
Gets a boolean value for a key, providing a default.
|
ClassDef |
getClassDef(String key,
ClassDef defaultClassDef)
Gets a class definition for a key, providing a default.
|
Optional<ClassDef> |
getClassDef(String key,
Optional<ClassDef> defaultClassDef)
Gets a class definition for a key, providing a default.
|
ClassDef[] |
getClassDefs(String key)
Gets the class definition array for the specified key.
|
double |
getDouble(String key,
double defaultValue)
Gets a double value for a key, providing a default.
|
Optional<ElapsedTime> |
getElapsed(String key,
Optional<ElapsedTime> defaultValue,
Optional<ElapsedTime> emptyValue)
Gets an elapsed time value for a key, providing a value for default and
empty.
|
int |
getInt(String key,
int defaultValue)
Gets an int value for a key, providing a default.
|
Optional<Integer> |
getInteger(String key,
Optional<Integer> defaultValue)
Gets an integer value for a key, providing a default.
|
long |
getLong(String key,
long defaultValue)
Gets a long value for a key, providing a default.
|
Optional<Long> |
getLong(String key,
Optional<Long> defaultValue)
Gets a long value for a key, providing a default.
|
Optional<?> |
getObject(String key)
Gets the object for a key.
|
List<Object> |
getObjects(String key)
Gets the object list for a key.
|
Optional<char[]> |
getPassword(String key)
Gets the password value for a key.
|
Optional<String> |
getString(String key)
Gets a string value for a key.
|
Optional<String> |
getString(String key,
Optional<String> defaultValue)
Gets the first value for a key, providing a default.
|
String[] |
getStrings(String key)
Gets the values for the specified key.
|
protected Logger |
getThisLogger()
Gets the logger.
|
String |
getType()
Gets the type of value stored in the dictionary.
|
Object[] |
getValues(String key)
Gets the values for the specified key.
|
Set<Map.Entry<String,List<Object>>> |
getValuesEntries()
Gets the Set of entries.
|
Set<String> |
getValuesKeys()
Gets the set of keys for the values.
|
int |
getValuesSize()
Gets the size of the values map.
|
static int |
hashCapacity(int count)
Computes the hash capacity needed to hold a specified key count.
|
int |
hashCode() |
boolean |
isEmpty()
Asks if this is empty.
|
boolean |
isFrozen()
Asks if this is frozen.
|
boolean |
isHidden()
Gets the hidden indicator.
|
boolean |
isMultiple(String key)
Asks if a key has multiple values.
|
void |
removeValue(String key)
Removes a keyed value.
|
void |
setHidden(boolean hidden)
Sets the hidden indicator.
|
protected void |
setObjects(String key,
List<Object> objects)
Sets the object list for a key.
|
void |
setValue(String key,
Object value)
Sets a keyed value.
|
void |
setValuesHidden(String key)
Sets the values hidden for the specified key.
|
String |
substitute(String text,
boolean deferred)
Substitutes markers in a given text.
|
KeyedValues |
thawed()
Returns a thawed instance of this.
|
String |
toString() |
public static final String ANONYMOUS
public static final float HASH_LOAD_FACTOR
protected static final Comparator<Map.Entry<String,List<Object>>> MAP_ENTRY_COMPARATOR
public KeyedValues()
public KeyedValues(@Nonnull
String type)
type - A string identifying the type of value stored.protected KeyedValues(@Nonnull
KeyedValues other)
other - The other instance.@CheckReturnValue public static int hashCapacity(int count)
count - The expected key count.public void add(@Nonnull
String key,
@Nonnull
Object value)
If the key is already in the dictionary, the value is appended to the list of values for that key.
key - The value key.value - The value.public final void addAll(@Nonnull
KeyedValues keyedValues)
The new values are appended to those already present.
keyedValues - The other keyed values.@CheckReturnValue
public boolean areValuesHidden(@Nonnull
String key)
key - The key.public void clear()
@CheckReturnValue
public boolean containsValueKey(@Nonnull
String key)
key - The key to look for.@Nonnull @CheckReturnValue public KeyedValues copy()
public boolean equals(Object other)
equals in class Object@Nonnull public KeyedValues freeze()
@Nonnull @CheckReturnValue public KeyedValues frozen()
@CheckReturnValue
public final boolean getBoolean(@Nonnull
String key)
If the key is not found or its value is unrecognized, false will be returned.
key - The name of the value.getBoolean(String key, boolean defaultValue)@CheckReturnValue
public final boolean getBoolean(@Nonnull
String key,
boolean defaultValue)
If the key is not found or its value is unrecognized the default will be returned.
key - The name of the value.defaultValue - The default value for the key.@Nonnull
@CheckReturnValue
public final Optional<Boolean> getBoolean(@Nonnull
String key,
@Nonnull
Optional<Boolean> defaultValue)
If the key is not found or its value is unrecognized the default will be returned.
key - The name of the value.defaultValue - The default value for the key (may be empty).@Nonnull @CheckReturnValue public final ClassDef getClassDef(@Nonnull String key, @Nonnull ClassDef defaultClassDef)
A string value will be converted to a class definition.
key - The key for the class definition.defaultClassDef - The default for the key.@Nonnull @CheckReturnValue public final Optional<ClassDef> getClassDef(@Nonnull String key, @Nonnull Optional<ClassDef> defaultClassDef)
A string value will be converted to a class definition.
key - The key for the class definition.defaultClassDef - The default for the key.@Nonnull @CheckReturnValue public final ClassDef[] getClassDefs(@Nonnull String key)
String values will be converted to class definitionss.
key - The key for the requested class definitions array.public final double getDouble(@Nonnull
String key,
double defaultValue)
If the key is not found or its value is unrecognized the default will be returned.
key - The key for the value.defaultValue - The default value.@Nonnull @CheckReturnValue public final Optional<ElapsedTime> getElapsed(@Nonnull String key, @Nonnull Optional<ElapsedTime> defaultValue, @Nonnull Optional<ElapsedTime> emptyValue)
key - The key for the elapsed time.defaultValue - The default.emptyValue - The assumed value for empty.@CheckReturnValue
public final int getInt(@Nonnull
String key,
int defaultValue)
If the key is not found or its value is unrecognized, the default will be returned.
key - The name of the value.defaultValue - The default value.@Nonnull
@CheckReturnValue
public final Optional<Integer> getInteger(@Nonnull
String key,
@Nonnull
Optional<Integer> defaultValue)
key - The name of the value.defaultValue - The default value (may be empty).@CheckReturnValue
public final long getLong(@Nonnull
String key,
long defaultValue)
If the key is not found or its value is unrecognized, the default will be returned.
key - The name of the value.defaultValue - The default value.@Nonnull
@CheckReturnValue
public final Optional<Long> getLong(@Nonnull
String key,
@Nonnull
Optional<Long> defaultValue)
key - The name of the value.defaultValue - The default value (may be empty).@Nonnull
@CheckReturnValue
public final Optional<?> getObject(@Nonnull
String key)
key - The object key.@Nonnull
@CheckReturnValue
public List<Object> getObjects(@Nonnull
String key)
key - The object key.@Nonnull
@CheckReturnValue
public final Optional<char[]> getPassword(@Nonnull
String key)
key - The value name.@Nonnull
@CheckReturnValue
public final Optional<String> getString(@Nonnull
String key)
key - The value name.@Nonnull
@CheckReturnValue
public final Optional<String> getString(@Nonnull
String key,
@Nonnull
Optional<String> defaultValue)
key - The value name.defaultValue - The value to return if the key is not present.@Nonnull
@CheckReturnValue
public final String[] getStrings(@Nonnull
String key)
key - The values name.@Nonnull @CheckReturnValue public String getType()
@Nonnull
@CheckReturnValue
public Object[] getValues(@Nonnull
String key)
key - The key for the requested values.@Nonnull @CheckReturnValue public final Set<Map.Entry<String,List<Object>>> getValuesEntries()
@Nonnull @CheckReturnValue public final Set<String> getValuesKeys()
@CheckReturnValue public int getValuesSize()
public int hashCode()
hashCode in class Object@CheckReturnValue public boolean isEmpty()
@CheckReturnValue public final boolean isFrozen()
@CheckReturnValue public final boolean isHidden()
@CheckReturnValue
public boolean isMultiple(@Nonnull
String key)
key - The key.public void removeValue(@Nonnull
String key)
key - The value key.public final void setHidden(boolean hidden)
hidden - The hidden indicator.public void setValue(@Nonnull
String key,
@Nonnull
Object value)
If the key is already in the dictionary, its value is replaced.
key - The value key.value - The value.public void setValuesHidden(@Nonnull
String key)
key - The key.@Nonnull
@CheckReturnValue
public final String substitute(@Nonnull
String text,
boolean deferred)
A substitution marker would be a '${x}' property reference.
Note: when the property ('x') is not found, en empty string is used.
text - The text possibly containing substitution markers.deferred - True if substitution of '$${x}' should be deferred.@Nonnull @CheckReturnValue public KeyedValues thawed()
@Nonnull @CheckReturnValue public String toString()
toString in class Objectprotected final void addObject(@Nonnull
String key,
@Nonnull
Object object)
If the key is already in the dictionary, the value is appended to the list of objects for that key.
key - The object key.object - The object.protected final void checkNotFrozen()
@Nonnull @CheckReturnValue protected final Logger getThisLogger()
protected void setObjects(@Nonnull
String key,
@Nonnull
List<Object> objects)
key - The object key.objects - The object list.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.