List of usage examples for org.apache.commons.lang ObjectUtils equals
public static boolean equals(Object object1, Object object2)
Compares two objects for equality, where either one or both objects may be null
.
ObjectUtils.equals(null, null) = true ObjectUtils.equals(null, "") = false ObjectUtils.equals("", null) = false ObjectUtils.equals("", "") = true ObjectUtils.equals(Boolean.TRUE, null) = false ObjectUtils.equals(Boolean.TRUE, "true") = false ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE) = true ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false
From source file:MainClass.java
public static void main(String[] args) { //Create ObjectUtilsTrial instance MyClass one = new MyClass(); MyClass two = one; //Same Reference MyClass three = new MyClass(); //New Object MyClass four = null;/*from w w w. j a v a 2s . c om*/ //one and two point to the same object System.out.print("2) References to the same object >>>"); System.out.println(ObjectUtils.equals(one, two)); }
From source file:MainClass.java
public static void main(String[] args) { //Create ObjectUtilsTrial instance MyClass one = new MyClass(); MyClass two = one; //Same Reference MyClass three = new MyClass(); //New Object MyClass four = null;/*from www . jav a 2s . c o m*/ //one and three are different objects System.out.print("3) Check object references and not values >>>"); System.out.println(ObjectUtils.equals(one, three)); }
From source file:ObjectUtilsTrial.java
public static void main(String[] args) { // Create ObjectUtilsTrial instance String one = new String(); String two = one; // Same Reference String three = new String(); // New Object String four = null;//from w w w . ja v a2 s. c o m // four is null, returns DEFAULT System.out.print("1) If null return DEFAULT >>>"); System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT")); // one and two point to the same object System.out.print("2) References to the same object >>>"); System.out.println(ObjectUtils.equals(one, two)); // one and three are different objects System.out.print("3) Check object references and not values >>>"); System.out.println(ObjectUtils.equals(one, three)); // toString method gets called System.out.print("4) toSring gets invoked >>>"); System.out.println(one); // Object details displayed..toString is not called System.out.print("5) Display object details >>>"); System.out.println(ObjectUtils.identityToString(one)); // Pass null get empty string System.out.print("6) Pass null and get back an Empty string >>>"); System.out.println("**" + ObjectUtils.toString(null) + "**"); }
From source file:com.haulmont.cuba.core.entity.LockDescriptorNameType.java
public static LockDescriptorNameType fromId(String id) { for (LockDescriptorNameType type : LockDescriptorNameType.values()) { if (ObjectUtils.equals(id, type.getId())) return type; }/* w w w . j a v a2s .c o m*/ return null; // unknown id }
From source file:com.dianping.lion.util.EnumUtils.java
/** * ?property??// w w w . jav a 2s. c o m * @param <T> * @param enumClass * @param property * @param propValue * @return */ public static <T extends Enum<T>> T fromEnumProperty(Class<T> enumClass, String property, Object propValue) { T[] enumConstants = enumClass.getEnumConstants(); for (T t : enumConstants) { Object constantPropValue; try { constantPropValue = BeanUtils.getDeclaredFieldValue(t, property); if (ObjectUtils.equals(constantPropValue, propValue)) { return t; } } catch (Exception e) { throw new RuntimeException(e); } } return null; }
From source file:com.haulmont.cuba.security.entity.ConstraintOperationType.java
public static ConstraintOperationType fromId(String id) { for (ConstraintOperationType area : ConstraintOperationType.values()) { if (ObjectUtils.equals(id, area.getId())) return area; }//from w w w .j ava2s . c o m return null; // unknown id }
From source file:com.haulmont.cuba.security.entity.ConstraintCheckType.java
public static ConstraintCheckType fromId(String id) { for (ConstraintCheckType type : ConstraintCheckType.values()) { if (ObjectUtils.equals(id, type.getId())) return type; }//from w w w .ja va 2 s . co m return null; // unknown id }
From source file:com.haulmont.cuba.gui.app.security.entity.PermissionVariant.java
public static PermissionVariant fromId(Integer id) { for (PermissionVariant variant : PermissionVariant.values()) { if (ObjectUtils.equals(variant.getId(), id)) { return variant; }/*ww w .j ava 2 s. c o m*/ } return null; }
From source file:com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant.java
public static UiPermissionVariant fromId(Integer id) { for (UiPermissionVariant variant : UiPermissionVariant.values()) { if (ObjectUtils.equals(variant.getId(), id)) { return variant; }// w w w .j a va 2s . c o m } return null; }
From source file:com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant.java
public static AttributePermissionVariant fromId(Integer id) { for (AttributePermissionVariant variant : AttributePermissionVariant.values()) { if (ObjectUtils.equals(variant.getId(), id)) { return variant; }/* ww w . j a v a2 s.com*/ } return null; }