Package com.day.util

Class OrderedStringKeyMap


  • public class OrderedStringKeyMap
    extends java.lang.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
      OrderedStringKeyMap()
      creates a new OrderedMap
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all of the elements from this key map.
      boolean contains​(java.lang.Object o)
      Checks if this map contains the specified value.
      boolean contains​(java.lang.String key)
      Checks if this map contains the specified key.
      boolean containsKey​(java.lang.String key)
      Checks if this map contains the specified key.
      boolean containsValue​(java.lang.Object o)
      Checks if this map contains the specified value.
      java.util.Set entrySet()
      Returns a collection view of the mappings contained in this map.
      java.lang.Object get​(int index)
      Returns the element at the specified position in this list.
      java.lang.Object get​(java.lang.String key)
      Returns the value with the given key or null if the values is not in this map.
      int indexOf​(java.lang.Object value)
      Searches for the first occurence of the given argument, testing for equality using the equals method.
      boolean isEmpty()
      Checks if this map is empty.
      java.util.Iterator iterator()
      Returns an iterator over the elements in this list in proper sequence.
      java.util.Iterator iterator​(boolean reverse)
      Returns an iterator over the elements in this list in proper sequence.
      java.util.Iterator keys()
      Returns an iterator over all keys in the map in any order.
      java.util.Set keySet()
      Returns a set view of the keys contained in this map.
      java.lang.Object lastElement()
      Returns the last element of this list, or null if this list is empty.
      void move​(java.lang.String key, java.lang.String above)
      Moves the element with the key above the one specified with above.
      java.lang.Object put​(java.lang.String key, java.lang.Object value)
      Puts an element into the map and appends it to the end of the list.
      java.lang.Object put​(java.lang.String key, java.lang.Object value, int index)
      Inserts the specified element at the specified position in this list.
      java.lang.Object put​(java.lang.String key, java.lang.Object value, java.lang.String above)
      Inserts the specified element above the element specified with above.
      java.lang.Object remove​(int index)
      Removes the element at the specified position in this list.
      java.lang.Object remove​(java.lang.String key)
      Removes the mapping for this key from this map if present.
      java.lang.Object set​(java.lang.String key, java.lang.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 size()
      Returns the number of the elelemts in this map
      java.lang.Object[] toArray()
      Returns an array containing all of the elements in this list in the correct order.
      java.lang.Object[] toArray​(java.lang.Object[] a)
      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 Detail

      • OrderedStringKeyMap

        public OrderedStringKeyMap()
        creates a new OrderedMap
    • Method Detail

      • 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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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 java.lang.Object get​(java.lang.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 java.lang.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:
        java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).
      • iterator

        public java.util.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 java.util.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 java.util.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 java.lang.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 java.lang.Object[] toArray​(java.lang.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:
        java.lang.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 java.lang.Object put​(java.lang.String key,
                                    java.lang.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 java.lang.Object set​(java.lang.String key,
                                    java.lang.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​(java.lang.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:
        Object.equals(Object)
      • put

        public java.lang.Object put​(java.lang.String key,
                                    java.lang.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:
        java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).
      • put

        public java.lang.Object put​(java.lang.String key,
                                    java.lang.Object value,
                                    java.lang.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 java.lang.Object remove​(java.lang.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 java.lang.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:
        java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).
      • lastElement

        public java.lang.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​(java.lang.String key,
                         java.lang.String above)
        Moves the element with the key above the one specified with above.
        Parameters:
        key - the key
        above - the above value
      • entrySet

        public java.util.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:
        Map.Entry
      • keySet

        public java.util.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.