Package org.jibx.util
Class ReferenceCountMap
- java.lang.Object
-
- org.jibx.util.ReferenceCountMap
-
public class ReferenceCountMap extends Object
Hash map for counting references toObjectkeys. The map implementation is not very efficient when resizing, but works well when the size of the map is known in advance or when accesses are substantially more common than adds.- Author:
- Dennis M. Sosnoski
-
-
Constructor Summary
Constructors Constructor Description ReferenceCountMap()Default constructor.ReferenceCountMap(int count)Constructor with count.ReferenceCountMap(ReferenceCountMap base)Copy (clone) constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all keys and counts.Objectclone()Construct a copy of the table.intgetCount(Object key)Find an entry in the table.intincrementCount(Object key)Increment a use count in the table.Iteratoriterator()Get iterator for keys in map.Object[]keyArray()Get array of keys in map.intsize()Get number of entries in map.
-
-
-
Constructor Detail
-
ReferenceCountMap
public ReferenceCountMap(int count)
Constructor with count.- Parameters:
count- number of values to assume in initial sizing of table
-
ReferenceCountMap
public ReferenceCountMap()
Default constructor.
-
ReferenceCountMap
public ReferenceCountMap(ReferenceCountMap base)
Copy (clone) constructor.- Parameters:
base- instance being copied
-
-
Method Detail
-
incrementCount
public int incrementCount(Object key)
Increment a use count in the table. If the key object is already present in the table this adds one to the reference count; if not present, this adds the key with an initial reference count of one.- Parameters:
key- referenced object (non-null)- Returns:
- incremented use count
-
getCount
public final int getCount(Object key)
Find an entry in the table.- Parameters:
key- key for entry to be returned- Returns:
- value for key, or zero if key not found
-
size
public int size()
Get number of entries in map.- Returns:
- entry count
-
iterator
public Iterator iterator()
Get iterator for keys in map. The returned iterator is not safe, so the iterator behavior is undefined if the map is modified.- Returns:
- iterator
-
keyArray
public Object[] keyArray()
Get array of keys in map.- Returns:
- key array
-
clone
public Object clone()
Construct a copy of the table.
-
clear
public void clear()
Clear all keys and counts.
-
-