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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtil.CopyInfoFile copy statistics
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleananySet(boolean[] w)Is any value set?static HashMap<String,String>array2map(String[] a)Converts an array into a hash map.static HashSet<Integer>array2set(int... a)static HashSet<String>array2set(String... a)Can also take String[] astatic Vector<Integer>array2vector(int... a)static <T> Vector<T>array2vector(T... a)static Stringcap1(String s)Capitalizes the first character of a stringstatic Util.CopyInfocopyFileUniqueLines(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).static <T> HashSet<String>eachToString(Collection<T> v)static booleanfoundAny(String text, String[] keywords)static booleanfoundAnyWordStart(String text, String[] keywords)static <T> Stringjoin(String sep, Vector<T> v)static <T> Stringjoin(String sep, T[] x)static <T> StringjoinNonBlank(String sep, double[] z)static <T> StringjoinNonBlank(String sep, int[] z)static <T> StringjoinNonBlank(String sep, NumberFormat fmt, double[] z)static <T> StringjoinNonBlank(String sep, Collection<T> v)Only uses non-null non-blank stringsstatic <T> StringjoinNonBlank(String sep, T[] z)static <T> Vector<T>joinSubsections(Vector<T[]> w)static int[]listBits(BitSet b)static <T> Set<Object>loseType(Set<T> a)static <T> Vector<Object>loseType(Vector<T> a)static Stringplural(String x, int n)"cow" -> "cows"static StringreadTextFile(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 Stringroman(int n)Converting to a roman numeralstatic booleansame(Object a, Object b)Returns true if both objects are non-nulls and equals() return true, or if both are nulls.static StringstackToString(Exception ex)static booleanstartsWithAny(String text, String[] keywords)static <T> intsumLen(Vector<T[]> w)static BitSettoBitSet(Collection<Integer> v)Converts a vector of integers to a BitSetstatic voidwriteTextFile(File f, String data)Writes a string into a new text file
-
-
-
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, ...)
-
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, NumberFormat fmt, double[] z)
-
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()!
-
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
-
anySet
public static boolean anySet(boolean[] w)
Is any value set?- Returns:
- The "OR" of all elements
-
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.
-
listBits
public static int[] listBits(BitSet b)
- Returns:
- an array containing the indexes of the "on" bits
-
eachToString
public static <T> HashSet<String> eachToString(Collection<T> v)
-
copyFileUniqueLines
public static Util.CopyInfo copyFileUniqueLines(File f, File g) throws IOException
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
-
sumLen
public static <T> int sumLen(Vector<T[]> w)
-
-