|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
ObjectUtilMDE
public final class UtilMDE
Utility functions that do not belong elsewhere in the utilMDE package.
| Nested Class Summary | |
|---|---|
static class |
UtilMDE.EnumerationIterator<T>
Converts an Enumeration into an Iterator. |
static class |
UtilMDE.FilteredIterator<T>
|
static class |
UtilMDE.IteratorEnumeration<T>
Converts an Iterator into an Enumeration. |
static class |
UtilMDE.MergedIterator<T>
An Iterator that returns the elements in each of its argument Iterators, in turn. |
static class |
UtilMDE.MergedIterator2<T>
An Iterator that returns first the elements returned by its first argument, then the elements returned by its second argument. |
static class |
UtilMDE.NullableStringComparator
|
static class |
UtilMDE.RemoveFirstAndLastIterator<T>
Returns an iterator just like its argument, except that the first and last elements are removed. |
static class |
UtilMDE.WildcardFilter
|
| Method Summary | ||
|---|---|---|
static void |
addToClasspath(String dir)
Add the directory to the system classpath. |
|
static String |
appendProperty(Properties p,
String key,
String value)
Set the property to its previous value concatenated to the given value. |
|
static String |
arglistFromJvm(String arglist)
Convert an argument list from JVML format to Java format. |
|
static String |
arglistToJvm(String arglist)
Convert a fully-qualified argument list from Java format to JVML format. |
|
static String |
backTrace()
Deprecated. use "backtrace(new Throwable())" instead, to avoid spurious "at utilMDE.UtilMDE.backTrace(UtilMDE.java:1491)" in output. |
|
static String |
backTrace(Throwable t)
For the current backtrace, do "backtrace(new Throwable())". |
|
static BufferedReader |
bufferedFileReader(File file)
Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. |
|
static BufferedReader |
bufferedFileReader(File file,
String charsetName)
Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. |
|
static BufferedReader |
bufferedFileReader(String filename)
Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. |
|
static BufferedReader |
bufferedFileReader(String filename,
String charsetName)
Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. |
|
static BufferedWriter |
bufferedFileWriter(String filename)
Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed. |
|
static BufferedWriter |
bufferedFileWriter(String filename,
boolean append)
Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed. |
|
static boolean |
canCreateAndWrite(File file)
Returns true if the file exists and is writable, or if the file can be created. |
|
static Class<?> |
classForName(String className)
Like @link{Class.forName(String)}, but works when the string represents a primitive type, too. |
|
static String |
classnameFromJvm(String classname)
Convert a classname from JVML format to Java format. |
|
static String |
classnameToJvm(String classname)
Convert a fully-qualified classname from Java format to JVML format. |
|
static long |
count_lines(String filename)
Count the number of lines in the specified file |
|
static int |
count(String s,
int ch)
Return the number of times the character appears in the string. |
|
static int |
count(String s,
String sub)
Return the number of times the second string appears in the first. |
|
static ArrayList<ArrayList<Integer>> |
create_combinations(int arity,
int start,
int cnt)
Returns a list of lists of each combination (with repetition, but not permutations) of integers from start to cnt (inclusive) over arity dimensions. |
|
static
|
create_combinations(int dims,
int start,
List<T> objs)
Returns a list of lists of each combination (with repetition, but not permutations) of the specified objects starting at index start over dims dimensions, for dims > 0. |
|
static File |
createTempDir(String prefix,
String suffix)
Creates an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name. |
|
static void |
deleteDir(File dir)
Deletes the directory at dirName and all its files. |
|
static void |
deleteDir(String dirName)
Deletes the directory at dirName and all its files. |
|
static boolean |
equalFiles(String file1,
String file2)
Returns true iff files have the same contents. |
|
static boolean |
equalFiles(String file1,
String file2,
boolean trimLines)
Returns true iff files have the same contents. |
|
static String |
escapeNonASCII(String orig)
Escape unprintable characters in the target, following the usual Java backslash conventions, so that the result is sure to be printable ASCII. |
|
static String |
escapeNonJava(Character ch)
|
|
static String |
escapeNonJava(String orig)
Escape \, ", newline, and carriage-return characters in the target as \\, \\", \n, and \r; return a new string if any modifications were necessary. |
|
static InputStream |
fileInputStream(File file)
Returns an InputStream for the file, accounting for the possibility that the file is compressed. |
|
static InputStreamReader |
fileReader(File file)
Returns a Reader for the file, accounting for the possibility that the file is compressed. |
|
static InputStreamReader |
fileReader(File file,
String charsetName)
Returns a Reader for the file, accounting for the possibility that the file is compressed. |
|
static InputStreamReader |
fileReader(String filename)
Returns a Reader for the file, accounting for the possibility that the file is compressed. |
|
static File |
fix_filename(File name)
Fixes a file name to do tilde expansion (to the user's home directory). |
|
static String |
fix_filename(String name)
Fixes a file name to do tilde expansion (to the users home directory). |
|
static Object |
getFromSet(Set<?> set,
Object key)
Returns the object in this set that is equal to key. |
|
static int |
hash(double x)
|
|
static int |
hash(double[] a)
|
|
static int |
hash(double[] a,
double[] b)
|
|
static int |
hash(double a,
double b)
|
|
static int |
hash(double a,
double b,
double c)
|
|
static int |
hash(long l)
|
|
static int |
hash(long[] a)
|
|
static int |
hash(long[] a,
long[] b)
|
|
static int |
hash(long a,
long b)
|
|
static int |
hash(long a,
long b,
long c)
|
|
static int |
hash(String a)
|
|
static int |
hash(String[] a)
|
|
static int |
hash(String a,
String b)
|
|
static int |
hash(String a,
String b,
String c)
|
|
static String |
human_readable(long val)
|
|
static
|
incrementMap(Map<T,Integer> m,
T key,
int count)
Increment the Integer which is indexed by key in the Map. |
|
static String |
inferLineSeparator(File filename)
Tries to infer the line separator used in a file. |
|
static String |
inferLineSeparator(String filename)
Tries to infer the line separator used in a file. |
|
static int |
intersectionCardinality(BitSet a,
BitSet b)
Returns the cardinality of the intersection of the two BitSets. |
|
static int |
intersectionCardinality(BitSet a,
BitSet b,
BitSet c)
Returns the cardinality of the intersection of the three BitSets. |
|
static boolean |
intersectionCardinalityAtLeast(BitSet a,
BitSet b,
BitSet c,
int i)
Returns true if the cardinality of the intersection of the two BitSets is at least the given value. |
|
static boolean |
intersectionCardinalityAtLeast(BitSet a,
BitSet b,
int i)
Returns true if the cardinality of the intersection of the two BitSets is at least the given value. |
|
static String |
java_source(File name)
Returns a string version of the name that can be used in java source. |
|
static String |
join(List<?> v,
String delim)
Concatenate the string representations of the objects, placing the delimiter between them. |
|
static String |
join(Object[] a,
String delim)
Concatenate the string representations of the objects, placing the delimiter between them. |
|
static String |
joinLines(List<String> v,
String delim)
Concatenate the string representations of the objects, placing the system-specific line separator between them. |
|
static String |
joinLines(Object... a)
Concatenate the string representations of the objects, placing the system-specific line separator between them. |
|
static LineNumberReader |
lineNumberFileReader(File file)
Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed. |
|
static LineNumberReader |
lineNumberFileReader(String filename)
Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed. |
|
static Class<?> |
loadClassFromFile(String className,
String pathname)
|
|
static
|
makeVector(Enumeration<T> e)
Returns a vector containing the elements of the enumeration. |
|
static
|
mapToString(Appendable sb,
Map<K,V> m,
String linePrefix)
Write a multi-line representation of the map into the given Appendable (e.g., a StringBuilder). |
|
static
|
mapToString(Map<K,V> m)
|
|
static Method |
methodForName(String method)
|
|
static Method |
methodForName(String classname,
String methodname,
Class<?>[] params)
|
|
static String |
nplural(int n,
String noun)
|
|
static String |
patternQuote(String s)
Returns a literal pattern String for the specified
String. |
|
static String |
primitive_name_to_jvm(String primitive_name)
Convert a primitive java type name (e.g., "int", "double", etc.) to the single character JVM name (e.g., "I", "D", etc.). |
|
static boolean |
propertyIsTrue(Properties p,
String key)
Determines whether a property has value "true", "yes", or "1". |
|
static
|
randomElements(Iterator<T> itor,
int num_elts)
Return an List containing num_elts randomly chosen elements from the iterator, or all the elements of the iterator if there are fewer. |
|
static
|
randomElements(Iterator<T> itor,
int num_elts,
Random random)
Return an List containing num_elts randomly chosen elements from the iterator, or all the elements of the iterator if there are fewer. |
|
static String |
readerContents(Reader r)
Reads the entire contents of the reader and returns it as a string. |
|
static String |
readFile(File file)
Reads the entire contents of the file and returns it as a string. |
|
static Object |
readObject(File file)
Reads an Object from a File. |
|
static
|
removeDuplicates(List<T> l)
Returns a copy of the list with duplicates removed. |
|
static String |
removeWhitespaceAfter(String arg,
String delimiter)
Remove all whitespace after instances of delimiter. |
|
static String |
removeWhitespaceAround(String arg,
String delimiter)
Remove all whitespace before or after instances of delimiter. |
|
static String |
removeWhitespaceBefore(String arg,
String delimiter)
Remove all whitespace before instances of delimiter. |
|
static String |
replaceString(String target,
String oldStr,
String newStr)
Return a new string which is the text of target with all instances of oldStr replaced by newStr. |
|
static String |
rpad(double num,
int length)
|
|
static String |
rpad(int num,
int length)
|
|
static String |
rpad(String s,
int length)
|
|
static String |
setDefault(Properties p,
String key,
String value)
Deprecated. use setDefaultMaybe |
|
static String |
setDefaultMaybe(Properties p,
String key,
String value)
Set the property only if it was not previously set. |
|
static void |
setFinalField(Object o,
String fieldName,
Object value)
Sets the given field, which may be final. |
|
static
|
sortList(List<T> l,
Comparator<? super T> c)
Returns the sorted version of the list. |
|
static String[] |
split(String s,
char delim)
Return an array of Strings representing the characters between successive instances of the delimiter character. |
|
static String[] |
split(String s,
String delim)
Return an array of Strings representing the characters between successive instances of the delimiter String. |
|
static String[] |
splitLines(String s)
Return an array of Strings, one for each line in the argument. |
|
static void |
streamCopy(InputStream from,
OutputStream to)
Copy the contents of the input stream to the output stream. |
|
static String |
streamString(InputStream is)
Return a String containing all the characters from the input stream. |
|
static Vector<Object> |
tokens(String str)
Return a Vector of the Strings returned by StringTokenizer.StringTokenizer(String) with the given arguments. |
|
static Vector<Object> |
tokens(String str,
String delim)
Return a Vector of the Strings returned by StringTokenizer.StringTokenizer(String,String) with the given arguments. |
|
static Vector<Object> |
tokens(String str,
String delim,
boolean returnTokens)
Return a Vector of the Strings returned by StringTokenizer.StringTokenizer(String,String,boolean) with the given arguments. |
|
static String |
unescapeNonJava(String orig)
Replace "\\", "\"", "\n", and "\r" sequences by their one-character equivalents. |
|
static String |
unqualified_name(Class<?> cls)
Returns the simple unqualified class name that corresponds to the specified class. |
|
static String |
unqualified_name(String qualified_name)
Returns the simple unqualified class name that corresponds to the specified fully qualified name. |
|
static void |
writeFile(File file,
String contents)
Creates a file with the given name and writes the specified string to it. |
|
static void |
writeObject(Object o,
File file)
Writes an Object to a File. |
|
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean intersectionCardinalityAtLeast(BitSet a,
BitSet b,
int i)
public static boolean intersectionCardinalityAtLeast(BitSet a,
BitSet b,
BitSet c,
int i)
public static int intersectionCardinality(BitSet a,
BitSet b)
public static int intersectionCardinality(BitSet a,
BitSet b,
BitSet c)
public static InputStream fileInputStream(File file)
throws IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
IOException
public static InputStreamReader fileReader(String filename)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static InputStreamReader fileReader(File file)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static InputStreamReader fileReader(File file,
String charsetName)
throws FileNotFoundException,
IOException
charsetName - may be null, or the name of a Charset
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static BufferedReader bufferedFileReader(String filename)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static BufferedReader bufferedFileReader(File file)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static BufferedReader bufferedFileReader(String filename,
String charsetName)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static BufferedReader bufferedFileReader(File file,
String charsetName)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static LineNumberReader lineNumberFileReader(String filename)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static LineNumberReader lineNumberFileReader(File file)
throws FileNotFoundException,
IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
FileNotFoundException
IOException
public static BufferedWriter bufferedFileWriter(String filename)
throws IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
IOException
public static BufferedWriter bufferedFileWriter(String filename,
boolean append)
throws IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
IOException
public static Class<?> classForName(String className)
throws ClassNotFoundException
ClassNotFoundExceptionpublic static String classnameToJvm(String classname)
public static String primitive_name_to_jvm(String primitive_name)
public static String arglistToJvm(String arglist)
public static String classnameFromJvm(String classname)
public static String arglistFromJvm(String arglist)
public static Class<?> loadClassFromFile(String className,
String pathname)
throws FileNotFoundException,
IOException
pathname - the pathname of a .class file
FileNotFoundException
IOExceptionpublic static void addToClasspath(String dir)
public static long count_lines(String filename)
throws IOException
IOException
public static String inferLineSeparator(String filename)
throws IOException
IOException
public static String inferLineSeparator(File filename)
throws IOException
IOException
public static boolean equalFiles(String file1,
String file2)
public static boolean equalFiles(String file1,
String file2,
boolean trimLines)
trimLines - if true, call String.trim on each line before comparingpublic static boolean canCreateAndWrite(File file)
public static File createTempDir(String prefix,
String suffix)
throws IOException
prefix - The prefix string to be used in generating the file's
name; must be at least three characters longsuffix - The suffix string to be used in generating the file's
name; may be null, in which case the suffix ".tmp" will be used Returns:
An abstract pathname denoting a newly-created empty file
IllegalArgumentException - If the prefix argument contains fewer
than three characters
IOException - If a file could not be created
SecurityException - If a security manager exists and its
SecurityManager.checkWrite(java.lang.String) method does not allow a
file to be createdFile.createTempFile(String, String, File)public static void deleteDir(String dirName)
public static void deleteDir(File dir)
public static File fix_filename(File name)
public static String fix_filename(String name)
public static String java_source(File name)
public static void writeObject(Object o,
File file)
throws IOException
IOException
public static Object readObject(File file)
throws IOException,
ClassNotFoundException
IOException
ClassNotFoundExceptionpublic static String readerContents(Reader r)
public static String readFile(File file)
public static void writeFile(File file,
String contents)
public static <T> Integer incrementMap(Map<T,Integer> m,
T key,
int count)
public static <K,V> String mapToString(Map<K,V> m)
public static <K,V> void mapToString(Appendable sb,
Map<K,V> m,
String linePrefix)
public static final int hash(double x)
public static final int hash(double a,
double b)
public static final int hash(double a,
double b,
double c)
public static final int hash(double[] a)
public static final int hash(double[] a,
double[] b)
public static final int hash(long l)
public static final int hash(long a,
long b)
public static final int hash(long a,
long b,
long c)
public static final int hash(long[] a)
public static final int hash(long[] a,
long[] b)
public static final int hash(String a)
public static final int hash(String a,
String b)
public static final int hash(String a,
String b,
String c)
public static final int hash(String[] a)
public static <T> List<T> randomElements(Iterator<T> itor,
int num_elts)
public static <T> List<T> randomElements(Iterator<T> itor,
int num_elts,
Random random)
public static Method methodForName(String method)
throws ClassNotFoundException,
NoSuchMethodException,
SecurityException
ClassNotFoundException
NoSuchMethodException
SecurityException
public static Method methodForName(String classname,
String methodname,
Class<?>[] params)
throws ClassNotFoundException,
NoSuchMethodException,
SecurityException
ClassNotFoundException
NoSuchMethodException
SecurityException
public static boolean propertyIsTrue(Properties p,
String key)
Properties.getProperty(java.lang.String)
public static String appendProperty(Properties p,
String key,
String value)
Properties.getProperty(java.lang.String),
Properties.setProperty(java.lang.String, java.lang.String)
@Deprecated
public static String setDefault(Properties p,
String key,
String value)
Properties.getProperty(java.lang.String),
Properties.setProperty(java.lang.String, java.lang.String)
public static String setDefaultMaybe(Properties p,
String key,
String value)
Properties.getProperty(java.lang.String),
Properties.setProperty(java.lang.String, java.lang.String)public static String patternQuote(String s)
String for the specified
String.
This method produces a String that can be used to
create a Pattern that would match the string
s as if it were a literal pattern.
s - The string to be literalized
public static void setFinalField(Object o,
String fieldName,
Object value)
throws NoSuchFieldException,
IllegalAccessException
NoSuchFieldException
IllegalAccessException
public static Object getFromSet(Set<?> set,
Object key)
public static void streamCopy(InputStream from,
OutputStream to)
public static String streamString(InputStream is)
public static String replaceString(String target,
String oldStr,
String newStr)
public static String[] split(String s,
char delim)
split(String s, String delim)
public static String[] split(String s,
String delim)
split(String s, char delim)public static String[] splitLines(String s)
split(String s, char delim)
public static String join(Object[] a,
String delim)
ArraysMDE.toString(int[])public static String joinLines(Object... a)
ArraysMDE.toString(int[])
public static String join(List<?> v,
String delim)
AbstractCollection.toString()
public static String joinLines(List<String> v,
String delim)
AbstractCollection.toString()public static String escapeNonJava(String orig)
public static String escapeNonJava(Character ch)
public static String escapeNonASCII(String orig)
public static String unescapeNonJava(String orig)
public static String removeWhitespaceAround(String arg,
String delimiter)
public static String removeWhitespaceAfter(String arg,
String delimiter)
public static String removeWhitespaceBefore(String arg,
String delimiter)
public static String nplural(int n,
String noun)
public static String rpad(String s,
int length)
public static String rpad(int num,
int length)
public static String rpad(double num,
int length)
public static int count(String s,
int ch)
public static int count(String s,
String sub)
public static Vector<Object> tokens(String str,
String delim,
boolean returnTokens)
StringTokenizer.StringTokenizer(String,String,boolean) with the given arguments.
The static type is Vector
public static Vector<Object> tokens(String str,
String delim)
StringTokenizer.StringTokenizer(String,String) with the given arguments.
public static Vector<Object> tokens(String str)
StringTokenizer.StringTokenizer(String) with the given arguments.
public static String backTrace(Throwable t)
@Deprecated public static String backTrace()
backTrace(Throwable)
public static <T> List<T> sortList(List<T> l,
Comparator<? super T> c)
public static <T> List<T> removeDuplicates(List<T> l)
public static <T> Vector<T> makeVector(Enumeration<T> e)
public static <T> List<List<T>> create_combinations(int dims,
int start,
List<T> objs)
public static ArrayList<ArrayList<Integer>> create_combinations(int arity,
int start,
int cnt)
public static String unqualified_name(String qualified_name)
public static String unqualified_name(Class<?> cls)
public static String human_readable(long val)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||