Package edu.wisc.game.util

## Class Util

- java.lang.Object
- - edu.wisc.game.util.Util

-     public class Util
      extends Object

  Auxiliary methods for manipulating hash tables etc

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Util()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static boolean` | `anySet​(boolean[] w)` |
    `static HashMap<String,​String>` | `array2map​(String[] a)` | Converts an array into a hash map.
    `static HashSet<String>` | `array2set​(String... a)` | Can also take String[] a
    `static <T> Vector<T>` | `array2vector​(T... a)` |
    `static String` | `cap1​(String s)` | Capitalizes the first character of a string
    `static boolean` | `foundAny​(String text, String[] keywords)` |
    `static boolean` | `foundAnyWordStart​(String text, String[] keywords)` |
    `static <T> String` | `join​(String sep, Vector<T> v)` |
    `static <T> String` | `join​(String sep, T[] x)` |
    `static <T> String` | `joinNonBlank​(String sep, Collection<T> v)` | Only uses non-null non-blank strings
    `static <T> String` | `joinNonBlank​(String sep, T[] z)` |
    `static String` | `plural​(String x, int n)` | "cow" -> "cows"
    `static String` | `readTextFile​(File f)` | Reads an entire text file into a string
    `static <T> T[]` | `reverseArray​(T[] x)` | Creates a new array containing the same elements as x, but in reversed order.
    `static String` | `roman​(int n)` | Converting to a roman numeral
    `static boolean` | `same​(Object a, Object b)` | Returns true if both objects are non-nulls and equals() return true, or if both are nulls.
    `static boolean` | `startsWithAny​(String text, String[] keywords)` |
    `static BitSet` | `toBitSet​(Collection<Integer> v)` | Converts a vector of integers to a BitSet
    `static void` | `writeTextFile​(File f, String data)` | Writes a string into a new text file

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Util

          public Util()

  - ### Method Detail

    - #### array2map

          public static HashMap<String,​String> array2map​(String[] a)

      Converts an array into a hash map. This is used because Java, unlike Perl, does not have an easy-to-use literal to initialize a hash map.
      Parameters:
        `a` - An array with the content (key1, val1, key2, val2, ...)

    - #### array2set

          public static HashSet<String> array2set​(String... a)

      Can also take String[] a

    - #### array2vector

          public static <T> Vector<T> array2vector​(T... a)

    - #### joinNonBlank

          public static <T> String joinNonBlank​(String sep,
                                                Collection<T> v)

      Only uses non-null non-blank strings

    - #### joinNonBlank

          public static <T> String joinNonBlank​(String sep,
                                                T[] z)

    - #### join

          public static <T> String join​(String sep,
                                        Vector<T> v)

    - #### join

          public static <T> String join​(String sep,
                                        T[] x)

    - #### foundAny

          public static boolean foundAny​(String text,
                                         String[] keywords)

    - #### foundAnyWordStart

          public static boolean foundAnyWordStart​(String text,
                                                  String[] keywords)

    - #### startsWithAny

          public static boolean startsWithAny​(String text,
                                              String[] keywords)

    - #### reverseArray

          public static <T> T[] reverseArray​(T[] x)

      Creates a new array containing the same elements as x, but in reversed order. We can't use `new T[x.length]` ("generic array creation"), but we can piggyback on Arrays.copyOf()!

    - #### plural

          public static String plural​(String x,
                                      int n)

      "cow" -> "cows"

    - #### roman

          public static String roman​(int n)

      Converting to a roman numeral
      Returns:
        a lowercase Roman numeral, e.g. "mcmxli" for 1941

    - #### same

          public static boolean same​(Object a,
                                     Object b)

      Returns true if both objects are non-nulls and equals() return true, or if both are nulls.

    - #### readTextFile

          public static String readTextFile​(File f)
                                     throws IOException

      Reads an entire text file into a string
      Throws:
        `IOException`

    - #### writeTextFile

          public static void writeTextFile​(File f,
                                           String data)
                                    throws IOException

      Writes a string into a new text file
      Throws:
        `IOException`

    - #### cap1

          public static String cap1​(String s)

      Capitalizes the first character of a string

    - #### anySet

          public static boolean anySet​(boolean[] w)

    - #### toBitSet

          public static BitSet toBitSet​(Collection<Integer> v)

      Converts a vector of integers to a BitSet
      Returns:
        A BitSet with bit i set for every i in v.