|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavatools.administrative.D
public class D
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools).
It is licensed under the Creative Commons Attribution License
(see http://creativecommons.org/licenses/by/3.0) by
the YAGO-NAGA team (see http://mpii.de/yago-naga).
This class provides convenience methods for Input/Output.
Allows to do basic I/O with easy procedure calls
-- nearly like in normal programming languages.
Furthermore, the class provides basic set operations for EnumSets, NULL-safe
comparisons and adding to maps.
Example:
D.p("This is an easy way to write a string"); // And this is an easy way to read one: String s=D.r(); // Here is a cool way to print something inline computeProduct(factor1,(Integer)D.p(factor2)); // Here are some tricks with enums enum T {a,b,c}; EnumSet<T> i=D.intersection(EnumSet.of(T.a,T.b),EnumSet.of(T.b,T.c)); EnumSet<T> u=D.union(EnumSet.of(T.a,T.b),EnumSet.of(T.b,T.c)); // Here is how to compare things, even if they are NULL D.compare(object1, object2); // Here is how to add something to maps that contain lists Map<String,List<String>> string2list=new TreeMap<String,List<String>>(); D.addKeyValue(string2list,"key","new list element",ArrayList.class); // now, the map contains "key" -> [ "new list element" ] D.addKeyValue(string2list,"key","again a new list element",ArrayList.class); // now, the map contains "key" -> [ "new list element", "again a new list element" ] // Here is how to add something to maps that contain integers Map<String,Integer> string2list=new TreeMap<String,Integer>(); D.addKeyValue(string2list,"key",7); // map now contains "key" -> 7 D.addKeyValue(string2list,"key",3); // map now contains "key" -> 10
Field Summary | |
---|---|
static int |
indent
Indentation margin. |
Constructor Summary | |
---|---|
D()
|
Method Summary | ||
---|---|---|
static
|
addKeyValue(java.util.Map<K,C> map,
K key,
V value,
java.lang.Class<L> collectionType)
Given a map that maps to collections, adds a new key/value pair or introduces the key |
|
static
|
addKeyValue(java.util.Map<K,java.lang.Integer> map,
K key,
int value)
Given a map that maps to integers, adds a new key/value pair or increases the counter |
|
static
|
addKeyValueDbl(java.util.Map<K,java.lang.Double> map,
K key,
double value)
Given a map that maps to doubles, adds a new key/value pair or increases the counter |
|
static
|
addKeyValueFlt(java.util.Map<K,java.lang.Float> map,
K key,
float value)
Given a map that maps to floats, adds a new key/value pair or increases the counter |
|
static
|
addKeyValues(java.util.Map<K,C> map,
K key,
C values,
java.lang.Class<L> collectionType)
Given a map that maps to collections, adds a new key/value pair or introduces the key |
|
static
|
compare(E s1,
E s2)
Compares two things, including NULL |
|
static int |
comparePairs(java.lang.Object... o)
Compares pairs of comparable things (a1,a2,b1,b2,...), including NULL |
|
static
|
containsOneOf(java.util.EnumSet<E> s1,
java.util.EnumSet<E> s2)
Tells whether the intersection is non-empty |
|
static
|
equal(E s1,
E s2)
Returns true if two things are equal, including NULL |
|
static boolean |
equalPairs(java.lang.Object... o)
Compares pairs of comparable things (a1,a2,b1,b2,...) for equality, including NULL |
|
static void |
execute(java.lang.String cmd,
java.io.File folder)
Executes a command |
|
static void |
exit()
Exits with error code 0 |
|
static
|
getOr(java.util.Map<K,V> map,
K key,
V defValue)
Returns the element of a map or a default value |
|
static
|
getOrZero(java.util.Map<K,java.lang.Integer> map,
K key)
Returns the element of a map or 0 |
|
static
|
getOrZeroDouble(java.util.Map<K,java.lang.Double> map,
K key)
Returns the element of a map or 0 |
|
static int |
indexOf(java.lang.Object o,
java.lang.Object... os)
Returns the index of a thing in an array or -1 |
|
static
|
intersection(java.util.EnumSet<E> s1,
java.util.EnumSet<E> s2)
Returns the intersection of two enumsets |
|
static
|
intersectionSize(java.util.Collection<T> c1,
java.util.Collection<T> c2)
Returns the size of the intersection |
|
static double[] |
p(double[] a)
Prints an array of doubles |
|
static int[] |
p(int[] a)
Prints an array of integers |
|
static java.lang.Object |
p(java.lang.Object... a)
Prints some Objects, returns them |
|
static
|
pick(java.util.Collection<T> set)
Picks one element from a set or NULL |
|
static void |
pl(java.lang.Object... a)
Prints some Objects on one line |
|
static java.lang.Object |
println(java.lang.Object... a)
Prints some Objects |
|
static java.lang.String |
r()
Reads a line from the keyboard |
|
static java.lang.String |
read()
Reads a line from the keyboard |
|
static java.lang.String |
read(java.lang.String question)
Reads a long from the keyboard |
|
static boolean |
readBoolean(java.lang.String question)
Reads a long from the keyboard |
|
static double |
readDouble(java.lang.String question)
Reads a double from the keyboard |
|
static long |
readLong(java.lang.String question)
Reads a long from the keyboard |
|
static
|
setKeyValueIfGreaterThanCurrent(java.util.Map<K,V> map,
K key,
V value)
Given a map that maps to comparable objects, sets a key to a given value iff the current value is null or smaller than the given value |
|
static void |
silentWriteln(java.io.Writer out,
java.lang.Object s)
Writes a line silently to a writer. |
|
static
|
smaller(java.lang.Enum<C> e1,
java.lang.Enum<C> e2)
TRUE if the first enum is before the second |
|
static
|
sorted(java.util.Map<T,java.lang.Integer> map)
Returns a sorted list of the items |
|
static
|
sortedDouble(java.util.Map<T,java.lang.Double> map)
Returns a sorted list of the items |
|
static java.lang.String |
toString(java.lang.Object... o)
Returns a reasonable String representation of a sequence of things. |
|
static
|
union(java.util.EnumSet<E> s1,
java.util.EnumSet<E> s2)
Returns the union of two enumsets |
|
static void |
waitMS(long milliseconds)
Waits for a number of milliseconds |
|
static void |
writeln(java.io.OutputStream out,
java.lang.Object s)
Writes a line to a writer. |
|
static void |
writeln(java.io.Writer out,
java.lang.Object s)
Writes a line to a writer. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int indent
Constructor Detail |
---|
public D()
Method Detail |
---|
public static java.lang.Object p(java.lang.Object... a)
public static java.lang.Object println(java.lang.Object... a)
public static void pl(java.lang.Object... a)
public static int[] p(int[] a)
public static double[] p(double[] a)
public static java.lang.String r()
public static java.lang.String read()
public static java.lang.String read(java.lang.String question)
public static boolean readBoolean(java.lang.String question)
public static long readLong(java.lang.String question)
public static double readDouble(java.lang.String question)
public static void waitMS(long milliseconds)
public static <E extends java.lang.Enum<E>> java.util.EnumSet<E> intersection(java.util.EnumSet<E> s1, java.util.EnumSet<E> s2)
public static <E extends java.lang.Enum<E>> java.util.EnumSet<E> union(java.util.EnumSet<E> s1, java.util.EnumSet<E> s2)
public static <E extends java.lang.Enum<E>> boolean containsOneOf(java.util.EnumSet<E> s1, java.util.EnumSet<E> s2)
public static void exit()
public static void writeln(java.io.Writer out, java.lang.Object s) throws java.io.IOException
java.io.IOException
public static void writeln(java.io.OutputStream out, java.lang.Object s) throws java.io.IOException
java.io.IOException
public static void silentWriteln(java.io.Writer out, java.lang.Object s)
public static void execute(java.lang.String cmd, java.io.File folder) throws java.lang.Exception
java.lang.Exception
public static <K,V,C extends java.util.Collection<V>,L extends java.util.Collection> void addKeyValue(java.util.Map<K,C> map, K key, V value, java.lang.Class<L> collectionType)
public static <K,V,C extends java.util.Collection<V>,L extends java.util.Collection> void addKeyValues(java.util.Map<K,C> map, K key, C values, java.lang.Class<L> collectionType)
public static <K> void addKeyValue(java.util.Map<K,java.lang.Integer> map, K key, int value)
public static <K> void addKeyValueFlt(java.util.Map<K,java.lang.Float> map, K key, float value)
public static <K> void addKeyValueDbl(java.util.Map<K,java.lang.Double> map, K key, double value)
public static <K,V extends java.lang.Comparable<V>> void setKeyValueIfGreaterThanCurrent(java.util.Map<K,V> map, K key, V value)
public static <K> int getOrZero(java.util.Map<K,java.lang.Integer> map, K key)
public static <K> double getOrZeroDouble(java.util.Map<K,java.lang.Double> map, K key)
public static <K,V> V getOr(java.util.Map<K,V> map, K key, V defValue)
public static <T> java.util.List<T> sorted(java.util.Map<T,java.lang.Integer> map)
public static <T> java.util.List<T> sortedDouble(java.util.Map<T,java.lang.Double> map)
public static <E> boolean equal(E s1, E s2)
public static <E extends java.lang.Comparable<E>> int compare(E s1, E s2)
public static int comparePairs(java.lang.Object... o)
public static boolean equalPairs(java.lang.Object... o)
public static int indexOf(java.lang.Object o, java.lang.Object... os)
public static <C extends java.lang.Enum<C>> boolean smaller(java.lang.Enum<C> e1, java.lang.Enum<C> e2)
public static java.lang.String toString(java.lang.Object... o)
public static <T> T pick(java.util.Collection<T> set)
public static <T> int intersectionSize(java.util.Collection<T> c1, java.util.Collection<T> c2)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |