Class OrderedTwoWayTable


  • public class OrderedTwoWayTable
    extends java.lang.Object
    A map-like structure which has two side-by-side ordered sets of Objects in pairs. This is basically a map structure except that it is always ordered and has a less strict an idea of key and value. The terms key and value are still used to differentiate data from the two sets. The primary advantage to using this class is that you can do lookups either by key or value, in case where translation in both directions is necessary.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected int findIndex​(java.util.Vector<?> data, java.lang.Object target)
      Get the index of the target in the table.
      java.lang.Object getKeyAt​(int index)
      Get the key at the given index.
      int getKeyIndex​(java.lang.Object key)
      Get the position of the key within the table.
      int getSize()
      Get the number of pairs in the table.
      java.lang.Object getValueAt​(int index)
      Get the value at the given index.
      int getValueIndex​(java.lang.Object value)
      Get the position of a value within the table.
      void put​(java.lang.Object key, java.lang.Object value)
      Put an object in the table.
      void remove​(int index)
      Remove the object at a specified index.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OrderedTwoWayTable

        public OrderedTwoWayTable()
    • Method Detail

      • put

        public void put​(java.lang.Object key,
                        java.lang.Object value)
        Put an object in the table.
        Parameters:
        key - the key for this object
        value - the object to be stored in the table
      • getKeyIndex

        public int getKeyIndex​(java.lang.Object key)
        Get the position of the key within the table.
        Parameters:
        key - the key whose position is required
        Returns:
        the position of the key within the table, or -1 if not found
      • getValueIndex

        public int getValueIndex​(java.lang.Object value)
        Get the position of a value within the table.
        Parameters:
        value - the value whose position is required
        Returns:
        the position of the value within the table, or -1 if not found
      • getValueAt

        public java.lang.Object getValueAt​(int index)
        Get the value at the given index.
        Parameters:
        index - the index of the required value
        Returns:
        the value at the given index, or null if not found or index out of bounds.
      • getKeyAt

        public java.lang.Object getKeyAt​(int index)
        Get the key at the given index.
        Parameters:
        index - the index of the given key
        Returns:
        the value at the given index, null if not found or index out of bounds.
      • getSize

        public int getSize()
        Get the number of pairs in the table.
        Returns:
        the numbver of pairs on the table
      • remove

        public void remove​(int index)
        Remove the object at a specified index.
        Parameters:
        index - the index of the entry to be removed.
      • findIndex

        protected int findIndex​(java.util.Vector<?> data,
                                java.lang.Object target)
        Get the index of the target in the table. This is a reference equality search.
        Parameters:
        data - the vector in which to search
        target - the object to search for
        Returns:
        the index of the target in the vector, or -1 if not found