JavaScript is disabled on your browser.
Skip navigation links
processing.data

Class IntDict



  • public class IntDict
    extends java.lang.Object
    A simple class to use a String as a lookup for an int value.
    See Also:
    FloatDict, StringDict
    • Nested Class Summary

      Nested Classes
      Modifier and Type Class and Description
      class IntDict.Entry
    • Constructor Summary

      Constructors
      Constructor and Description
      IntDict ()
      IntDict (java.io.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 (java.lang.Object[][] pairs)
      Constructor to allow (more intuitive) inline initialization, e.g.:
      IntDict (java.lang.String[] keys, int[] values)
    • Method Summary

      All Methods
      Modifier and Type Method and Description
      void add (java.lang.String key, int amount)
      void clear ()
      Remove all entries.
      IntDict copy ()
      Returns a duplicate copy of this object.
      void div (java.lang.String key, int amount)
      java.lang.Iterable<IntDict.Entry> entries ()
      java.util.Iterator<IntDict.Entry> entryIterator ()
      int get (java.lang.String key)
      Return a value for the specified key.
      int get (java.lang.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 (java.lang.String key)
      void increment (IntDict dict)
      Merge another dictionary into this one.
      void increment (java.lang.String key)
      Increase the value associated with a specific key by 1.
      int index (java.lang.String what)
      java.lang.String key (int index)
      java.lang.String[] keyArray ()
      Return a copy of the internal keys array.
      java.lang.String[] keyArray (java.lang.String[] outgoing)
      java.util.Iterator<java.lang.String> keyIterator ()
      java.lang.Iterable<java.lang.String> keys ()
      int maxIndex ()
      java.lang.String maxKey ()
      return the key corresponding to the maximum value or null if no entries
      int maxValue ()
      int minIndex ()
      java.lang.String minKey ()
      int minValue ()
      void mult (java.lang.String key, int amount)
      void print ()
      int remove (java.lang.String key)
      int removeIndex (int index)
      void resize (int length)
      Resize the internal data, this can only be used to shrink the list.
      void save (java.io.File file)
      Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
      void set (java.lang.String key, int amount)
      Create a new key/value pair or change the value of one.
      void setIndex (int index, java.lang.String key, int value)
      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 sortValues (boolean stable)
      Set true to ensure that the order returned is identical.
      void sortValuesReverse ()
      Sort by values in descending order.
      void sortValuesReverse (boolean stable)
      void sub (java.lang.String key, int amount)
      int sum ()
      long sumLong ()
      void swap (int a, int b)
      java.lang.String toJSON ()
      Return this dictionary as a String in JSON format.
      java.lang.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).
      java.util.Iterator<java.lang.Integer> valueIterator ()
      java.lang.Iterable<java.lang.Integer> values ()
      void write (java.io.PrintWriter writer)
      Write tab-delimited entries to a PrintWriter
      • 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(java.io.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(java.lang.String[] keys,
         int[] values)
      • IntDict

        public IntDict(java.lang.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
        In brief:
        Returns the number of key/value pairs
      • resize

        public void resize(int length)
        Resize the internal data, this can only be used to shrink the list. Helpful for situations like sorting and then grabbing the top 50 entries.
      • clear

        public void clear()
        Remove all entries.
        In brief:
        Remove all entries
      • entryIterator

        public java.util.Iterator<IntDict.Entry> entryIterator()
      • key

        public java.lang.String key(int index)
      • keys

        public java.lang.Iterable<java.lang.String> keys()
      • keyIterator

        public java.util.Iterator<java.lang.String> keyIterator()
      • keyArray

        public java.lang.String[] keyArray()
        Return a copy of the internal keys array. This array can be modified.
        In brief:
        Return a copy of the internal keys array
      • keyArray

        public java.lang.String[] keyArray(java.lang.String[] outgoing)
      • value

        public int value(int index)
      • values

        public java.lang.Iterable<java.lang.Integer> values()
        In brief:
        Return the internal array being used to store the values
      • valueIterator

        public java.util.Iterator<java.lang.Integer> valueIterator()
      • valueArray

        public int[] valueArray()
        Create a new array and copy each of the values into it.
        In brief:
        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(java.lang.String key)
        Return a value for the specified key.
        In brief:
        Return a value for the specified key
      • get

        public int get(java.lang.String key,
         int alternate)
      • set

        public void set(java.lang.String key,
         int amount)
        Create a new key/value pair or change the value of one.
        In brief:
        Create a new key/value pair or change the value of one
      • setIndex

        public void setIndex(int index,
         java.lang.String key,
         int value)
      • hasKey

        public boolean hasKey(java.lang.String key)
        In brief:
        Check if a key is a part of the data structure
      • increment

        public void increment(java.lang.String key)
        Increase the value associated with a specific key by 1.
        In brief:
        Increase the value of a specific key value by 1
      • increment

        public void increment(IntDict dict)
        Merge another dictionary into this one. Calling this increment() since it doesn't make sense in practice for the other dictionary types, even though it's technically an add().
      • add

        public void add(java.lang.String key,
         int amount)
        In brief:
        Add to a value
      • sub

        public void sub(java.lang.String key,
         int amount)
        In brief:
        Subtract from a value
      • mult

        public void mult(java.lang.String key,
         int amount)
        In brief:
        Multiply a value
      • div

        public void div(java.lang.String key,
         int amount)
        In brief:
        Divide a value
      • minIndex

        public int minIndex()
      • minKey

        public java.lang.String minKey()
      • minValue

        public int minValue()
      • maxIndex

        public int maxIndex()
      • maxKey

        public java.lang.String maxKey()
        return the key corresponding to the maximum value or null if no entries
      • maxValue

        public int maxValue()
      • sum

        public int sum()
      • sumLong

        public long sumLong()
      • index

        public int index(java.lang.String what)
      • remove

        public int remove(java.lang.String key)
        In brief:
        Remove a key/value pair
      • removeIndex

        public int 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).
        In brief:
        Sort the keys alphabetically
      • 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).
        In brief:
        Sort the keys alphabetically in reverse
      • sortValues

        public void sortValues()
        Sort by values in ascending order. The smallest value will be at [0].
        In brief:
        Sort by values in ascending order
      • sortValues

        public void sortValues(boolean stable)
        Set true to ensure that the order returned is identical. Slightly slower because the tie-breaker for identical values compares the keys.
        Parameters:
        stable -
      • sortValuesReverse

        public void sortValuesReverse()
        Sort by values in descending order. The largest value will be at [0].
        In brief:
        Sort by values in descending order
      • sortValuesReverse

        public void sortValuesReverse(boolean stable)
      • 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:
        an IntDict with the original keys, mapped to their pct of the total
      • copy

        public IntDict copy()
        Returns a duplicate copy of this object.
      • print

        public void print()
      • save

        public void save(java.io.File file)
        Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
      • write

        public void write(java.io.PrintWriter writer)
        Write tab-delimited entries to a PrintWriter
      • toJSON

        public java.lang.String toJSON()
        Return this dictionary as a String in JSON format.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
Skip navigation links

AltStyle によって変換されたページ (->オリジナル) /