[OmniFaces utilities] The
isEmpty()
method returns true
if the given value is null
or is empty. Types of String
, Collection
, Map
and Array
are recognized. If none is recognized, then examine the emptiness of the toString()
representation instead.Methods:
This method uses the below ones (which can be invoked individually):
Testing a String:
String aString = null;
String bString = "";
String cString = "Done!";
import org.omnifaces.util.Utils;
...
boolean a = Utils.isEmpty(aString); // true
boolean b = Utils.isEmpty(bString); // true
boolean c = Utils.isEmpty(cString); // false
Testing an Object[]:
Object[] aObjectArray = null;
Object[] bObjectArray = new Object[1];
Object[] cObjectArray = {1};
boolean a = Utils.isEmpty(aObjectArray); // true
boolean b = Utils.isEmpty(bObjectArray); // false
boolean c = Utils.isEmpty(cObjectArray); // false
Testing a List:
List aList = null;
List bList = new ArrayList();
List<String> cList = new ArrayList<>();
ArrayList<String> dList = new ArrayList<String>() {
{
add("A");
add("B");
add("C");
}
};
boolean a =
Utils.isEmpty(aList); // true
boolean b =
Utils.isEmpty(bList); // true
boolean c =
Utils.isEmpty(cList); // true
boolean d =
Utils.isEmpty(dList); // false
Testing a Map:
Testing a Map:
Map aMap = null;
Map bMap = new HashMap();
Map<String, String> cMap = new HashMap<>();
Map<Byte, Integer> dMap = new HashMap<Byte,
Integer>() {
{
put(new
Byte("1"), 1);
put(new
Byte("2"), 2);
};
};
boolean a =
Utils.isEmpty(aMap); // true
boolean b =
Utils.isEmpty(bMap); // true
boolean c =
Utils.isEmpty(cMap); // true
boolean d = Utils.isEmpty(dMap); // false
Niciun comentariu :
Trimiteți un comentariu