Class Is
java.lang.Object
org.openxava.util.Is
Utility class to reduce the ifs size.
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();
}
- Author:
- Javier Paniza, Hayrol Reyes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCompare the first argurment with the rest and if any if equal returns true.static final booleanVerifies if the sent object is null or a "neutral" value: - Empty string - Number zero (including BigDecimal ZERO) - Empty-or-zero Map (seeMaps.isEmptyOrZero(Map)) - Empty-or-zero Collection (seeXCollections.isEmptyOrZero(Collection)) - Empty Java native arraystatic final booleanemptyString(String... strs) Verifies if some of the sent strings arenullor empty string.static final booleanemptyStringAll(String... strs) Verifies if all sent strings arenullor empty string.static final booleanIfais equals tob.static final booleanequalAsString(Object a, Object b) Ifa.toString().trim()is equals tob.toString().trim().static final booleanIfa.toString().trim()is equal to b.toString().trim() ignoring case.
-
Constructor Details
-
Is
public Is()
-
-
Method Details
-
anyEqual
Compare the first argurment with the rest and if any if equal returns true. Uses Is.equal() to compare the elements. The null is a valid value, so if you send null as first argument and any of the possible value is null returns true.- Parameters:
object- The object we are looking for. Can null.possibleValues- The objects where we are looking for. Can contain nulls.- Since:
- 5.6
-
empty
Verifies if the sent object is null or a "neutral" value: - Empty string - Number zero (including BigDecimal ZERO) - Empty-or-zero Map (seeMaps.isEmptyOrZero(Map)) - Empty-or-zero Collection (seeXCollections.isEmptyOrZero(Collection)) - Empty Java native arraySince v5.9 it supports Java native arrays. Since v7.6 it supports collections.
-
emptyString
Verifies if some of the sent strings arenullor empty string. -
emptyStringAll
Verifies if all sent strings arenullor empty string. -
equal
Ifais equals tob.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.- Parameters:
a- Can be null.b- Can be null.
-
equalAsString
-
equalAsStringIgnoreCase
-