List of usage examples for org.apache.commons.lang3.builder EqualsBuilder append
public EqualsBuilder append(final boolean[] lhs, final boolean[] rhs)
Deep comparison of array of boolean
.
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalService.java
/** * Utility method to factor out logic between {@link #equals(Object)} and {@link #equalsShallow(LogicalService)} * @param obj The other object to compare * @param excludeAssociations set to true to exclude the {@link #logicalNodeServiceAssociations} in the comparison * or false to include them. * @return//from w w w . j av a2 s .c o m */ protected boolean equals(Object obj, boolean excludeAssociations) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj.getClass() != getClass()) { return false; } LogicalService rhs = (LogicalService) obj; EqualsBuilder equalsBuilder = new EqualsBuilder().appendSuper(super.equals(obj, EqualsUtils .mergeExcludedFieldLists(EXCLUDED_EQUALS_FIELDS, EXCLUDED_HIBERNATE_BROKEN_EQUALS_COLLECTIONS))); if (!excludeAssociations) { List<LogicalNodeServiceAssociation> thisLogicalNodeServiceAssociations = new ArrayList<LogicalNodeServiceAssociation>( logicalNodeServiceAssociations); Collections.sort(thisLogicalNodeServiceAssociations); List<LogicalNodeServiceAssociation> rhsLogicalNodeServiceAssociations = new ArrayList<LogicalNodeServiceAssociation>( rhs.logicalNodeServiceAssociations); Collections.sort(rhsLogicalNodeServiceAssociations); equalsBuilder.append(thisLogicalNodeServiceAssociations, rhsLogicalNodeServiceAssociations); } return equalsBuilder.isEquals(); }
From source file:annis.model.DataObject.java
@Override public boolean equals(final Object obj) { // enforce equals contract (turn on debugging for this class to see the bug) if (obj == null) return false; if (this.getClass() != obj.getClass()) return false; final EqualsBuilder equalsBuilder = new EqualsBuilder(); final Object _this = this; forEachFieldDo(new FieldCallBack() { public void doForField(Field field) throws IllegalAccessException { Object thisValue = field.get(_this); Object otherValue = field.get(obj); if (log.isDebugEnabled()) { String fieldName = field.getDeclaringClass().getSimpleName() + "." + field.getName(); try { boolean equal = thisValue != null && thisValue.equals(otherValue) || thisValue == null && otherValue == null; log.debug(fieldName + ": " + thisValue + " " + (equal ? "=" : "!=") + " " + otherValue); } catch (RuntimeException e) { log.error("Exception while comparing " + fieldName + "(" + thisValue + ", " + otherValue + ")"); throw e; }//from w w w .j av a 2s. c o m } equalsBuilder.append(thisValue, otherValue); } }); return equalsBuilder.isEquals(); }
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalDeployment.java
@Override public boolean equals(Object obj) { //Note: Hibernate implementation of List (PersistentBag) breaks List.equals() contract. //http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/collection/PersistentBag.html#equals%28java.lang.Object%29 //Therefore, we have to wrap the hibernate collection into a standard one which properly //respect the equals() by comparing elements within it. //In terms of performance impact, this should be quite limited because PersistentBag is backed //by an ArrayList, and therefore this should merely translate into an array copy + one ArrayList //wrapper object creation. if (obj == null) { return false; }// www.j a v a 2s. co m if (obj == this) { return true; } if (obj.getClass() != getClass()) { return false; } LogicalDeployment rhs = (LogicalDeployment) obj; //In addition, we can't simply delegate equals() to super class, otherwise it will pick up the collections //from LogicalDeployment "this" instance using reflection. Therefore we explicitly request to exclude it in //the first equals() call. This will however, take EqualsBuilder equalsBuilder = new EqualsBuilder() .appendSuper(super.equals(obj, EXCLUDED_HIBERNATE_BROKEN_EQUALS_COLLECTIONS)); //Then we manually compare the collections by wrapping them. // We need to sort it first (based on labels + class names) List<ProcessingNode> thisProcessingNodes = new ArrayList<ProcessingNode>(processingNodes); Collections.sort(thisProcessingNodes); List<LogicalService> thisLogicalServices = new ArrayList<LogicalService>(logicalServices); Collections.sort(thisLogicalServices); List<ProcessingNode> rhsProcessingNodes = new ArrayList<ProcessingNode>(rhs.processingNodes); Collections.sort(rhsProcessingNodes); List<LogicalService> rhsLogicalServices = new ArrayList<LogicalService>(rhs.logicalServices); Collections.sort(rhsLogicalServices); boolean equals = equalsBuilder.append(thisProcessingNodes, rhsProcessingNodes) .append(thisLogicalServices, rhsLogicalServices).isEquals(); return equals; }
From source file:net.sourceforge.seqware.pipeline.plugins.BatchMetadataInjectionTest.java
/** * Compares all values in the json to make sure that they are equal * * @param original/*www . ja v a 2s . com*/ * @param actual * @return If the jsons match or not */ private boolean equals(RunInfo original, RunInfo actual, String jsonName) throws IOException { ObjectMapper mapper = new ObjectMapper(); original = mapper.readValue(new File(jsonName), RunInfo.class); EqualsBuilder equal = new EqualsBuilder(); //Study stuff equal.append(original.getStudyTitle(), actual.getStudyTitle()); equal.append(original.getStudyDescription(), actual.getStudyDescription()); equal.append(original.getStudyCenterName(), actual.getStudyCenterName()); equal.append(original.getStudyCenterProject(), actual.getStudyCenterProject()); //Sequencer stuff equal.append(original.getRunName(), actual.getRunName()); equal.append(original.getRunSkip(), actual.getRunSkip()); equal.append(original.getRunDescription(), actual.getRunDescription()); List<TagValueUnit> originalRunAttributes = new ArrayList<TagValueUnit>(original.getRunAttributes()); List<TagValueUnit> actualRunAttributes = new ArrayList<TagValueUnit>(actual.getRunAttributes()); Collections.sort(originalRunAttributes); Collections.sort(actualRunAttributes); Iterator<TagValueUnit> iterRunAttrOrig = originalRunAttributes.iterator(); Iterator<TagValueUnit> iterRunAttrAct = actualRunAttributes.iterator(); while (iterRunAttrAct.hasNext() && iterRunAttrOrig.hasNext()) { TagValueUnit unitOrig = iterRunAttrOrig.next(); TagValueUnit unitAct = iterRunAttrAct.next(); equal.append(unitAct.getTag(), unitOrig.getTag()); equal.append(unitAct.getValue(), unitOrig.getValue()); } //Experiment stuff equal.append(original.getExperimentDescription(), actual.getExperimentDescription()); equal.append(original.getExperimentName(), actual.getExperimentName()); List<TagValueUnit> originalExperimentAttributes = new ArrayList<TagValueUnit>( original.getExperimentAttributes()); List<TagValueUnit> actualExperimentAttributes = new ArrayList<TagValueUnit>( actual.getExperimentAttributes()); Collections.sort(originalExperimentAttributes); Collections.sort(actualExperimentAttributes); Iterator<TagValueUnit> iterExperimentAttrOrig = originalExperimentAttributes.iterator(); Iterator<TagValueUnit> iterExperimentAttrAct = actualExperimentAttributes.iterator(); while (iterExperimentAttrAct.hasNext() && iterExperimentAttrOrig.hasNext()) { TagValueUnit unitOrig = iterExperimentAttrAct.next(); TagValueUnit unitAct = iterExperimentAttrOrig.next(); equal.append(unitAct.getTag(), unitOrig.getTag()); equal.append(unitAct.getValue(), unitOrig.getValue()); } //Lanes List<LaneInfo> originalLanes = new ArrayList<LaneInfo>(original.getLanes()); List<LaneInfo> actualLanes = new ArrayList<LaneInfo>(actual.getLanes()); Collections.sort(originalLanes); Collections.sort(actualLanes); Iterator<LaneInfo> iterActualLane = actualLanes.iterator(); Iterator<LaneInfo> iterOriginalLane = originalLanes.iterator(); //Adds all the lane info while (iterActualLane.hasNext() && iterOriginalLane.hasNext()) { LaneInfo originalLane = iterOriginalLane.next(); LaneInfo actualLane = iterActualLane.next(); equal.append(originalLane.getLaneName(), actualLane.getLaneName()); equal.append(originalLane.getLaneNumber(), actualLane.getLaneNumber()); equal.append(originalLane.getLaneDescription(), actualLane.getLaneDescription()); equal.append(originalLane.getLaneCycleDescriptor(), actualLane.getLaneCycleDescriptor()); equal.append(originalLane.getLaneSkip(), actualLane.getLaneSkip()); equal.append(originalLane.getLibrarySelectionAcc(), actualLane.getLibrarySelectionAcc()); equal.append(originalLane.getLibrarySourceAcc(), actualLane.getLibrarySourceAcc()); equal.append(originalLane.getLibraryStrategyAcc(), actualLane.getLibraryStrategyAcc()); //Adds all the lane attributes List<TagValueUnit> originalLaneAttributes = new ArrayList<TagValueUnit>( originalLane.getLaneAttributes()); List<TagValueUnit> actualLaneAttributes = new ArrayList<TagValueUnit>(actualLane.getLaneAttributes()); Collections.sort(originalLaneAttributes); Collections.sort(actualLaneAttributes); Iterator<TagValueUnit> iterOrigLaneAttr = originalLaneAttributes.iterator(); Iterator<TagValueUnit> iterActualLaneAttr = actualLaneAttributes.iterator(); while (iterOrigLaneAttr.hasNext() && iterActualLaneAttr.hasNext()) { TagValueUnit unitOrig = iterOrigLaneAttr.next(); TagValueUnit unitActual = iterActualLaneAttr.next(); equal.append(unitOrig.getTag(), unitActual.getTag()); equal.append(unitOrig.getValue(), unitActual.getValue()); } //Now to check samples List<SampleInfo> originalSamples = new ArrayList<SampleInfo>(originalLane.getSamples()); List<SampleInfo> actualSamples = new ArrayList<SampleInfo>(actualLane.getSamples()); Collections.sort(actualSamples); Collections.sort(originalSamples); Iterator<SampleInfo> iterSampleOrig = originalSamples.iterator(); Iterator<SampleInfo> iterSampleActual = actualSamples.iterator(); while (iterSampleActual.hasNext() && iterSampleOrig.hasNext()) { SampleInfo originalSample = iterSampleOrig.next(); SampleInfo actualSample = iterSampleActual.next(); equal.append(originalSample.getProjectCode(), actualSample.getProjectCode()); equal.append(originalSample.getIndividualNumber(), actualSample.getIndividualNumber()); equal.append(originalSample.getName(), actualSample.getName()); equal.append(originalSample.getTissueType(), actualSample.getTissueType()); equal.append(originalSample.getTissueOrigin(), actualSample.getTissueOrigin()); equal.append(originalSample.getLibrarySizeCode(), actualSample.getLibrarySizeCode()); equal.append(originalSample.getLibrarySourceTemplateType(), actualSample.getLibrarySourceTemplateType()); equal.append(originalSample.getLibraryType(), actualSample.getLibraryType()); equal.append(originalSample.getParentSample(), actualSample.getParentSample()); equal.append(originalSample.getTissuePreparation(), actualSample.getTissuePreparation()); equal.append(originalSample.getTargetedResequencing(), actualSample.getTargetedResequencing()); equal.append(originalSample.getSampleDescription(), actualSample.getSampleDescription()); equal.append(originalSample.getBarcode(), actualSample.getBarcode()); equal.append(originalSample.getIusName(), actualSample.getIusName()); equal.append(originalSample.getIusDescription(), actualSample.getIusDescription()); equal.append(originalSample.getIusSkip(), actualSample.getIusSkip()); List<TagValueUnit> originalSampleAttributes = new ArrayList<TagValueUnit>( originalSample.getSampleAttributes()); List<TagValueUnit> actualSampleAttributes = new ArrayList<TagValueUnit>( actualSample.getSampleAttributes()); Collections.sort(originalSampleAttributes); Collections.sort(actualSampleAttributes); Iterator<TagValueUnit> iterOrigSampleAttr = originalSampleAttributes.iterator(); Iterator<TagValueUnit> iterActualSampleAttr = actualSampleAttributes.iterator(); while (iterOrigSampleAttr.hasNext() && iterActualSampleAttr.hasNext()) { TagValueUnit unitOrig = iterOrigSampleAttr.next(); TagValueUnit unitActual = iterActualSampleAttr.next(); equal.append(unitOrig.getTag(), unitActual.getTag()); equal.append(unitOrig.getValue(), unitActual.getValue()); } List<TagValueUnit> originalIUSAttributes = new ArrayList<TagValueUnit>( originalSample.getIusAttributes()); List<TagValueUnit> actualIUSAttributes = new ArrayList<TagValueUnit>( originalSample.getIusAttributes()); Collections.sort(originalIUSAttributes); Collections.sort(actualIUSAttributes); Iterator<TagValueUnit> iterOrigIUSAttr = originalIUSAttributes.iterator(); Iterator<TagValueUnit> iterActualIUSIterator = actualIUSAttributes.iterator(); while (iterOrigIUSAttr.hasNext() && iterActualIUSIterator.hasNext()) { TagValueUnit unitOrig = iterOrigSampleAttr.next(); TagValueUnit unitActual = iterActualSampleAttr.next(); equal.append(unitOrig.getTag(), unitActual.getTag()); equal.append(unitOrig.getValue(), unitActual.getValue()); } } } return equal.isEquals(); }
From source file:org.bgp4j.net.attributes.CommunityPathAttribute.java
@Override protected boolean subclassEquals(PathAttribute obj) { CommunityPathAttribute o = (CommunityPathAttribute) obj; EqualsBuilder builder = (new EqualsBuilder()).append(getCommunity(), o.getCommunity()) .append(getMembers().size(), o.getMembers().size()); if (builder.isEquals()) { Iterator<CommunityMember> lit = getMembers().iterator(); Iterator<CommunityMember> rit = o.getMembers().iterator(); while (lit.hasNext()) builder.append(lit.next(), rit.next()); }/* w w w . ja va2 s . co m*/ return builder.isEquals(); }
From source file:org.bgp4j.net.attributes.MultiProtocolReachableNLRI.java
@Override protected boolean subclassEquals(PathAttribute obj) { MultiProtocolReachableNLRI o = (MultiProtocolReachableNLRI) obj; EqualsBuilder builer = (new EqualsBuilder()).append(getAddressFamily(), o.getAddressFamily()) .append(getSubsequentAddressFamily(), o.getSubsequentAddressFamily()) .append(getNextHop(), o.getNextHop()).append(getNlris().size(), o.getNlris().size()); if (builer.isEquals()) { Iterator<NetworkLayerReachabilityInformation> lit = getNlris().iterator(); Iterator<NetworkLayerReachabilityInformation> rit = o.getNlris().iterator(); while (lit.hasNext()) builer.append(lit.next(), rit.next()); }/* ww w .j a v a 2s.com*/ return builer.isEquals(); }
From source file:org.bgp4j.net.attributes.MultiProtocolUnreachableNLRI.java
@Override protected boolean subclassEquals(PathAttribute obj) { MultiProtocolUnreachableNLRI o = (MultiProtocolUnreachableNLRI) obj; EqualsBuilder builer = (new EqualsBuilder()).append(getAddressFamily(), o.getAddressFamily()) .append(getSubsequentAddressFamily(), o.getSubsequentAddressFamily()) .append(getNlris().size(), o.getNlris().size()); if (builer.isEquals()) { Iterator<NetworkLayerReachabilityInformation> lit = getNlris().iterator(); Iterator<NetworkLayerReachabilityInformation> rit = o.getNlris().iterator(); while (lit.hasNext()) builer.append(lit.next(), rit.next()); }//from w w w. j a v a 2s .c o m return builer.isEquals(); }
From source file:org.bgp4j.net.attributes.PathAttribute.java
@Override public boolean equals(Object obj) { if (!(obj instanceof PathAttribute)) return false; PathAttribute o = (PathAttribute) obj; EqualsBuilder builder = new EqualsBuilder(); builder.append(internalType(), o.internalType()).append(getCategory(), o.getCategory()) .append(isOptional(), o.isOptional()).append(isPartial(), o.isPartial()) .append(isTransitive(), o.isTransitive()); if (internalType() == o.internalType()) builder.appendSuper(subclassEquals(o)); return builder.isEquals(); }
From source file:org.bonitasoft.engine.bdm.model.field.RelationField.java
@Override public boolean equals(final Object obj) { if (obj instanceof RelationField) { final RelationField other = (RelationField) obj; if (reference == null ^ other.reference == null) { return false; }/*from www . jav a2 s . c o m*/ EqualsBuilder builder = new EqualsBuilder().appendSuper(super.equals(obj)).append(type, other.type); if (reference != null && other.reference != null) { builder = builder.append(reference.getQualifiedName(), other.reference.getQualifiedName()); } return builder.isEquals(); } return false; }
From source file:org.grouplens.grapht.Component.java
@Override public boolean equals(Object o) { if (!(o instanceof Component)) { return false; }//from w w w . j av a2s . c o m Component c = (Component) o; EqualsBuilder eqb = new EqualsBuilder(); return eqb.append(satisfaction, c.satisfaction).append(cachePolicy, c.cachePolicy).isEquals(); }