public class D
extends java.lang.Object
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
| Modifier and Type | Field and Description |
|---|---|
static int |
indent
Indentation margin.
|
| Constructor and Description |
|---|
D() |
| Modifier and Type | Method and Description |
|---|---|
static <K,V,C extends java.util.Collection<V>,L extends java.util.Collection> |
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 <K> void |
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 <K> void |
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 <K> void |
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 <K,V,C extends java.util.Collection<V>,L extends java.util.Collection> |
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 <E extends java.lang.Comparable<E>> |
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 <E extends java.lang.Enum<E>> |
containsOneOf(java.util.EnumSet<E> s1,
java.util.EnumSet<E> s2)
Tells whether the intersection is non-empty
|
static <E> boolean |
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 <K,V> V |
getOr(java.util.Map<K,V> map,
K key,
V defValue)
Returns the element of a map or a default value
|
static <K> int |
getOrZero(java.util.Map<K,java.lang.Integer> map,
K key)
Returns the element of a map or 0
|
static <K> double |
getOrZeroDouble(java.util.Map<K,java.lang.Double> map,
K key)
Returns the element of a map or 0
|
protected static void |
i()
Prints
|
static int |
indexOf(java.lang.Object o,
java.lang.Object... os)
Returns the index of a thing in an array or -1
|
static <E extends java.lang.Enum<E>> |
intersection(java.util.EnumSet<E> s1,
java.util.EnumSet<E> s2)
Returns the intersection of two enumsets
|
static <T> int |
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 <T> T |
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 <K,V extends java.lang.Comparable<V>> |
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 <C extends java.lang.Enum<C>> |
smaller(java.lang.Enum<C> e1,
java.lang.Enum<C> e2)
TRUE if the first enum is before the second
|
static <T> java.util.List<T> |
sorted(java.util.Map<T,java.lang.Integer> map)
Returns a sorted list of the items
|
static <T> java.util.List<T> |
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 <E extends java.lang.Enum<E>> |
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.
|
public static int indent
protected static void i()
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.IOExceptionpublic static void writeln(java.io.OutputStream out,
java.lang.Object s)
throws java.io.IOException
java.io.IOExceptionpublic 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.Exceptionpublic 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)