public class Is
extends java.lang.Object
Useful for implementing asserts (invariants, preconditions, postcondition).
For example:
if (name != null || name.trim().equals("") || surname1 != null || surname1.trim().equals("")) || surname2 != null || surname2.trim().equals("")) { doSomething(); }can be write:
if (Is.emptyString(name, surname1, surname2)) { doSomethis(); }
Constructor and Description |
---|
Is() |
Modifier and Type | Method and Description |
---|---|
static boolean |
anyEqual(java.lang.Object object,
java.lang.Object... possibleValues)
Compare the first argurment with the rest and if any if equal returns true.
|
static boolean |
empty(java.lang.Object object)
Verifies if the sent object is
null or empty string
(if it's string) or 0 (if it's number) or empty Map. |
static boolean |
emptyString(java.lang.String... strs)
Verifies if some of the sent strings are
null or empty string. |
static boolean |
emptyStringAll(java.lang.String... strs)
Verifies if all sent strings are
null or empty string. |
static boolean |
equal(java.lang.Object a,
java.lang.Object b)
If
a is equals to b . |
static boolean |
equalAsString(java.lang.Object a,
java.lang.Object b)
If
a.toString().trim() is equals to b.toString().trim() . |
static boolean |
equalAsStringIgnoreCase(java.lang.Object a,
java.lang.Object b)
If
a.toString().trim() is equal to b.toString().trim() ignoring case. |
public static boolean anyEqual(java.lang.Object object, java.lang.Object... possibleValues)
object
- The object we are looking for. Can null.possibleValues
- The objects where we are looking for. Can contain nulls.public static final boolean empty(java.lang.Object object)
null
or empty string
(if it's string) or 0 (if it's number) or empty Map. Since v5.9 it supports Java native arrays.
public static final boolean emptyString(java.lang.String... strs)
null
or empty string. public static final boolean emptyStringAll(java.lang.String... strs)
null
or empty string. public static final boolean equal(java.lang.Object a, java.lang.Object b)
a
is equals to b
.
Takes in account the nulls. Use compareTo when appropriate and
compares Java 5 enums with numbers by the ordinal value. Compares
Integer, Long, Short among themselves.
Also admits to compare objects of not compatible types, just it returns
false in this case.
Since v5.9 works fine with Java native arrays.
a
- Can be null.b
- Can be null.public static final boolean equalAsString(java.lang.Object a, java.lang.Object b)
a.toString().trim()
is equals to b.toString().trim()
.
Takes in account the nulls.
a
- Can be null.b
- Can be null.public static final boolean equalAsStringIgnoreCase(java.lang.Object a, java.lang.Object b)
a.toString().trim()
is equal to b.toString().trim() ignoring case.
Takes in account the nulls.
a
- Can be null.b
- Can be null.