List of usage examples for org.apache.commons.lang.builder EqualsBuilder append
public EqualsBuilder append(boolean[] lhs, boolean[] rhs)
Deep comparison of array of boolean.
From source file:com.google.code.simplestuff.bean.SimpleBean.java
/** * Compare two bean basing the comparison only on the {@link BusinessField} * annotated fields./* w w w. ja va2s .c om*/ * * @param firstBean First bean to compare. * @param secondBean Second bean to compare. * @return The equals result. * @throws IllegalArgumentException If one of the beans compared is not an * instance of a {@link BusinessObject} annotated class. */ public static boolean equals(Object firstBean, Object secondBean) { // null + !null = false // null + null = true if ((firstBean == null) || (secondBean == null)) { if ((firstBean == null) && (secondBean == null)) { return true; } else { return false; } } final BusinessObjectDescriptor firstBusinessObjectInfo = BusinessObjectContext .getBusinessObjectDescriptor(firstBean.getClass()); final BusinessObjectDescriptor secondBusinessObjectInfo = BusinessObjectContext .getBusinessObjectDescriptor(secondBean.getClass()); // We don't need here a not null check since by contract the // getBusinessObjectDescriptor method always returns an abject. // All this conditions are to support the case in which // SimpleBean.equals is used in not Business Object. Than the rules are: // !BO.equals(!BO) = The objects are equals if one of them is assignable // to the other (the or is used for the respect the symmetric rule) // !BO.eqauls(BO) = The equals of the !BO is used. // BO.equals(!BO) = The equals of the !BO is used. if (firstBusinessObjectInfo.getNearestBusinessObjectClass() == null) { if (secondBusinessObjectInfo.getNearestBusinessObjectClass() == null) { return firstBean.getClass().isAssignableFrom(secondBean.getClass()) || secondBean.getClass().isAssignableFrom(firstBean.getClass()); } else { return firstBean.equals(secondBean); } } else if (secondBusinessObjectInfo.getNearestBusinessObjectClass() == null) { return secondBean.equals(firstBean); } // TODO: Revise this code in order to make it more readable... // If one of the two bean has the class with Business relevance then // we need to compare the lowest hierarchical annotated classes of // the two beans. if ((firstBusinessObjectInfo.isClassToBeConsideredInComparison() || secondBusinessObjectInfo.isClassToBeConsideredInComparison()) && (!firstBusinessObjectInfo.getNearestBusinessObjectClass() .equals(secondBusinessObjectInfo.getNearestBusinessObjectClass()))) { // If the comparison fails than we can already return false. return false; } // Then we continue with the annotated fields, first checking // if the two objects contain the same annotated fields. A paranoid // comparison (both sides) is done only if the two objects are not on // the same class in order to handle tricky cases. final boolean performParanoidComparison = false; if (!compareAnnotatedFieldsByName(firstBusinessObjectInfo.getAnnotatedFields(), secondBusinessObjectInfo.getAnnotatedFields(), performParanoidComparison)) { // If the comparison fails than we can already return false. return false; } // Then we continue with the values of the annotated fields. Collection<Field> firstBeanAnnotatedFields = firstBusinessObjectInfo.getAnnotatedFields(); for (Field field : firstBeanAnnotatedFields) { final BusinessField fieldAnnotation = field.getAnnotation(BusinessField.class); // Since the cycle is on the annotated Field we are sure that // fieldAnnotation will always be not null. if (fieldAnnotation.includeInEquals()) { Object firstBeanFieldValue = null; Object secondBeanFieldValue = null; try { firstBeanFieldValue = PropertyUtils.getProperty(firstBean, field.getName()); // Also in this case, since before of the cycle we // compare the annotated fields, we can be sure that the // field exists. secondBeanFieldValue = PropertyUtils.getProperty(secondBean, field.getName()); // If there were problems (like when we compare // different Business Object with different Business // Fields), then we return false. } catch (IllegalAccessException e) { if (log.isDebugEnabled()) { log.debug("IllegalAccessException exception when comparing class " + firstBean.getClass().toString() + " with class" + secondBean.getClass().toString(), e); } return false; } catch (InvocationTargetException e) { if (log.isDebugEnabled()) { log.debug("InvocationTargetException exceptionwhen comparing class " + firstBean.getClass().toString() + " with class" + secondBean.getClass().toString(), e); } return false; } catch (NoSuchMethodException e) { if (log.isDebugEnabled()) { log.debug("NoSuchMethodException exception when comparing class " + firstBean.getClass().toString() + " with class" + secondBean.getClass().toString(), e); } return false; } // Some date implementations give not exact // comparison... if ((ClassUtils.isAssignable(field.getType(), Date.class)) || (ClassUtils.isAssignable(field.getType(), Calendar.class))) { if (firstBeanFieldValue != null) { firstBeanFieldValue = DateUtils.round(firstBeanFieldValue, Calendar.MILLISECOND); } if (secondBeanFieldValue != null) { secondBeanFieldValue = DateUtils.round(secondBeanFieldValue, Calendar.MILLISECOND); } } // We use always EqualsBuilder since we can get also // primitive arrays and they need ot be internally // compared. EqualsBuilder equalsBuilder = new EqualsBuilder(); equalsBuilder.append(firstBeanFieldValue, secondBeanFieldValue); if (!equalsBuilder.isEquals()) { return false; } else { // If we are here the bean are both not null and // equals or both null (then equals)... the cycle // can // continue... continue; } } } // If we finally arrive here, then all the comparison were // successful and the two beans are equals. return true; }
From source file:edu.illinois.my.wiki.services.streaming.data.FailureOption.java
@Override protected void buildEquals(FailureOption<T> rhs, EqualsBuilder equalsBuilder) { equalsBuilder.append(exception, rhs.exception); }
From source file:edu.illinois.my.wiki.services.streaming.data.SuccessOption.java
@Override protected void buildEquals(SuccessOption<T> rhs, EqualsBuilder equalsBuilder) { equalsBuilder.append(object, rhs.object); }
From source file:com.alibaba.cobar.manager.util.Tuple.java
@Override public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof Tuple)) return false; Tuple that = (Tuple) obj;//from w w w . j av a 2 s. c o m EqualsBuilder builder = new EqualsBuilder(); builder.append(this.objects, that.objects); return builder.isEquals(); }
From source file:com.ms.commons.test.common.dbencoding.DbField.java
@Override public boolean equals(Object obj) { if (obj == null) { return false; }//from w w w.ja v a 2s. c o m if (obj.getClass() != this.getClass()) { return false; } DbField another = (DbField) obj; EqualsBuilder eb = new EqualsBuilder(); eb.append(this.table, another.table); eb.append(this.field, another.field); return eb.isEquals(); }
From source file:com.vladmihalcea.hibernate.model.store.Company.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }//from ww w. ja v a 2 s. co m if (!(obj instanceof Company)) { return false; } Company that = (Company) obj; EqualsBuilder eb = new EqualsBuilder(); eb.append(name, that.name); return eb.isEquals(); }
From source file:edu.illinois.my.wiki.services.parameters.ImmutableMapParameters.java
@Override protected void buildEquals(ImmutableMapParameters rhs, EqualsBuilder equalsBuilder) { equalsBuilder.append(parameters, rhs.parameters); }
From source file:com.vladmihalcea.hibernate.model.store.Importer.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }//from w w w . ja v a 2 s.co m if (!(obj instanceof Importer)) { return false; } Importer that = (Importer) obj; EqualsBuilder eb = new EqualsBuilder(); eb.append(name, that.getName()); return eb.isEquals(); }
From source file:edu.illinois.my.wiki.services.WikiLocationImpl.java
@Override protected void buildEquals(WikiLocationImpl rhs, EqualsBuilder builder) { builder.append(title, rhs.title); builder.append(urlPath, rhs.urlPath); builder.append(lastModificationDate, rhs.lastModificationDate); builder.append(lastModifier, rhs.lastModifier); }
From source file:com.cognifide.slice.core.internal.context.CacheableContextKey.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }/* w w w . j av a 2 s .co m*/ if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } CacheableContextKey other = (CacheableContextKey) obj; EqualsBuilder equalsBuilder = new EqualsBuilder(); equalsBuilder.append(path, other.path); equalsBuilder.append(type, other.type); return equalsBuilder.isEquals(); }