org.cip4.jdflib.util
Class VectorMap<key,vectorObject>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<key,Vector<vectorObject>>
          extended by org.cip4.jdflib.util.VectorMap<key,vectorObject>
Type Parameters:
key - the type used for the key
vectorObject - the type used for individual elements of each vector in the map
All Implemented Interfaces:
Serializable, Cloneable, Map<key,Vector<vectorObject>>
Direct Known Subclasses:
JDFAmountPool.AmountMap

public class VectorMap<key,vectorObject>
extends HashMap<key,Vector<vectorObject>>

HashMap of multiple elements utility class

Author:
Rainer Prosi
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
VectorMap()
          null constructor
 
Method Summary
 void appendUnique(key key, Vector<vectorObject> vVal)
          append a map, ensuring uniqueness
 void appendUnique(VectorMap<key,vectorObject> map)
          append a VectorMap, ensuring uniqueness
 Vector<vectorObject> getAllValues()
          get all values as one big vector, multiple entries are retained (see ContainerUtil.unify())
 int getIndex(key key, vectorObject singleObject)
          get the index of singleObject in the vector of key
 Map<vectorObject,key> getInvertedMap()
          get an inverted map that uses all entries a s keys and vice versa
note that the behavior is undefined in case of multiple identical values
 vectorObject getOne(Object key, int i)
          get the value for key
 boolean isUnique()
          Getter for bUnique attribute.
 void putOne(key key, vectorObject val)
          put the value for key, ensuring uniqueness
 void removeOne(key key, vectorObject val)
          remove the value for key,also remove key if the vector is empty
 void setOne(key key, vectorObject newObj, int pos)
          insert the value for keyat position pos
 void setOne(key key, vectorObject newObj, vectorObject oldObj)
          replace the value for key, add if oldObj==null or is not there
 void setUnique(boolean bUnique)
          Setter for bUnique attribute.
 int size(key key)
          get the size of the vector for key
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

VectorMap

public VectorMap()
null constructor

Method Detail

getOne

public vectorObject getOne(Object key,
                           int i)
get the value for key

Parameters:
key - the search key
i - the index in the vecor matching key; if <0 count from the back of the vector
Returns:
the matching vectorObject; null if the key does not exist or i is out of range

getIndex

public int getIndex(key key,
                    vectorObject singleObject)
get the index of singleObject in the vector of key

Parameters:
key - the key of the vector
singleObject - the object to search
Returns:
-2: no such key; -1: no value in key; else the index in the vexctor of key

size

public int size(key key)
get the size of the vector for key

Parameters:
key - the key of the vector
Returns:
the size of the vector for key, 0 if no key exists

putOne

public void putOne(key key,
                   vectorObject val)
put the value for key, ensuring uniqueness

Parameters:
key - the key of the vector
val - the vector element

appendUnique

public void appendUnique(key key,
                         Vector<vectorObject> vVal)
append a map, ensuring uniqueness

Parameters:
key - the key of the vector
vVal - the vector of elements

appendUnique

public void appendUnique(VectorMap<key,vectorObject> map)
append a VectorMap, ensuring uniqueness

Parameters:
map - the map to add

getAllValues

public Vector<vectorObject> getAllValues()
get all values as one big vector, multiple entries are retained (see ContainerUtil.unify())

Returns:
a vector of all values, null if empty

getInvertedMap

public Map<vectorObject,key> getInvertedMap()
get an inverted map that uses all entries a s keys and vice versa
note that the behavior is undefined in case of multiple identical values

Returns:
an inverted map

removeOne

public void removeOne(key key,
                      vectorObject val)
remove the value for key,also remove key if the vector is empty

Parameters:
key - the key of the vector
val - the vector element

setOne

public void setOne(key key,
                   vectorObject newObj,
                   vectorObject oldObj)
replace the value for key, add if oldObj==null or is not there

Parameters:
key - the key of the vector
newObj - the new object to set
oldObj - the old object to replace

setOne

public void setOne(key key,
                   vectorObject newObj,
                   int pos)
insert the value for keyat position pos

Parameters:
key - the key of the vector
newObj - the new object to set
pos - the index in the vector, may be <0 to count from the end
Throws:
IllegalArgumentException - if pos is negative and abs(pos)>size()

isUnique

public boolean isUnique()
Getter for bUnique attribute.

Returns:
the bUnique

setUnique

public void setUnique(boolean bUnique)
Setter for bUnique attribute.

Parameters:
bUnique - the bUnique to set


Copyright © 2013. All Rights Reserved.