processing.data

## Class StringDict

- Object
- - StringDict

-     public class StringDict
      extends Object

  A simple table class to use a String as a lookup for another String value.
  See Also:
    `IntDict`, `FloatDict`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringDict()`
    `StringDict(BufferedReader reader)` Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab.
    `StringDict(int length)` Create a new lookup pre-allocated to a specific length.
    `StringDict(String[][] pairs)` Constructor to allow (more intuitive) inline initialization, e.g.:
    `StringDict(String[] keys, String[] values)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Remove all entries.
    `StringDict` | `copy()` Returns a duplicate copy of this object.
    `String` | `get(String key)` Return a value for the specified key.
    `String` | `get(String key, String alternate)`
    `boolean` | `hasKey(String key)`
    `int` | `index(String what)`
    `String` | `key(int index)`
    `String[]` | `keyArray()` Return a copy of the internal keys array.
    `String[]` | `keyArray(String[] outgoing)`
    `Iterable<String>` | `keys()`
    `void` | `print()`
    `int` | `remove(String key)`
    `String` | `removeIndex(int index)`
    `void` | `set(String key, String value)`
    `int` | `size()`
    `void` | `sortKeys()` Sort the keys alphabetically (ignoring case).
    `void` | `sortKeysReverse()`
    `void` | `sortValues()` Sort by values in descending order (largest value will be at [0]).
    `void` | `sortValuesReverse()`
    `void` | `swap(int a, int b)`
    `String` | `toString()`
    `String` | `value(int index)`
    `String[]` | `valueArray()` Create a new array and copy each of the values into it.
    `String[]` | `valueArray(String[] array)` Fill an already-allocated array with the values (more efficient than creating a new array each time).
    `Iterable<String>` | `values()`
    `void` | `write(PrintWriter writer)` Write tab-delimited entries out to

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### StringDict

          public StringDict()

    - #### StringDict

          public StringDict(int length)

      Create a new lookup pre-allocated to a specific length. This will not change the size(), but is more efficient than not specifying a length. Use it when you know the rough size of the thing you're creating.

    - #### StringDict

          public StringDict(BufferedReader reader)

      Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab.

    - #### StringDict

          public StringDict(String[] keys,
                            String[] values)

    - #### StringDict

          public StringDict(String[][] pairs)

      Constructor to allow (more intuitive) inline initialization, e.g.:

           new StringDict(new String[][] {
             { "key1", "value1" },
             { "key2", "value2" }
           });

      It's no Python, but beats a static { } block with HashMap.put() statements.

  - ### Method Detail

    - #### size

          public int size()

    - #### clear

          public void clear()

      Remove all entries.

    - #### key

          public String key(int index)

    - #### keys

          public Iterable<String> keys()

    - #### keyArray

          public String[] keyArray()

      Return a copy of the internal keys array. This array can be modified.

    - #### keyArray

          public String[] keyArray(String[] outgoing)

    - #### value

          public String value(int index)

    - #### values

          public Iterable<String> values()

    - #### valueArray

          public String[] valueArray()

      Create a new array and copy each of the values into it.

    - #### valueArray

          public String[] valueArray(String[] array)

      Fill an already-allocated array with the values (more efficient than creating a new array each time). If 'array' is null, or not the same size as the number of values, a new array will be allocated and returned.

    - #### get

          public String get(String key)

      Return a value for the specified key.

    - #### get

          public String get(String key,
                            String alternate)

    - #### set

          public void set(String key,
                          String value)

    - #### index

          public int index(String what)

    - #### hasKey

          public boolean hasKey(String key)

    - #### remove

          public int remove(String key)

    - #### removeIndex

          public String removeIndex(int index)

    - #### swap

          public void swap(int a,
                           int b)

    - #### sortKeys

          public void sortKeys()

      Sort the keys alphabetically (ignoring case). Uses the value as a tie-breaker (only really possible with a key that has a case change).

    - #### sortKeysReverse

          public void sortKeysReverse()

    - #### sortValues

          public void sortValues()

      Sort by values in descending order (largest value will be at [0]).

    - #### sortValuesReverse

          public void sortValuesReverse()

    - #### copy

          public StringDict copy()

      Returns a duplicate copy of this object.

    - #### write

          public void write(PrintWriter writer)

      Write tab-delimited entries out to
      Parameters:
        `writer` -

    - #### print

          public void print()

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`