Package org.jibx.binding.util
Class MultipleValueMap
- java.lang.Object
-
- org.jibx.binding.util.MultipleValueMap
-
public class MultipleValueMap extends java.lang.ObjectMap supporting multiple values for a single key. The multiple value concept doesn't really fit with the standard collections idea of a map, so this provides its own variation of a map interface rather than extend the standard one.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMultipleValueMap.MultipleIteratorIterator for only the multiple-valued keys in the map.private static classMultipleValueMap.MultipleValueListList used for multiple values.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMapm_backingMapBacking map from key to value or array of values.private java.lang.Objectm_lastKeyLast lookup key (nullif none, or if value changed).private java.lang.Objectm_lastValueLast lookup value (nullif none, or if value changed).private intm_valueCountActual number of values (not keys) present in map.
-
Constructor Summary
Constructors Constructor Description MultipleValueMap()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.Object key, java.lang.Object value)Add value for key.voidclear()Clear all entries.booleancontainsKey(java.lang.Object key)Check key present in map.java.util.ArrayListextract(java.lang.Object key)Extract all values for key.java.util.ArrayListget(java.lang.Object key)Get all values for key.java.lang.Objectget(java.lang.Object key, int index)Get indexed value for key.intgetCount(java.lang.Object key)Get number of values present for key.private java.lang.ObjectgetMapped(java.lang.Object key)Internal cached lookup.booleanisEmpty()Check if map is empty.java.util.SetkeySet()Get key set.intkeySize()Get number of keys.java.util.IteratormultipleIterator()Get iterator over only the multiple-valued keys present in the map.intvalueSize()Get number of values.
-
-
-
Field Detail
-
m_backingMap
private final java.util.HashMap m_backingMap
Backing map from key to value or array of values.
-
m_valueCount
private int m_valueCount
Actual number of values (not keys) present in map.
-
m_lastKey
private java.lang.Object m_lastKey
Last lookup key (nullif none, or if value changed).
-
m_lastValue
private java.lang.Object m_lastValue
Last lookup value (nullif none, or if value changed).
-
-
Method Detail
-
getMapped
private java.lang.Object getMapped(java.lang.Object key)
Internal cached lookup.- Parameters:
key-- Returns:
- value
-
clear
public void clear()
Clear all entries.
-
getCount
public int getCount(java.lang.Object key)
Get number of values present for key.- Parameters:
key-- Returns:
- value count
-
get
public java.lang.Object get(java.lang.Object key, int index)Get indexed value for key.- Parameters:
key-index-- Returns:
- value
-
add
public void add(java.lang.Object key, java.lang.Object value)Add value for key.- Parameters:
key-value-
-
get
public java.util.ArrayList get(java.lang.Object key)
Get all values for key. This returns the value(s) from the map and returns them in the form of a list.- Parameters:
key-- Returns:
- list of values
-
extract
public java.util.ArrayList extract(java.lang.Object key)
Extract all values for key. This removes the value(s) from the map and returns them in the form of a list.- Parameters:
key-- Returns:
- prior list of values
-
keySize
public int keySize()
Get number of keys.- Returns:
- key count
-
valueSize
public int valueSize()
Get number of values.- Returns:
- value count
-
multipleIterator
public java.util.Iterator multipleIterator()
Get iterator over only the multiple-valued keys present in the map.- Returns:
- iterator
-
containsKey
public boolean containsKey(java.lang.Object key)
Check key present in map.- Parameters:
key-- Returns:
- key present flag
-
isEmpty
public boolean isEmpty()
Check if map is empty.- Returns:
- empty flag
-
keySet
public java.util.Set keySet()
Get key set.- Returns:
- set of keys
-
-