processing.data

## Class IntDict

- java.lang.Object
- - processing.data.IntDict

-     public class IntDict
      extends Object

  A simple class to use a String as a lookup for an int value.
  See Also:
    `FloatDict`, `StringDict`

- - ### Constructor Summary

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

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(String key, int amount)`
    `void` | `clear()` Remove all entries.
    `IntDict` | `copy()` Returns a duplicate copy of this object.
    `void` | `div(String key, int amount)`
    `int` | `get(String key)` Return a value for the specified key.
    `int` | `get(String key, int alternate)`
    `FloatDict` | `getPercent()` Sum all of the values in this dictionary, then return a new FloatDict of each key, divided by the total sum.
    `boolean` | `hasKey(String key)`
    `void` | `increment(String key)` Increase the value associated with a specific key by 1.
    `int` | `index(String what)`
    `String` | `key(int index)`
    `String[]` | `keyArray()` Return a copy of the internal keys array.
    `String[]` | `keyArray(String[] outgoing)`
    `Iterator<String>` | `keyIterator()`
    `Iterable<String>` | `keys()` Return the internal array being used to store the keys.
    `int` | `maxIndex()`
    `String` | `maxKey()`
    `int` | `maxValue()`
    `int` | `minIndex()`
    `String` | `minKey()`
    `int` | `minValue()`
    `void` | `mult(String key, int amount)`
    `void` | `print()`
    `int` | `remove(String key)`
    `String` | `removeIndex(int index)`
    `void` | `set(String key, int amount)` Create a new key/value pair or change the value of one.
    `int` | `size()` Returns the number of key/value pairs
    `void` | `sortKeys()` Sort the keys alphabetically (ignoring case).
    `void` | `sortKeysReverse()` Sort the keys alphabetically in reverse (ignoring case).
    `void` | `sortValues()` Sort by values in ascending order.
    `void` | `sortValuesReverse()` Sort by values in descending order.
    `void` | `sub(String key, int amount)`
    `void` | `swap(int a, int b)`
    `String` | `toString()`
    `int` | `value(int index)`
    `int[]` | `valueArray()` Create a new array and copy each of the values into it.
    `int[]` | `valueArray(int[] array)` Fill an already-allocated array with the values (more efficient than creating a new array each time).
    `Iterator<Integer>` | `valueIterator()`
    `Iterable<Integer>` | `values()`
    `void` | `write(PrintWriter writer)` Write tab-delimited entries out to

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### IntDict

          public IntDict()

    - #### IntDict

          public IntDict(int length)

      Create a new lookup with a specific size. This is more efficient than not specifying a size. Use it when you know the rough size of the thing you're creating.

    - #### IntDict

          public IntDict(BufferedReader reader)

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

    - #### IntDict

          public IntDict(String[] keys,
                         int[] values)

    - #### IntDict

          public IntDict(Object[][] pairs)

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

           new FloatDict(new Object[][] {
             { "key1", 1 },
             { "key2", 2 }
           });

  - ### Method Detail

    - #### size

          public int size()

      Returns the number of key/value pairs

    - #### clear

          public void clear()

      Remove all entries.

    - #### key

          public String key(int index)

    - #### keys

          public Iterable<String> keys()

      Return the internal array being used to store the keys. Allocated but unused entries will be removed. This array should not be modified.

    - #### keyIterator

          public Iterator<String> keyIterator()

    - #### 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 int value(int index)

    - #### values

          public Iterable<Integer> values()

    - #### valueIterator

          public Iterator<Integer> valueIterator()

    - #### valueArray

          public int[] valueArray()

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

    - #### valueArray

          public int[] valueArray(int[] 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.
      Parameters:
        `array` - values to copy into the array

    - #### get

          public int get(String key)

      Return a value for the specified key.

    - #### get

          public int get(String key,
                         int alternate)

    - #### set

          public void set(String key,
                          int amount)

      Create a new key/value pair or change the value of one.

    - #### hasKey

          public boolean hasKey(String key)

    - #### increment

          public void increment(String key)

      Increase the value associated with a specific key by 1.

    - #### add

          public void add(String key,
                          int amount)

    - #### sub

          public void sub(String key,
                          int amount)

    - #### mult

          public void mult(String key,
                           int amount)

    - #### div

          public void div(String key,
                          int amount)

    - #### minIndex

          public int minIndex()

    - #### minValue

          public int minValue()

    - #### minKey

          public String minKey()

    - #### maxIndex

          public int maxIndex()

    - #### maxValue

          public int maxValue()

    - #### maxKey

          public String maxKey()

    - #### index

          public int index(String what)

    - #### 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()

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

    - #### sortValues

          public void sortValues()

      Sort by values in ascending order. The smallest value will be at [0].

    - #### sortValuesReverse

          public void sortValuesReverse()

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

    - #### getPercent

          public FloatDict getPercent()

      Sum all of the values in this dictionary, then return a new FloatDict of each key, divided by the total sum. The total for all values will be ~1.0.
      Returns:
        a Dict with the original keys, mapped to their pct of the total

    - #### copy

          public IntDict 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`