Modifier and Type | Field and Description |
---|---|
static char |
GSEP |
static ZoneId |
UTC |
static Charset |
UTF8 |
Constructor and Description |
---|
Literals() |
Modifier and Type | Method and Description |
---|---|
static <T,R> List<R> |
apply(Collection<T> coll,
Function<? super T,? extends R> mapper)
Simple, Python style list comprehensions helper:
List<Integer> listB = apply(listA, a -> a * a);
Hat tip: http://stackoverflow.com/questions/26205409/java-8-idiomatic-way-to-apply-a-lambda-to-a-list-returning-another-list
|
static boolean |
areEqual(Object a,
Object b)
Null safe check for equals.
|
static <T> T[] |
array(T... elems) |
static <T> T[] |
asArray(List<T> myList,
Class<? extends T> cls) |
static <T> List<T> |
asList(T... things) |
static <K,V> Map<K,V> |
defaultMap(Class<? extends V> cls,
Map.Entry<K,V>... entries) |
static <K,V> Map<K,V> |
defaultMap(V prototype,
Map.Entry<K,V>... entries) |
static boolean |
empty(CharSequence a) |
static boolean |
empty(Collection a) |
static boolean |
empty(int a) |
static boolean |
empty(Integer a) |
static boolean |
empty(long a) |
static boolean |
empty(Long a) |
static boolean |
empty(Map a) |
static boolean |
empty(Object[] objects) |
static boolean |
empty(ZonedDateTime dt) |
static boolean |
emptyInstance(Object o) |
static boolean |
emptyObject(Object o) |
static <T> List<T> |
filter(Collection<T> coll,
Predicate<? super T> filterer)
Simple, Python style list comprehensions helper:
List<Integer> listB = apply(listA, a -> !empty(a));
Hat tip: http://stackoverflow.com/questions/26205409/java-8-idiomatic-way-to-apply-a-lambda-to-a-list-returning-another-list
|
static <T> List<T> |
filterEmpty(Collection<T> things) |
static String |
firstTruthy(String... things) |
static <T> List<T> |
list(T... elems) |
static <K,V> Map<K,V> |
map(Map.Entry<K,V>... entries) |
static long |
mils() |
static Integer |
or(Integer obj,
Integer defaultVal) |
static Long |
or(Long obj,
Long defaultVal) |
static String |
or(String obj,
String defaultVal) |
static <T> T |
or(T obj,
T defaultVal) |
static Iterable<Integer> |
safeLoop(int max)
safeLoop() returns an iterator that will run a maximum of "max" times before throwing an exception
Use safeLoop() instead of a while loop:
Do not do:
while (true) {
// some logic
if (endCondition) {
break;
}
}
Instead do:
for(int x: safeLoop(1000)) {
// some logic
if (endCondition) {
break;
}
}
That way if your logic goes awry, you won't hard crash the server by eating up all the CPU.
|
static <T> Set<T> |
set(T... elems) |
static String |
slice(String s,
int start,
int end)
Imitation of Python's [2:-7] syntax that never throws errors while slicing
and that accepts negative indexes
|
static <T extends List> |
slice(T l,
int start,
int end) |
static String |
truncate(String s,
int length) |
static <T extends List> |
truncate(T l,
int length) |
static String |
truncateSmart(String s,
int length)
A truncat the tries to truncate on a sentence or word boundary.
|
static ZonedDateTime |
utcNow() |
static <K,V> Map.Entry<K,V> |
val(K key,
V value) |
public static final char GSEP
public Literals()
public static boolean areEqual(Object a, Object b)
a
- b
- public static <T> T or(T obj, T defaultVal)
public static String firstTruthy(String... things)
public static String slice(String s, int start, int end)
s
- start
- end
- public static String truncateSmart(String s, int length)
s
- length
- public static long mils()
public static ZonedDateTime utcNow()
public static <T> T[] array(T... elems)
public static <K,V> Map<K,V> defaultMap(Class<? extends V> cls, Map.Entry<K,V>... entries)
public static <K,V> Map<K,V> defaultMap(V prototype, Map.Entry<K,V>... entries)
public static boolean emptyInstance(Object o)
public static boolean emptyObject(Object o)
public static boolean empty(ZonedDateTime dt)
public static boolean empty(Collection a)
public static boolean empty(CharSequence a)
public static boolean empty(int a)
public static boolean empty(long a)
public static <T,R> List<R> apply(Collection<T> coll, Function<? super T,? extends R> mapper)
T
- R
- coll
- mapper
- public static <T> List<T> filter(Collection<T> coll, Predicate<? super T> filterer)
T
- coll
- filterer
- public static <T> List<T> filterEmpty(Collection<T> things)
public static Iterable<Integer> safeLoop(int max)
max
- Copyright © 2016. All rights reserved.