Package org.jibx.util

Class ReferenceCountMap


  • public class ReferenceCountMap
    extends Object
    Hash map for counting references to Object keys. 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 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.
        Overrides:
        clone in class Object
        Returns:
        shallow copy of table
      • clear

        public void clear()
        Clear all keys and counts.