public class D extends 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 Collection<V>,L extends Collection> |
addKeyValue(Map<K,C> map,
K key,
V value,
Class<L> collectionType)
Given a map that maps to collections, adds a new key/value pair or introduces the key
|
static <K,V extends Enum<V>> |
addKeyValue(Map<K,EnumSet<V>> map,
K key,
V value)
Given a map that maps to EnumSets, adds a new key/value pair or introduces the key
|
static <K> void |
addKeyValue(Map<K,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(Map<K,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(Map<K,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 Collection<V>,L extends Collection> |
addKeyValues(Map<K,C> map,
K key,
C values,
Class<L> collectionType)
Given a map that maps to collections, adds a new key/value pair or introduces the key
|
static <E extends Comparable<E>> |
compare(E s1,
E s2)
Compares two things, including NULL
|
static int |
comparePairs(Object... o)
Compares pairs of comparable things (a1,a2,b1,b2,...), including NULL
|
static <E extends Enum<E>> |
containsOneOf(EnumSet<E> s1,
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(Object... o)
Compares pairs of comparable things (a1,a2,b1,b2,...) for equality, including NULL
|
static void |
execute(String cmd,
File folder)
Executes a command
|
static void |
exit()
Exits with error code 0
|
static <K,V> V |
getOr(Map<K,V> map,
K key,
V defValue)
Returns the element of a map or a default value
|
static <K> int |
getOrZero(Map<K,Integer> map,
K key)
Returns the element of a map or 0
|
static <K> double |
getOrZeroDouble(Map<K,Double> map,
K key)
Returns the element of a map or 0
|
protected static void |
i()
Prints <indent> spaces
|
static int |
indexOf(Object o,
Object... os)
Returns the index of a thing in an array or -1
|
static <E extends Enum<E>> |
intersection(EnumSet<E> s1,
EnumSet<E> s2)
Returns the intersection of two enumsets
|
static <T> int |
intersectionSize(Collection<T> c1,
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 Object |
p(Object... a)
Prints some Objects, returns them
|
static <T> T |
pick(Collection<T> set)
Picks one element from a set or NULL
|
static void |
pl(Object... a)
Prints some Objects on one line
|
static Object |
println(Object... a)
Prints some Objects
|
static String |
r()
Reads a line from the keyboard
|
static String |
read()
Reads a line from the keyboard
|
static String |
read(String question)
Reads a long from the keyboard
|
static boolean |
readBoolean(String question)
Reads a long from the keyboard
|
static double |
readDouble(String question)
Reads a double from the keyboard
|
static long |
readLong(String question)
Reads a long from the keyboard
|
static <K,V extends Comparable<V>> |
setKeyValueIfGreaterThanCurrent(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(Writer out,
Object s)
Writes a line silently to a writer.
|
static <C extends Enum<C>> |
smaller(Enum<C> e1,
Enum<C> e2)
TRUE if the first enum is before the second
|
static <T> List<T> |
sorted(Map<T,Integer> map)
Returns a sorted list of the items
|
static <T> List<T> |
sortedDouble(Map<T,Double> map)
Returns a sorted list of the items
|
static String |
toString(Object... o)
Returns a reasonable String representation of a sequence of things.
|
static <E extends Enum<E>> |
union(EnumSet<E> s1,
EnumSet<E> s2)
Returns the union of two enumsets
|
static void |
waitMS(long milliseconds)
Waits for a number of milliseconds
|
static void |
writeln(OutputStream out,
Object s)
Writes a line to a writer.
|
static void |
writeln(Writer out,
Object s)
Writes a line to a writer.
|
public static int indent
protected static void i()
public static void pl(Object... a)
public static int[] p(int[] a)
public static double[] p(double[] a)
public static String r()
public static String read()
public static boolean readBoolean(String question)
public static long readLong(String question)
public static double readDouble(String question)
public static void waitMS(long milliseconds)
public static <E extends Enum<E>> EnumSet<E> intersection(EnumSet<E> s1, EnumSet<E> s2)
public static <E extends Enum<E>> EnumSet<E> union(EnumSet<E> s1, EnumSet<E> s2)
public static <E extends Enum<E>> boolean containsOneOf(EnumSet<E> s1, EnumSet<E> s2)
public static void exit()
public static void writeln(Writer out, Object s) throws IOException
IOExceptionpublic static void writeln(OutputStream out, Object s) throws IOException
IOExceptionpublic static void silentWriteln(Writer out, Object s)
public static void execute(String cmd, File folder) throws Exception
Exceptionpublic static <K,V,C extends Collection<V>,L extends Collection> void addKeyValue(Map<K,C> map, K key, V value, Class<L> collectionType)
public static <K,V extends Enum<V>> void addKeyValue(Map<K,EnumSet<V>> map, K key, V value)
public static <K,V,C extends Collection<V>,L extends Collection> void addKeyValues(Map<K,C> map, K key, C values, Class<L> collectionType)
public static <K> void addKeyValue(Map<K,Integer> map, K key, int value)
public static <K> void addKeyValueFlt(Map<K,Float> map, K key, float value)
public static <K> void addKeyValueDbl(Map<K,Double> map, K key, double value)
public static <K,V extends Comparable<V>> void setKeyValueIfGreaterThanCurrent(Map<K,V> map, K key, V value)
public static <K> int getOrZero(Map<K,Integer> map, K key)
public static <K> double getOrZeroDouble(Map<K,Double> map, K key)
public static <K,V> V getOr(Map<K,V> map, K key, V defValue)
public static <T> List<T> sortedDouble(Map<T,Double> map)
public static <E> boolean equal(E s1,
E s2)
public static <E extends Comparable<E>> int compare(E s1, E s2)
public static int comparePairs(Object... o)
public static boolean equalPairs(Object... o)
public static int indexOf(Object o, Object... os)
public static <C extends Enum<C>> boolean smaller(Enum<C> e1, Enum<C> e2)
public static String toString(Object... o)
public static <T> T pick(Collection<T> set)
public static <T> int intersectionSize(Collection<T> c1, Collection<T> c2)
Copyright © 2018. All rights reserved.