| Constructor and Description |
|---|
ICore() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
and(T... operands)
Returns the last parameter, if all parameters evaluate to true (via
isTrue). |
static <T> T |
and(T a,
T b)
If both parameters evaluate to true (via
isTrue), then the
second value is returned. |
static <T> T[] |
ary(T... args)
Converts varargs to T[].
|
static <T> T |
elvis(T obj,
T defVal)
An alias for the
or method. |
static Array<java.lang.Integer> |
intlist(java.lang.Integer... elements)
Returns an integer list, which can be empty.
|
static boolean |
isEmpty(java.lang.Object obj)
Returns whether the object is null or is a string or collection of zero length.
|
static boolean |
isEmpty(java.lang.String str)
Returns whether the string is null or of zero length.
|
static boolean |
isFalse(java.lang.Object... objs)
Returns whether the array is not null and is not of zero length.
|
static boolean |
isFalse(java.lang.Object obj)
Returns whether the object is null or is a string or collection of zero length.
|
static boolean |
isNotNull(java.lang.Object obj)
Returns whether the object is not null.
|
static boolean |
isNull(java.lang.Object obj)
Returns whether the object is null.
|
static boolean |
isTrue(java.lang.Object... objs)
Returns whether the array is not null and is not of zero length.
|
static boolean |
isTrue(java.lang.Object obj)
Returns whether the object is non-null and, if it is a collection or a
string, has a length greater than zero.
|
static java.lang.Iterable<java.lang.Integer> |
iter(int num)
Returns an iterator to be executed
num times. |
static <T> java.lang.Iterable<T> |
iter(java.lang.Iterable<T> coll)
Returns an Iterable (iterator) for the collection, which can be null.
|
static <T> java.lang.Iterable<T> |
iter(T[] ary)
Returns an Iterable (iterator) for the C-style array, which can be null.
|
static <T> Array<T> |
list(T... elements)
Returns a list (a Array) initialized with the given elements.
|
static <KeyType,ValueType> |
map()
Creates an empty tree map.
|
static <KeyType,ValueType> |
map(KeyType k1,
ValueType v1)
Creates a map with one key/value pair.
|
static <KeyType,ValueType> |
map(KeyType k1,
ValueType v1,
KeyType k2,
ValueType v2)
Creates a map with two key/value pairs.
|
static <T> T |
or(T... operands)
Returns the first parameter that evaluates to true (via
isTrue). |
static <T> T |
or(T a,
T b)
Returns the first parameter if it is true, and otherwise returns the
default value.
|
static boolean |
printf(java.lang.String fmt,
java.lang.Object... args)
Writes to standard output.
|
static boolean |
println(java.lang.Object obj)
Writes to standard output.
|
static boolean |
puts(java.lang.Object obj)
Writes to standard output.
|
static StringList |
strlist(java.lang.String... elements)
Returns an string list, which can be empty.
|
public static boolean isTrue(java.lang.Object obj)
obj - the object to checkisEmpty(java.lang.Object),
isFalse(java.lang.Object),
ObjectExt.isTrue(java.lang.Object)public static boolean isTrue(java.lang.Object... objs)
objs - the arrayisEmpty(java.lang.Object),
isFalse(java.lang.Object)public static boolean isFalse(java.lang.Object obj)
obj - the object to checkisEmpty(java.lang.Object)public static boolean isFalse(java.lang.Object... objs)
objs - the arrayisEmpty(java.lang.Object)public static boolean isEmpty(java.lang.Object obj)
obj - the object to checkisEmpty(java.lang.Object)public static boolean isEmpty(java.lang.String str)
str - the string to checkisEmpty(java.lang.Object)public static boolean isNull(java.lang.Object obj)
obj - the object to checkisNotNull(java.lang.Object)public static boolean isNotNull(java.lang.Object obj)
obj - the object to checkisNull(java.lang.Object)public static <T> T or(T a,
T b)
String statusName = userName != null ? userName : "guest";
String statusName = IUtil.or(userName, "guest");
This method is best for simple objects, since the default value is
evaluated before the method is executed. For example, in the second block
below, db.initialize() will be called.
String status = IUtil.or(db.status(), db.initialize());
String status = db.status() != null ? db.status() : db.initialize());
T - the type of a and ba - the value returned if trueb - the value returned if a is not true, and b is trueelvis(T, T),
isTrue(java.lang.Object)public static <T> T and(T a,
T b)
isTrue), then the
second value is returned. This results in code such as:
String statusName = userName != null && lastName != null ? lastName : null;
String statusName = IUtil.and(userName, lastName);
T - the type of a and ba - the value returned if trueb - the value returned if a is not true, and b is trueor(T, T),
isTrue(java.lang.Object)public static <T> T elvis(T obj,
T defVal)
or method. So-named for the "?:" operator
in Groovy.obj - the object to return if truedefVal - returned if obj is not trueor(T, T)@SafeVarargs public static <T> T and(T... operands)
isTrue).operands - the array of type Tor(T, T),
isTrue(java.lang.Object)@SafeVarargs public static <T> T or(T... operands)
isTrue).operands - the array of type Tor(T, T),
isTrue(java.lang.Object)public static <T> java.lang.Iterable<T> iter(T[] ary)
ary is null, an "empty" iterator will be returned.ary - the array to iterate over; can be nullpublic static <T> java.lang.Iterable<T> iter(java.lang.Iterable<T> coll)
coll is null, an "empty" iterator will be returned.coll - the collection to iterate over; can be nullpublic static java.lang.Iterable<java.lang.Integer> iter(int num)
num times.num - the number of times to iterate@SafeVarargs public static <T> Array<T> list(T... elements)
Arrays.asList(...), which returns a fixed-size, immutable
array). The following two blocks are equivalent:
List<String> names = new Array<String>(Arrays.asList("kevin", "jacob", "isaac"));
names.add("henry");
List<String> names = list("kevin", "jacob", "isaac");
names.add("henry");
elements - the array of type Tpublic static StringList strlist(java.lang.String... elements)
ICore.<String>list() for empty string lists.elements - the elements for the new arraypublic static Array<java.lang.Integer> intlist(java.lang.Integer... elements)
ICore.<Integer>list() for empty integer lists.elements - the elements for the new arraypublic static boolean puts(java.lang.Object obj)
obj - the object to writepublic static boolean printf(java.lang.String fmt,
java.lang.Object... args)
fmt - the formatargs - the arguments for the formatpublic static boolean println(java.lang.Object obj)
obj - the object to writepublic static <KeyType,ValueType> java.util.TreeMap<KeyType,ValueType> map()
public static <KeyType,ValueType> java.util.TreeMap<KeyType,ValueType> map(KeyType k1,
ValueType v1)
public static <KeyType,ValueType> java.util.TreeMap<KeyType,ValueType> map(KeyType k1,
ValueType v1,
KeyType k2,
ValueType v2)
@SafeVarargs public static <T> T[] ary(T... args)
ary("one", 1) is shorter than new Object[] {
"one", 1 }. For Object arrays (i.e., to work around the "unchecked generic array
creation" warning), use Common#objary.