Package com.day.util

Class OrderedStringKeyMap

java.lang.Object
com.day.util.OrderedStringKeyMap

public class OrderedStringKeyMap extends Object
a simple implementation for a map with internal ordering. it actually combines a list with a map. but takes only strings as keys.
Since:
antbear Audience wad
  • Constructor Summary

    Constructors
    Constructor
    Description
    creates a new OrderedMap
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all of the elements from this key map.
    boolean
    Checks if this map contains the specified value.
    boolean
    Checks if this map contains the specified key.
    boolean
    Checks if this map contains the specified key.
    boolean
    Checks if this map contains the specified value.
    Returns a collection view of the mappings contained in this map.
    get(int index)
    Returns the element at the specified position in this list.
    get(String key)
    Returns the value with the given key or null if the values is not in this map.
    int
    indexOf(Object value)
    Searches for the first occurence of the given argument, testing for equality using the equals method.
    boolean
    Checks if this map is empty.
    Returns an iterator over the elements in this list in proper sequence.
    iterator(boolean reverse)
    Returns an iterator over the elements in this list in proper sequence.
    Returns an iterator over all keys in the map in any order.
    Returns a set view of the keys contained in this map.
    Returns the last element of this list, or null if this list is empty.
    void
    move(String key, String above)
    Moves the element with the key above the one specified with above.
    put(String key, Object value)
    Puts an element into the map and appends it to the end of the list.
    put(String key, Object value, int index)
    Inserts the specified element at the specified position in this list.
    put(String key, Object value, String above)
    Inserts the specified element above the element specified with above.
    remove(int index)
    Removes the element at the specified position in this list.
    Removes the mapping for this key from this map if present.
    set(String key, Object value)
    Puts an element in this key map and replaces it in the internal list if an element with the key already exists, or appends it to the end of the list, otherwise.
    int
    Returns the number of the elelemts in this map
    Returns an array containing all of the elements in this list in the correct order.
    Returns an array containing all of the elements in this list in the correct order.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OrderedStringKeyMap

      public OrderedStringKeyMap()
      creates a new OrderedMap
  • Method Details

    • size

      public int size()
      Returns the number of the elelemts in this map
      Returns:
      the number of the elelemts in this map
    • isEmpty

      public boolean isEmpty()
      Checks if this map is empty.
      Returns:
      true if this map is empty; false otherwise.
    • contains

      public boolean contains(Object o)
      Checks if this map contains the specified value.
      Parameters:
      o - the object the check
      Returns:
      true if this map contains the value; false otherwise.
    • contains

      public boolean contains(String key)
      Checks if this map contains the specified key.
      Parameters:
      key - the key to check
      Returns:
      true if this map contaisn the key; false otherwise.
    • containsValue

      public boolean containsValue(Object o)
      Checks if this map contains the specified value.
      Parameters:
      o - the object the check
      Returns:
      true if this map contains the value; false otherwise.
    • containsKey

      public boolean containsKey(String key)
      Checks if this map contains the specified key.
      Parameters:
      key - the key to check
      Returns:
      true if this map contaisn the key; false otherwise.
    • get

      public Object get(String key)
      Returns the value with the given key or null if the values is not in this map.
      Parameters:
      key - the key of the value
      Returns:
      the value or null
    • get

      public Object get(int index)
      Returns the element at the specified position in this list.
      Parameters:
      index - index of element to return.
      Returns:
      the element at the specified position in this list.
      Throws:
      IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).
    • iterator

      public Iterator iterator()
      Returns an iterator over the elements in this list in proper sequence.
      Returns:
      an iterator over the elements in this list in proper sequence.
    • iterator

      public Iterator iterator(boolean reverse)
      Returns an iterator over the elements in this list in proper sequence.
      Parameters:
      reverse - if set to true, the elemens are iterated in reverse order
      Returns:
      an iterator over the elements in this list in proper sequence.
    • keys

      public Iterator keys()
      Returns an iterator over all keys in the map in any order.
      Returns:
      an iterator over all keys in the map in any order.
    • toArray

      public Object[] toArray()
      Returns an array containing all of the elements in this list in the correct order.
      Returns:
      an array containing all of the elements in this list in the correct order.
    • toArray

      public Object[] toArray(Object[] a)
      Returns an array containing all of the elements in this list in the correct order. The runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

      If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.

      Parameters:
      a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
      an array containing the elements of the list.
      Throws:
      ArrayStoreException - if the runtime type of a is not a supertype of the runtime type of every element in this list.
    • clear

      public void clear()
      Removes all of the elements from this key map. The key map will be empty after this call returns.
    • put

      public Object put(String key, Object value)
      Puts an element into the map and appends it to the end of the list.
      Parameters:
      key - the key of the element
      value - the value of the element
      Returns:
      the old element that was assigned with this key or null if there was no such element.
    • set

      public Object set(String key, Object value)
      Puts an element in this key map and replaces it in the internal list if an element with the key already exists, or appends it to the end of the list, otherwise.
      Parameters:
      key - the key of the element
      value - the value of the element
      Returns:
      the old element that was assigned with this key or null if there was no such element.
    • indexOf

      public int indexOf(Object value)
      Searches for the first occurence of the given argument, testing for equality using the equals method.
      Parameters:
      value - an object.
      Returns:
      the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
      See Also:
    • put

      public Object put(String key, Object value, int index)
      Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      Parameters:
      key - the key of the element
      value - element to be inserted.
      index - index at which the specified element is to be inserted.
      Returns:
      the old element that was assigned with this key or null if there was no such element.
      Throws:
      IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).
    • put

      public Object put(String key, Object value, String above)
      Inserts the specified element above the element specified with above.
      Parameters:
      key - the key of the element
      value - element to be inserted.
      above - the key of the element to insert above
      Returns:
      the old element that was assigned with this key or null if there was no such element.
    • remove

      public Object remove(String key)
      Removes the mapping for this key from this map if present.
      Parameters:
      key - key whose mapping is to be removed from the map.
      Returns:
      previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
    • remove

      public Object remove(int index)
      Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
      Parameters:
      index - the index of the element to removed.
      Returns:
      the element that was removed from the list.
      Throws:
      IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).
    • lastElement

      public Object lastElement()
      Returns the last element of this list, or null if this list is empty.
      Returns:
      the last element of this list.
    • move

      public void move(String key, String above)
      Moves the element with the key above the one specified with above.
      Parameters:
      key - the key
      above - the above value
    • entrySet

      public Set entrySet()
      Returns a collection view of the mappings contained in this map. Each element in the returned collection is a Map.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
      Returns:
      a collection view of the mappings contained in this map.
      See Also:
    • keySet

      public Set keySet()
      Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
      Returns:
      a set view of the keys contained in this map.