Package edu.wisc.game.util
Class Util
java.lang.Object
edu.wisc.game.util.Util
Auxiliary methods for manipulating hash tables etc
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
anySet
(boolean[] w) Is any value set?Converts an array into a hash map.array2set
(int... a) Can also take String[] astatic <T> Vector<T>
array2vector
(T... a) static String
Capitalizes the first character of a stringstatic Util.CopyInfo
copyFileUniqueLines
(File f, File g) Copies the content of file f to file g, skipping any duplicate lines (even if the two identical lines are not next to each other).eachToString
(Collection<T> v) static boolean
static boolean
foundAnyWordStart
(String text, String[] keywords) static <T> String
static <T> String
static <T> String
joinNonBlank
(String sep, double[] z) static <T> String
joinNonBlank
(String sep, int[] z) static <T> String
joinNonBlank
(String sep, NumberFormat fmt, double[] z) static <T> String
joinNonBlank
(String sep, Collection<T> v) Only uses non-null non-blank stringsstatic <T> String
joinNonBlank
(String sep, T[] z) static String
"cow" -> "cows"static String
readTextFile
(File f) Reads an entire text file into a stringstatic <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 numeralstatic boolean
Returns true if both objects are non-nulls and equals() return true, or if both are nulls.static String
static boolean
startsWithAny
(String text, String[] keywords) static BitSet
Converts a vector of integers to a BitSetstatic void
writeTextFile
(File f, String data) Writes a string into a new text file
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
array2map
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
Can also take String[] a -
array2set
-
array2vector
-
loseType
-
loseType
-
joinNonBlank
Only uses non-null non-blank strings -
joinNonBlank
-
joinNonBlank
-
joinNonBlank
-
joinNonBlank
-
join
-
join
-
foundAny
-
foundAnyWordStart
-
startsWithAny
-
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
"cow" -> "cows" -
roman
Converting to a roman numeral- Returns:
- a lowercase Roman numeral, e.g. "mcmxli" for 1941
-
same
Returns true if both objects are non-nulls and equals() return true, or if both are nulls. -
readTextFile
Reads an entire text file into a string- Throws:
IOException
-
writeTextFile
Writes a string into a new text file- Throws:
IOException
-
cap1
Capitalizes the first character of a string -
anySet
public static boolean anySet(boolean[] w) Is any value set?- Returns:
- The "OR" of all elements
-
toBitSet
Converts a vector of integers to a BitSet- Returns:
- A BitSet with bit i set for every i in v.
-
eachToString
-
stackToString
-
copyFileUniqueLines
Copies the content of file f to file g, skipping any duplicate lines (even if the two identical lines are not next to each other). This is used to remove duplicates in transcript files.- Returns:
- a statistics structure
- Throws:
IOException
-