Class KeyedObjects<K extends Comparable<K>>

    • Constructor Summary

      Constructors 
      Constructor Description
      KeyedObjects()
      Creates a new collection (initially empty).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addObject​(K key, Object object)
      Adds a new object to the collection, or overwrites an existing object.
      void clear()
      Clears all values from the collection.
      Object clone()
      Returns a clone of this object.
      boolean equals​(Object obj)
      Tests this object for equality with an arbitrary object.
      int getIndex​(K key)
      Returns the index for a given key, or -1.
      int getItemCount()
      Returns the number of items (values) in the collection.
      K getKey​(int index)
      Returns the key at the specified position in the list.
      List<K> getKeys()
      Returns a list containing all the keys in the list.
      Object getObject​(int item)
      Returns an object from the list.
      Object getObject​(K key)
      Returns the object for a given key.
      int hashCode()
      Returns a hash code.
      void insertValue​(int position, K key, Object value)
      Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position.
      void removeValue​(int index)
      Removes a value from the collection.
      void removeValue​(K key)
      Removes a value from the collection.
      void setObject​(K key, Object object)
      Replaces an existing object, or adds a new object to the collection.
    • Constructor Detail

      • KeyedObjects

        public KeyedObjects()
        Creates a new collection (initially empty).
    • Method Detail

      • getItemCount

        public int getItemCount()
        Returns the number of items (values) in the collection.
        Returns:
        The item count.
      • getObject

        public Object getObject​(int item)
        Returns an object from the list.
        Parameters:
        item - the item index (zero-based).
        Returns:
        The object (possibly null).
        Throws:
        IndexOutOfBoundsException - if item is out of bounds.
      • getKey

        public K getKey​(int index)
        Returns the key at the specified position in the list.
        Parameters:
        index - the item index (zero-based).
        Returns:
        The row key.
        Throws:
        IndexOutOfBoundsException - if item is out of bounds.
        See Also:
        getIndex(Comparable)
      • getIndex

        public int getIndex​(K key)
        Returns the index for a given key, or -1.
        Parameters:
        key - the key (null not permitted).
        Returns:
        The index, or -1 if the key is unrecognised.
        See Also:
        getKey(int)
      • getKeys

        public List<KgetKeys()
        Returns a list containing all the keys in the list.
        Returns:
        The keys (never null).
      • getObject

        public Object getObject​(K key)
        Returns the object for a given key. If the key is not recognised, the method should return null.
        Parameters:
        key - the key.
        Returns:
        The object (possibly null).
        See Also:
        addObject(Comparable, Object)
      • insertValue

        public void insertValue​(int position,
                                K key,
                                Object value)
        Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position.
        Parameters:
        position - the position (in the range 0 to getItemCount()).
        key - the key (null not permitted).
        value - the value (null permitted).
        Since:
        1.0.7
      • removeValue

        public void removeValue​(int index)
        Removes a value from the collection.
        Parameters:
        index - the index of the item to remove.
        See Also:
        removeValue(Comparable)
      • clear

        public void clear()
        Clears all values from the collection.
        Since:
        1.0.7
      • equals

        public boolean equals​(Object obj)
        Tests this object for equality with an arbitrary object.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object (null permitted).
        Returns:
        A boolean.
      • hashCode

        public int hashCode()
        Returns a hash code.
        Overrides:
        hashCode in class Object
        Returns:
        A hash code.