Class OrderedTwoWayTable

java.lang.Object
com.sun.javatest.util.OrderedTwoWayTable

public class OrderedTwoWayTable extends 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.
  • Constructor Details

    • OrderedTwoWayTable

      public OrderedTwoWayTable()
  • Method Details

    • put

      public void put(Object key, 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(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(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 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 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(Vector<?> data, 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