Package com.groiss.ds

Class KeyedList<K,V>

java.lang.Object
com.groiss.ds.KeyedList<K,V>
All Implemented Interfaces:
Iterable<V>, Collection<V>, List<V>

public class KeyedList<K,V> extends Object implements List<V>
This class implements an ordered map. A list of keys is mapped to a list of values. The values can be accessed by the key or the position in the list.
  • Constructor Details

    • KeyedList

      public KeyedList()
    • KeyedList

      public KeyedList(List<K> keys, List<V> content)
      Create a new KeyedList.
      Parameters:
      keys -
      content -
  • Method Details

    • put

      public void put(K key, V elem)
      Put an element to the end of the list.
      Parameters:
      key - a key
      elem - an element
    • put

      public void put(int pos, K key, V elem)
      Put an element at position.
      Parameters:
      pos - insert after this position
      key - a key
      elem - an element
    • get

      public V get(Object key)
      Get the object mapped to the given key.
      Parameters:
      key -
      Returns:
      the object for this key, null if key not bound to an object
    • set

      public void set(K key, V elem)
      Replace the element mapped to key with the given element.
      Parameters:
      key -
      elem -
    • values

      public List<V> values()
      Return the content list.
      Returns:
      the content.
    • getKey

      public K getKey(int i)
      Returns the key a postion i
      Parameters:
      i - the position
      Returns:
      the key a position i
    • getKeyIterator

      public Iterator<K> getKeyIterator()
      Returns an iterator for the key list
      Returns:
      an iterotor over key
    • getKeys

      public List<K> getKeys()
    • getKey

      public int getKey(Object key)
      Return the position of the given key in the key list.
      Parameters:
      key -
      Returns:
      the position of the key, -1 if not in keys
    • removeKey

      public boolean removeKey(Object key)
      Removes the key (and associated object) from the list
      Parameters:
      key -
      Returns:
      true it the key was in the list
    • size

      public int size()
      Specified by:
      size in interface Collection<K>
      Specified by:
      size in interface List<K>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<K>
      Specified by:
      clear in interface List<K>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<K>
      Specified by:
      isEmpty in interface List<K>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<K>
      Specified by:
      toArray in interface List<K>
    • get

      public V get(int pos)
      Specified by:
      get in interface List<K>
    • remove

      public V remove(int pos)
      Specified by:
      remove in interface List<K>
    • add

      public void add(int pos, V o)
      Specified by:
      add in interface List<K>
    • indexOf

      public int indexOf(Object o)
      Specified by:
      indexOf in interface List<K>
    • lastIndexOf

      public int lastIndexOf(Object o)
      Specified by:
      lastIndexOf in interface List<K>
    • add

      public boolean add(V o)
      Caution: This method destroys the one-to-one relation between keys and content! It manipulates only the content.
      Specified by:
      add in interface Collection<K>
      Specified by:
      add in interface List<K>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<K>
      Specified by:
      contains in interface List<K>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<K>
      Specified by:
      remove in interface List<K>
    • addAll

      public boolean addAll(int i, Collection<? extends V> c)
      Caution: This method destroys the one-to-one relation between keys and content! It manipulates only the content.
      Specified by:
      addAll in interface List<K>
    • addAll

      public boolean addAll(Collection<? extends V> c)
      Caution: This method destroys the one-to-one relation between keys and content! It manipulates only the content.
      Specified by:
      addAll in interface Collection<K>
      Specified by:
      addAll in interface List<K>
    • addAll

      public boolean addAll(KeyedList<K,V> c)
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<K>
      Specified by:
      containsAll in interface List<K>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<K>
      Specified by:
      removeAll in interface List<K>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<K>
      Specified by:
      retainAll in interface List<K>
    • iterator

      public Iterator<V> iterator()
      Specified by:
      iterator in interface Collection<K>
      Specified by:
      iterator in interface Iterable<K>
      Specified by:
      iterator in interface List<K>
    • subList

      public List<V> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<K>
    • listIterator

      public ListIterator<V> listIterator()
      Specified by:
      listIterator in interface List<K>
    • listIterator

      public ListIterator<V> listIterator(int i)
      Specified by:
      listIterator in interface List<K>
    • set

      public V set(int i, V o)
      Specified by:
      set in interface List<K>
    • toArray

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<K>
      Specified by:
      toArray in interface List<K>