@Deprecated
public final class UtilMDE
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
UtilMDE.EnumerationIterator<T>
Deprecated.
Converts an Enumeration into an Iterator.
|
static class |
UtilMDE.FilteredIterator<T>
Deprecated.
An iterator that only returns elements that match the given Filter.
|
static class |
UtilMDE.IteratorEnumeration<T>
Deprecated.
Converts an Iterator into an Enumeration.
|
static class |
UtilMDE.MergedIterator<T>
Deprecated.
An Iterator that returns the elements in each of its argument Iterators, in turn.
|
static class |
UtilMDE.MergedIterator2<T>
Deprecated.
An Iterator that returns first the elements returned by its first argument, then the elements
returned by its second argument.
|
static class |
UtilMDE.NullableStringComparator
Deprecated.
Same as built-in String comparison, but accept null arguments, and place them at the beginning.
|
static class |
UtilMDE.ObjectComparator
Deprecated.
Attempt to order Objects.
|
static class |
UtilMDE.RemoveFirstAndLastIterator<T>
Deprecated.
Returns an iterator just like its argument, except that the first and last elements are
removed.
|
static class |
UtilMDE.WildcardFilter
Deprecated.
A FilenameFilter that accepts files whose name matches the given wildcard.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
abbreviateNumber(long val)
Deprecated.
Convert a number into an abbreviation such as "5.00K" for 5000 or "65.0M" for 65000000.
|
static void |
addToClasspath(java.lang.String dir)
Deprecated.
Add the directory to the system classpath.
|
static java.lang.String |
appendProperty(java.util.Properties p,
java.lang.String key,
java.lang.String value)
Deprecated.
Set the property to its previous value concatenated to the given value.
|
static java.lang.String |
arglistFromJvm(java.lang.String arglist)
Deprecated.
|
static java.lang.String |
arglistToJvm(java.lang.String arglist)
Deprecated.
|
static java.lang.String |
backticks(java.util.List<java.lang.String> command)
Deprecated.
Execute the given command, and return all its output as a string.
|
static java.lang.String |
backticks(java.lang.String... command)
Deprecated.
Execute the given command, and return all its output as a string.
|
static java.lang.String |
backTrace(java.lang.Throwable t)
Deprecated.
Return a String representation of the backtrace of the given Throwable.
|
static java.lang.String |
binaryNameToClassGetName(java.lang.String bn)
Deprecated.
|
static java.lang.String |
binaryNameToFieldDescriptor(java.lang.String classname)
Deprecated.
|
static java.io.BufferedOutputStream |
bufferedFileOutputStream(java.lang.String filename,
boolean append)
Deprecated.
Returns a BufferedOutputStream for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.io.File file)
Deprecated.
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.io.File file,
java.lang.String charsetName)
Deprecated.
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.lang.String filename)
Deprecated.
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.lang.String filename,
java.lang.String charsetName)
Deprecated.
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedWriter |
bufferedFileWriter(java.lang.String filename)
Deprecated.
Returns a BufferedWriter for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedWriter |
bufferedFileWriter(java.lang.String filename,
boolean append)
Deprecated.
Returns a BufferedWriter for the file, accounting for the possibility that the file is
compressed.
|
static boolean |
canCreateAndWrite(java.io.File file)
Deprecated.
Returns true if the file exists and is writable, or if the file can be created.
|
static java.lang.Class<?> |
classForName(java.lang.String className)
Deprecated.
Like
Class.forName(String) , but also works when the string represents a primitive type
or a fully-qualified name (as opposed to a binary name). |
static long |
count_lines(java.lang.String filename)
Deprecated.
Count the number of lines in the specified file.
|
static int |
count(java.lang.String s,
int ch)
Deprecated.
Return the number of times the character appears in the string.
|
static int |
count(java.lang.String s,
java.lang.String sub)
Deprecated.
Return the number of times the second string appears in the first.
|
static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> |
create_combinations(int arity,
int start,
int cnt)
Deprecated.
Returns a list of lists of each combination (with repetition, but not permutations) of integers
from start to cnt (inclusive) over arity dimensions.
|
static <T> java.util.List<java.util.List<T>> |
create_combinations(int dims,
int start,
java.util.List<T> objs)
Deprecated.
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 java.io.File |
createTempDir(java.lang.String prefix,
java.lang.String suffix)
Deprecated.
Creates an empty directory in the default temporary-file directory, using the given prefix and
suffix to generate its name.
|
static boolean |
deepEquals(java.lang.Object o1,
java.lang.Object o2)
Deprecated.
Determines deep equality for the elements.
|
static java.lang.Class<?> |
defineClassFromFile(java.lang.String className,
java.lang.String pathname)
Deprecated.
Converts the bytes in a file into an instance of class Class, and resolves (links) the class.
|
static boolean |
deleteDir(java.io.File dir)
Deprecated.
Deletes the directory at dir and all its files.
|
static boolean |
deleteDir(java.lang.String dirName)
Deprecated.
Deletes the directory at dirName and all its files.
|
static boolean |
equalFiles(java.lang.String file1,
java.lang.String file2)
Deprecated.
Return true iff files have the same contents.
|
static boolean |
equalFiles(java.lang.String file1,
java.lang.String file2,
boolean trimLines)
Deprecated.
Return true iff the files have the same contents.
|
static java.lang.String |
escapeNonASCII(java.lang.String orig)
Deprecated.
Escape unprintable characters in the target, following the usual Java backslash conventions, so
that the result is sure to be printable ASCII.
|
static java.lang.String |
escapeNonJava(java.lang.Character ch)
Deprecated.
Like
escapeNonJava(String) , but for a single character. |
static java.lang.String |
escapeNonJava(java.lang.String orig)
Deprecated.
Escape \, ", newline, and carriage-return characters in the target as \\, \", \n, and \r;
return a new string if any modifications were necessary.
|
static java.io.File |
expandFilename(java.io.File name)
Deprecated.
Does tilde expansion on a file name (to the user's home directory).
|
static java.lang.String |
expandFilename(java.lang.String name)
Deprecated.
Does tilde expansion on a file name (to the user's home directory).
|
static java.lang.String |
fieldDescriptorToBinaryName(java.lang.String classname)
Deprecated.
|
static java.lang.String |
fieldDescriptorToClassGetName(java.lang.String fd)
Deprecated.
|
static java.io.InputStream |
fileInputStream(java.io.File file)
Deprecated.
Returns an InputStream for the file, accounting for the possibility that the file is
compressed.
|
static java.util.List<java.lang.String> |
fileLines(java.lang.String filename)
Deprecated.
Return the contents of the file, as a list of strings, one per line.
|
static java.io.InputStreamReader |
fileReader(java.io.File file)
Deprecated.
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.io.InputStreamReader |
fileReader(java.io.File file,
java.lang.String charsetName)
Deprecated.
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.io.InputStreamReader |
fileReader(java.lang.String filename)
Deprecated.
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.lang.String |
fullyQualifiedNameToSimpleName(java.lang.String qualified_name)
Deprecated.
Returns the simple unqualified class name that corresponds to the specified fully qualified
name.
|
static java.lang.Object |
getFromSet(java.util.Set<?> set,
java.lang.Object key)
Deprecated.
Return the object in this set that is equal to key.
|
static java.lang.Object |
getPrivateField(java.lang.Object o,
java.lang.String fieldName)
Deprecated.
Reads the given field, which may be private.
|
static int |
hash(double x)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(double[] a)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(double[] a,
double[] b)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(double a,
double b)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(double a,
double b,
double c)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(long l)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(long[] a)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(long[] a,
long[] b)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(long a,
long b)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(long a,
long b,
long c)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(java.lang.String a)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(java.lang.String[] a)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(java.lang.String a,
java.lang.String b)
Deprecated.
Return a hash of the arguments.
|
static int |
hash(java.lang.String a,
java.lang.String b,
java.lang.String c)
Deprecated.
Return a hash of the arguments.
|
static <T> java.lang.Integer |
incrementMap(java.util.Map<T,java.lang.Integer> m,
T key,
int count)
Deprecated.
Increment the Integer which is indexed by key in the Map.
|
static java.lang.String |
inferLineSeparator(java.io.File file)
Deprecated.
Tries to infer the line separator used in a file.
|
static java.lang.String |
inferLineSeparator(java.lang.String filename)
Deprecated.
Tries to infer the line separator used in a file.
|
static int |
intersectionCardinality(java.util.BitSet a,
java.util.BitSet b)
Deprecated.
Returns the cardinality of the intersection of the two BitSets.
|
static int |
intersectionCardinality(java.util.BitSet a,
java.util.BitSet b,
java.util.BitSet c)
Deprecated.
Returns the cardinality of the intersection of the three BitSets.
|
static boolean |
intersectionCardinalityAtLeast(java.util.BitSet a,
java.util.BitSet b,
java.util.BitSet c,
int i)
Deprecated.
Returns true if the cardinality of the intersection of the three BitSets is at least the given
value.
|
static boolean |
intersectionCardinalityAtLeast(java.util.BitSet a,
java.util.BitSet b,
int i)
Deprecated.
Returns true if the cardinality of the intersection of the two BitSets is at least the given
value.
|
static boolean |
isSubtype(java.lang.Class<?> sub,
java.lang.Class<?> sup)
Deprecated.
Return true iff sub is a subtype of sup.
|
static <T> java.lang.Iterable<T> |
iteratorToIterable(java.util.Iterator<T> source)
Deprecated.
Converts an Iterator to an Iterable.
|
static java.lang.String |
java_source(java.io.File name)
Deprecated.
Return a string version of the filename that can be used in Java source.
|
static java.lang.String |
join(java.lang.Iterable<? extends java.lang.Object> v,
java.lang.String delim)
Deprecated.
Concatenate the string representations of the objects, placing the delimiter between them.
|
static java.lang.String |
join(java.lang.Object[] a,
java.lang.String delim)
Deprecated.
Concatenate the string representations of the array elements, placing the delimiter between
them.
|
static java.lang.String |
joinLines(java.util.List<java.lang.String> v)
Deprecated.
Concatenate the string representations of the objects, placing the system-specific line
separator between them.
|
static java.lang.String |
joinLines(java.lang.Object... a)
Deprecated.
Concatenate the string representations of the objects, placing the system-specific line
separator between them.
|
static java.io.LineNumberReader |
lineNumberFileReader(java.io.File file)
Deprecated.
Returns a LineNumberReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.LineNumberReader |
lineNumberFileReader(java.lang.String filename)
Deprecated.
Returns a LineNumberReader for the file, accounting for the possibility that the file is
compressed.
|
static java.lang.String |
lpad(java.lang.String s,
int length)
Deprecated.
Returns a string of the specified length, truncated if necessary, and padded with spaces to the
left if necessary.
|
static <T> java.util.ArrayList<T> |
makeArrayList(java.util.Enumeration<T> e)
Deprecated.
Returns a vector containing the elements of the enumeration.
|
static <K,V> void |
mapToString(java.lang.Appendable sb,
java.util.Map<K,V> m,
java.lang.String linePrefix)
Deprecated.
Write a multi-line representation of the map into the given Appendable (e.g., a StringBuilder).
|
static <K,V> java.lang.String |
mapToString(java.util.Map<K,V> m)
Deprecated.
Returns a multi-line string representation of a map.
|
static java.lang.reflect.Method |
methodForName(java.lang.String method)
Deprecated.
Given a method signature, return the method.
|
static java.lang.reflect.Method |
methodForName(java.lang.String classname,
java.lang.String methodname,
java.lang.Class<?>[] params)
Deprecated.
Given a class name and a method name in that class, return the method.
|
static java.lang.String |
nplural(int n,
java.lang.String noun)
Deprecated.
Return either "n noun" or "n nouns" depending on n.
|
static java.lang.String |
primitiveTypeNameToFieldDescriptor(java.lang.String primitive_name)
|
static boolean |
propertyIsTrue(java.util.Properties p,
java.lang.String key)
Deprecated.
Determines whether a property has value "true", "yes", or "1".
|
static <T> java.util.List<T> |
randomElements(java.util.Iterator<T> itor,
int num_elts)
Deprecated.
Return a List containing num_elts randomly chosen elements from the iterator, or all the
elements of the iterator if there are fewer.
|
static <T> java.util.List<T> |
randomElements(java.util.Iterator<T> itor,
int num_elts,
java.util.Random random)
Deprecated.
Return a List containing num_elts randomly chosen elements from the iterator, or all the
elements of the iterator if there are fewer.
|
static java.lang.String |
readerContents(java.io.Reader r)
Deprecated.
Reads the entire contents of the reader and returns it as a string.
|
static java.lang.String |
readFile(java.io.File file)
Deprecated.
Reads the entire contents of the file and returns it as a string.
|
static java.lang.Object |
readObject(java.io.File file)
Deprecated.
Reads an Object from a File.
|
static <T> java.util.List<T> |
removeDuplicates(java.util.List<T> l)
Deprecated.
Return a copy of the list with duplicates removed.
|
static java.lang.String |
removeWhitespaceAfter(java.lang.String arg,
java.lang.String delimiter)
Deprecated.
Remove all whitespace after instances of delimiter.
|
static java.lang.String |
removeWhitespaceAround(java.lang.String arg,
java.lang.String delimiter)
Deprecated.
Remove all whitespace before or after instances of delimiter.
|
static java.lang.String |
removeWhitespaceBefore(java.lang.String arg,
java.lang.String delimiter)
Deprecated.
Remove all whitespace before instances of delimiter.
|
static java.lang.String |
replaceString(java.lang.String target,
java.lang.String oldStr,
java.lang.String newStr)
Deprecated.
Return a new string which is the text of target with all instances of oldStr replaced by
newStr.
|
static java.lang.String |
rpad(double num,
int length)
Deprecated.
Converts the double to a String, then formats it using
rpad(String,int) . |
static java.lang.String |
rpad(int num,
int length)
Deprecated.
Converts the int to a String, then formats it using
rpad(String,int) . |
static java.lang.String |
rpad(java.lang.String s,
int length)
Deprecated.
Returns a string of the specified length, truncated if necessary, and padded with spaces to the
right if necessary.
|
static java.lang.String |
setDefaultMaybe(java.util.Properties p,
java.lang.String key,
java.lang.String value)
Deprecated.
Set the property only if it was not previously set.
|
static void |
setFinalField(java.lang.Object o,
java.lang.String fieldName,
java.lang.Object value)
Deprecated.
Sets the given field, which may be final and/or private.
|
static <K extends java.lang.Comparable<? super K>,V> |
sortedKeySet(java.util.Map<K,V> m)
Deprecated.
Returns a sorted version of m.keySet().
|
static <K,V> java.util.Collection<K> |
sortedKeySet(java.util.Map<K,V> m,
java.util.Comparator<K> comparator)
Deprecated.
Returns a sorted version of m.keySet().
|
static <T> java.util.List<T> |
sortList(java.util.List<T> l,
java.util.Comparator<? super T> c)
Deprecated.
Return the sorted version of the list.
|
static java.lang.String[] |
split(java.lang.String s,
char delim)
Deprecated.
Return an array of Strings representing the characters between successive instances of the
delimiter character.
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String delim)
Deprecated.
Return an array of Strings representing the characters between successive instances of the
delimiter String.
|
static java.lang.String[] |
splitLines(java.lang.String s)
Deprecated.
Return an array of Strings, one for each line in the argument.
|
static void |
streamCopy(java.io.InputStream from,
java.io.OutputStream to)
Deprecated.
Copy the contents of the input stream to the output stream.
|
static java.util.List<java.lang.String> |
streamLines(java.io.InputStream stream)
Deprecated.
Reads all lines from the stream and returns them in a
List<String> . |
static java.lang.String |
streamString(java.io.InputStream is)
Deprecated.
Return a String containing all the characters from the input stream.
|
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str)
Deprecated.
Return a ArrayList of the Strings returned by
StringTokenizer.StringTokenizer(String) with the given arguments. |
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str,
java.lang.String delim)
Deprecated.
Return a ArrayList of the Strings returned by
StringTokenizer.StringTokenizer(String,String) with the given arguments. |
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str,
java.lang.String delim,
boolean returnDelims)
Deprecated.
Return a ArrayList of the Strings returned by
StringTokenizer.StringTokenizer(String,String,boolean) with the given arguments. |
static java.lang.String |
unescapeNonJava(java.lang.String orig)
Deprecated.
Replace "\\", "\"", "\n", and "\r" sequences by their one-character equivalents.
|
static java.lang.String |
unqualified_name(java.lang.Class<?> cls)
Deprecated.
use
Class.getSimpleName() instead. |
static java.lang.String |
unqualified_name(java.lang.String qualified_name)
Deprecated.
use
fullyQualifiedNameToSimpleName(java.lang.String) instead. |
static void |
writeFile(java.io.File file,
java.lang.String contents)
Deprecated.
Creates a file with the given name and writes the specified string to it.
|
static void |
writeObject(java.lang.Object o,
java.io.File file)
Deprecated.
Writes an Object to a File.
|
public static boolean intersectionCardinalityAtLeast(java.util.BitSet a, java.util.BitSet b, int i)
a
- the first BitSet to intersectb
- the second BitSet to intersecti
- the cardinality boundpublic static boolean intersectionCardinalityAtLeast(java.util.BitSet a, java.util.BitSet b, java.util.BitSet c, int i)
a
- the first BitSet to intersectb
- the second BitSet to intersectc
- the third BitSet to intersecti
- the cardinality boundpublic static int intersectionCardinality(java.util.BitSet a, java.util.BitSet b)
a
- the first BitSet to intersectb
- the second BitSet to intersectpublic static int intersectionCardinality(java.util.BitSet a, java.util.BitSet b, java.util.BitSet c)
a
- the first BitSet to intersectb
- the second BitSet to intersectc
- the third BitSet to intersectpublic static java.io.InputStream fileInputStream(java.io.File file) throws java.io.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.
file
- the possibly-compressed file to readjava.io.IOException
- if there is trouble reading the filepublic static java.io.InputStreamReader fileReader(java.lang.String filename) throws java.io.FileNotFoundException, java.io.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.
filename
- the possibly-compressed file to readjava.io.IOException
- if there is trouble reading the filejava.io.FileNotFoundException
- if the file is not foundpublic static java.io.InputStreamReader fileReader(java.io.File file) throws java.io.FileNotFoundException, java.io.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.
file
- the possibly-compressed file to readjava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.InputStreamReader fileReader(java.io.File file, java.lang.String charsetName) throws java.io.FileNotFoundException, java.io.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.
file
- the possibly-compressed file to readcharsetName
- null, or the name of a Charset to use when reading the filejava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.lang.String filename) throws java.io.FileNotFoundException, java.io.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.
filename
- the possibly-compressed file to readjava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.io.File file) throws java.io.FileNotFoundException, java.io.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.
file
- the possibility-compressed file to readjava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.lang.String filename, java.lang.String charsetName) throws java.io.FileNotFoundException, java.io.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.
filename
- the possibly-compressed file to readcharsetName
- the character set to use when reading the filejava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.io.File file, java.lang.String charsetName) throws java.io.FileNotFoundException, java.io.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.
file
- the possibly-compressed file to readcharsetName
- the character set to use when reading the filejava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.LineNumberReader lineNumberFileReader(java.lang.String filename) throws java.io.FileNotFoundException, java.io.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.
filename
- the possibly-compressed file to readjava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.LineNumberReader lineNumberFileReader(java.io.File file) throws java.io.FileNotFoundException, java.io.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.
file
- the possibly-compressed file to readjava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the filepublic static java.io.BufferedWriter bufferedFileWriter(java.lang.String filename) throws java.io.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.
filename
- the possibly-compressed file to writejava.io.IOException
- if there is trouble writing the filepublic static java.io.BufferedWriter bufferedFileWriter(java.lang.String filename, boolean append) throws java.io.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.
filename
- the possibly-compressed file to writeappend
- if true, the resulting BufferedWriter appends to the end of the file instead of
the beginningjava.io.IOException
- if there is trouble writing the filepublic static java.io.BufferedOutputStream bufferedFileOutputStream(java.lang.String filename, boolean append) throws java.io.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.
filename
- the possibly-compressed file to writeappend
- if true, the resulting BufferedOutputStream appends to the end of the file
instead of the beginningjava.io.IOException
- if there is trouble writing the filepublic static boolean isSubtype(java.lang.Class<?> sub, java.lang.Class<?> sup)
sub
- class to test for being a subtypesup
- class to test for being a supertypepublic static java.lang.Class<?> classForName(java.lang.String className) throws java.lang.ClassNotFoundException
Class.forName(String)
, but also works when the string represents a primitive type
or a fully-qualified name (as opposed to a binary name).
If the given name can't be found, this method changes the last '.' to a dollar sign ($) and tries again. This accounts for inner classes that are incorrectly passed in in fully-qualified format instead of binary format. (It should try multiple dollar signs, not just at the last position.)
Recall the rather odd specification for Class.forName(String)
: the argument is a
binary name for non-arrays, but a field descriptor for arrays. This method uses the same rules,
but additionally handles primitive types and, for non-arrays, fully-qualified names.
className
- name of the classjava.lang.ClassNotFoundException
- if the class is not found@Deprecated public static java.lang.String binaryNameToFieldDescriptor(java.lang.String classname)
classname
- name of the class, in binary class name format@Deprecated public static java.lang.String primitiveTypeNameToFieldDescriptor(java.lang.String primitive_name)
primitive_name
- name of the type, in Java formatjava.lang.IllegalArgumentException
- if primitive_name is not a valid primitive type name@Deprecated public static java.lang.String binaryNameToClassGetName(java.lang.String bn)
Class.getName()
.bn
- the binary name to convert@Deprecated public static java.lang.String fieldDescriptorToClassGetName(java.lang.String fd)
Class.getName()
.fd
- the class, in field descriptor format@Deprecated public static java.lang.String arglistToJvm(java.lang.String arglist)
arglist
- an argument list, in Java format@Deprecated public static java.lang.String fieldDescriptorToBinaryName(java.lang.String classname)
classname
- name of the type, in JVML format@Deprecated public static java.lang.String arglistFromJvm(java.lang.String arglist)
arglist
- an argument list, in JVML formatpublic static java.lang.Class<?> defineClassFromFile(java.lang.String className, java.lang.String pathname) throws java.io.FileNotFoundException, java.io.IOException
ClassLoader.defineClass(String,byte[],int,int)
, but takes a file name rather than
an array of bytes as an argument, and also resolves (links) the class.className
- the name of the class to define, or null if not knownpathname
- the pathname of a .class filejava.io.FileNotFoundException
- if the file cannot be foundjava.io.IOException
- if there is trouble reading the fileClassLoader.defineClass(String,byte[],int,int)
public static void addToClasspath(java.lang.String dir)
dir
- directory to add to the system classpathpublic static long count_lines(java.lang.String filename) throws java.io.IOException
filename
- file whose size to countjava.io.IOException
- if there is trouble reading the filepublic static java.util.List<java.lang.String> fileLines(java.lang.String filename) throws java.io.IOException
filename
- the file whose contents to returnfilename
, one string per linejava.io.IOException
- if there was a problem reading the filepublic static java.lang.String inferLineSeparator(java.lang.String filename) throws java.io.IOException
filename
- the file to infer a line separator fromjava.io.IOException
- if there is trouble reading the filepublic static java.lang.String inferLineSeparator(java.io.File file) throws java.io.IOException
file
- the file to infer a line separator fromjava.io.IOException
- if there is trouble reading the filepublic static boolean equalFiles(java.lang.String file1, java.lang.String file2)
file1
- first file to comparefile2
- second file to comparepublic static boolean equalFiles(java.lang.String file1, java.lang.String file2, boolean trimLines)
file1
- first file to comparefile2
- second file to comparetrimLines
- if true, call String.trim on each line before comparingpublic static boolean canCreateAndWrite(java.io.File file)
file
- the file to create and writepublic static java.io.File createTempDir(java.lang.String prefix, java.lang.String suffix) throws java.io.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 filejava.lang.IllegalArgumentException
- If the prefix argument contains fewer than three charactersjava.io.IOException
- If a file could not be createdjava.lang.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 boolean deleteDir(java.lang.String dirName)
dirName
- the directory to deletepublic static boolean deleteDir(java.io.File dir)
dir
- the directory to deletepublic static java.io.File expandFilename(java.io.File name)
name
- file whose name to expandpublic static java.lang.String expandFilename(java.lang.String name)
name
- filename to expandpublic static java.lang.String java_source(java.io.File name)
The current implementation presumes that backslashes don't appear in filenames except as windows path separators. That seems like a reasonable assumption.
name
- file whose name to quotepublic static void writeObject(java.lang.Object o, java.io.File file) throws java.io.IOException
o
- the object to writefile
- the file to which to write the objectjava.io.IOException
- if there is trouble writing the filepublic static java.lang.Object readObject(java.io.File file) throws java.io.IOException, java.lang.ClassNotFoundException
file
- the file from which to readjava.io.IOException
- if there is trouble reading the filejava.lang.ClassNotFoundException
- if the object's class cannot be foundpublic static java.lang.String readerContents(java.io.Reader r)
r
- the Reader to readpublic static java.lang.String readFile(java.io.File file)
You could use new String(Files.readAllBytes(...))
, but it requires a Path rather
than a File, and it can throw IOException which has to be caught.
file
- the file to readpublic static void writeFile(java.io.File file, java.lang.String contents)
file
- the file to write tocontents
- the text to put in the filepublic static int hash(double x)
Double.hashCode()
.x
- value to be hashedpublic static int hash(double a, double b)
a
- value to be hashedb
- value to be hashedpublic static int hash(double a, double b, double c)
a
- value to be hashedb
- value to be hashedc
- value to be hashedpublic static int hash(double[] a)
a
- value to be hashedpublic static int hash(double[] a, double[] b)
a
- value to be hashedb
- value to be hashedpublic static int hash(long l)
Long.hashCode()
. But it doesn't map -1 and 0 to the same value.l
- value to be hashedpublic static int hash(long a, long b)
a
- value to be hashedb
- value to be hashedpublic static int hash(long a, long b, long c)
a
- value to be hashedb
- value to be hashedc
- value to be hashedpublic static int hash(long[] a)
a
- value to be hashedpublic static int hash(long[] a, long[] b)
a
- value to be hashedb
- value to be hashedpublic static int hash(java.lang.String a)
a
- value to be hashedpublic static int hash(java.lang.String a, java.lang.String b)
a
- value to be hashedb
- value to be hashedpublic static int hash(java.lang.String a, java.lang.String b, java.lang.String c)
a
- value to be hashedb
- value to be hashedc
- value to be hashedpublic static int hash(java.lang.String[] a)
a
- value to be hashedpublic static <T> java.lang.Iterable<T> iteratorToIterable(java.util.Iterator<T> source)
T
- the element typesource
- the Iterator to be converted to Iterablepublic static <T> java.util.List<T> randomElements(java.util.Iterator<T> itor, int num_elts)
T
- type of the iterator elementsitor
- elements to be randomly selected fromnum_elts
- number of elements to selectpublic static <T> java.util.List<T> randomElements(java.util.Iterator<T> itor, int num_elts, java.util.Random random)
T
- type of the iterator elementsitor
- elements to be randomly selected fromnum_elts
- number of elements to selectrandom
- the Random instance to use to make selectionspublic static <T> java.lang.Integer incrementMap(java.util.Map<T,java.lang.Integer> m, T key, int count)
T
- type of keys in the mapm
- map to have one of its values incrementedkey
- the key for the element whose value will be incrementedcount
- how much to increment the value byjava.lang.Error
- if the key is in the Map but maps to a non-Integerpublic static <K,V> java.lang.String mapToString(java.util.Map<K,V> m)
K
- type of map keysV
- type of map valuesm
- map to be converted to a stringpublic static <K,V> void mapToString(java.lang.Appendable sb, java.util.Map<K,V> m, java.lang.String linePrefix)
K
- type of map keysV
- type of map valuessb
- an Appendable (such as StringBuilder) to which to write a multi-line string
representation of mm
- map to be converted to a stringlinePrefix
- prefix to write at the beginning of each linepublic static <K extends java.lang.Comparable<? super K>,V> java.util.Collection<K> sortedKeySet(java.util.Map<K,V> m)
K
- type of the map keysV
- type of the map valuesm
- a map whose keyset will be sortedpublic static <K,V> java.util.Collection<K> sortedKeySet(java.util.Map<K,V> m, java.util.Comparator<K> comparator)
K
- type of the map keysV
- type of the map valuesm
- a map whose keyset will be sortedcomparator
- the Comparator to use for sortingpublic static java.lang.reflect.Method methodForName(java.lang.String method) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.SecurityException
Example calls are:
UtilMDE.methodForName("plume.UtilMDE.methodForName(java.lang.String, java.lang.String, java.lang.Class[])") UtilMDE.methodForName("plume.UtilMDE.methodForName(java.lang.String,java.lang.String,java.lang.Class[])") UtilMDE.methodForName("java.lang.Math.min(int,int)")
method
- a method signaturejava.lang.ClassNotFoundException
- if the class is not foundjava.lang.NoSuchMethodException
- if the method is not foundjava.lang.SecurityException
public static java.lang.reflect.Method methodForName(java.lang.String classname, java.lang.String methodname, java.lang.Class<?>[] params) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.SecurityException
classname
- class in which to find the methodmethodname
- the method nameparams
- the parameters of the methodjava.lang.ClassNotFoundException
- if the class is not foundjava.lang.NoSuchMethodException
- if the method is not foundjava.lang.SecurityException
public static java.lang.String backticks(java.lang.String... command)
command
- a command to execute on the command linepublic static java.lang.String backticks(java.util.List<java.lang.String> command)
command
- a command to execute on the command line, as a list of strings (the command,
then its arguments)public static boolean propertyIsTrue(java.util.Properties p, java.lang.String key)
p
- a Properties object in which to look up the propertykey
- name of the property to look upProperties.getProperty(java.lang.String)
public static java.lang.String appendProperty(java.util.Properties p, java.lang.String key, java.lang.String value)
p
- a Properties object in which to look up the propertykey
- name of the property to look upvalue
- value to concatenate to the previous value of the propertyProperties.getProperty(java.lang.String)
,
Properties.setProperty(java.lang.String, java.lang.String)
public static java.lang.String setDefaultMaybe(java.util.Properties p, java.lang.String key, java.lang.String value)
p
- a Properties object in which to look up the propertykey
- name of the property to look upvalue
- value to set the property to, if it is not already setProperties.getProperty(java.lang.String)
,
Properties.setProperty(java.lang.String, java.lang.String)
public static void setFinalField(java.lang.Object o, java.lang.String fieldName, java.lang.Object value) throws java.lang.NoSuchFieldException
o
- object in which to set the fieldfieldName
- name of field to setvalue
- new value of fieldjava.lang.NoSuchFieldException
- if the field does not exist in the objectpublic static java.lang.Object getPrivateField(java.lang.Object o, java.lang.String fieldName) throws java.lang.NoSuchFieldException
o
- object in which to set the fieldfieldName
- name of field to setjava.lang.NoSuchFieldException
- if the field does not exist in the objectpublic static java.lang.Object getFromSet(java.util.Set<?> set, java.lang.Object key)
set
- a set in which to look up the valuekey
- the value to look up in the setpublic static void streamCopy(java.io.InputStream from, java.io.OutputStream to)
from
- input streamto
- output streampublic static java.lang.String streamString(java.io.InputStream is)
is
- input stream to readpublic static java.util.List<java.lang.String> streamLines(java.io.InputStream stream) throws java.io.IOException
List<String>
.stream
- the stream to read fromjava.io.IOException
- if there is an error reading from the streampublic static java.lang.String replaceString(java.lang.String target, java.lang.String oldStr, java.lang.String newStr)
target
- the string to do replacement inoldStr
- the substring to replacenewStr
- the replacementpublic static java.lang.String[] split(java.lang.String s, char delim)
s
- the string to splitdelim
- delimiter to split the string onsplit(String s, String delim)
public static java.lang.String[] split(java.lang.String s, java.lang.String delim)
s
- the string to splitdelim
- delimiter to split the string onsplit(String s, char delim)
public static java.lang.String[] splitLines(java.lang.String s)
s
- the string to splitsplit(String s, char delim)
public static java.lang.String join(java.lang.Object[] a, java.lang.String delim)
If you are using Java 8 or later, then use the String.join()
method instead.
a
- array of values to concatenatedelim
- delimiter to place between printed representationsArraysMDE.toString(int[])
public static java.lang.String joinLines(java.lang.Object... a)
a
- array of values to concatenateArraysMDE.toString(int[])
public static java.lang.String join(java.lang.Iterable<? extends java.lang.Object> v, java.lang.String delim)
v
- collection of values to concatenatedelim
- delimiter to place between printed representationsAbstractCollection.toString()
public static java.lang.String joinLines(java.util.List<java.lang.String> v)
v
- list of values to concatenateAbstractCollection.toString()
public static java.lang.String escapeNonJava(java.lang.String orig)
orig
- string to quotepublic static java.lang.String escapeNonJava(java.lang.Character ch)
escapeNonJava(String)
, but for a single character.ch
- character to quotepublic static java.lang.String escapeNonASCII(java.lang.String orig)
orig
- string to quotepublic static java.lang.String unescapeNonJava(java.lang.String orig)
orig
- string to quotopublic static java.lang.String removeWhitespaceAround(java.lang.String arg, java.lang.String delimiter)
arg
- string to remove whitespace indelimiter
- string to remove whitespace abuttingpublic static java.lang.String removeWhitespaceAfter(java.lang.String arg, java.lang.String delimiter)
arg
- string to remove whitespace indelimiter
- string to remove whitespace afterpublic static java.lang.String removeWhitespaceBefore(java.lang.String arg, java.lang.String delimiter)
arg
- string to remove whitespace indelimiter
- string to remove whitespace beforepublic static java.lang.String nplural(int n, java.lang.String noun)
n
- count of nounsnoun
- word being countedpublic static java.lang.String lpad(java.lang.String s, int length)
s
- string to truncate or padlength
- goal lengthpublic static java.lang.String rpad(java.lang.String s, int length)
s
- string to truncate or padlength
- goal lengthpublic static java.lang.String rpad(int num, int length)
rpad(String,int)
.num
- int whose string representation to truncate or padlength
- goal lengthpublic static java.lang.String rpad(double num, int length)
rpad(String,int)
.num
- double whose string representation to truncate or padlength
- goal lengthpublic static int count(java.lang.String s, int ch)
s
- string to search inch
- character to search forpublic static int count(java.lang.String s, java.lang.String sub)
s
- string to search insub
- string to search forpublic static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str, java.lang.String delim, boolean returnDelims)
StringTokenizer.StringTokenizer(String,String,boolean)
with the given arguments.
The static type is ArrayList<Object>
because StringTokenizer extends Enumeration<Object>
instead of Enumeration<String>
as it should (probably due to
backward-compatibility).
str
- a string to be parseddelim
- the delimitersreturnDelims
- flag indicating whether to return the delimiters as tokenspublic static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str, java.lang.String delim)
StringTokenizer.StringTokenizer(String,String)
with the given arguments.str
- a string to be parseddelim
- the delimiterspublic static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str)
StringTokenizer.StringTokenizer(String)
with the given arguments.str
- a string to be parsedpublic static java.lang.String backTrace(java.lang.Throwable t)
backtrace(new Throwable())
.t
- the Throwable to obtain a backtrace ofpublic static <T> java.util.List<T> sortList(java.util.List<T> l, java.util.Comparator<? super T> c)
Collections.sort(List<T>, Comparator<? super T>)
.T
- type of elements of the listl
- a list to sortc
- a sorted version of the listpublic static <T> java.util.List<T> removeDuplicates(java.util.List<T> l)
T
- type of elements of the listl
- a list to remove duplicates frompublic static boolean deepEquals(java.lang.Object o1, java.lang.Object o2)
o1
- first value to compareo2
- second value to comarepublic static <T> java.util.ArrayList<T> makeArrayList(java.util.Enumeration<T> e)
T
- type of the enumeration and vector elementse
- an enumeration to convert to a ArrayListpublic static <T> java.util.List<java.util.List<T>> create_combinations(int dims, int start, java.util.List<T> objs)
start
over dims
dimensions, for dims
> 0
.
For example, create_combinations (1, 0, {a, b, c}) returns:
{a}, {b}, {c}And create_combinations (2, 0, {a, b, c}) returns:
{a, a}, {a, b}, {a, c} {b, b}, {b, c}, {c, c}
T
- type of the input list elements, and type of the innermost output list elementsdims
- number of dimensions: that is, size of each innermost liststart
- initial indexobjs
- list of elements to create combinations ofpublic static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> create_combinations(int arity, int start, int cnt)
For example, create_combinations (1, 0, 2) returns:
{0}, {1}, {2}And create_combinations (2, 10, 2) returns:
{10, 10}, {10, 11}, {10, 12} {11, 11} {11, 12}, {12, 12}
arity
- size of each innermost liststart
- initial valuecnt
- maximum element value@Deprecated public static java.lang.String unqualified_name(java.lang.String qualified_name)
fullyQualifiedNameToSimpleName(java.lang.String)
instead.qualified_name
- the fully-qualified name of a classpublic static java.lang.String fullyQualifiedNameToSimpleName(java.lang.String qualified_name)
qualified_name
- the fully-qualified name of a class@Deprecated public static java.lang.String unqualified_name(java.lang.Class<?> cls)
Class.getSimpleName()
instead.cls
- a classpublic static java.lang.String abbreviateNumber(long val)
val
- a numeric value