org.apache.commons.lang.builder.CompareToBuilder Java Examples

The following examples show how to use org.apache.commons.lang.builder.CompareToBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AncestorQueryIterator.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
    if (cf.getLength() == 0) {
        return new CompareToBuilder().append(o1, o2).toComparison();
    } else {
        boolean o1Matches = (o1 instanceof ValueTuple && (((ValueTuple) o1).getSource().getMetadata().getColumnFamily().equals(cf)));
        boolean o2Matches = (o2 instanceof ValueTuple && (((ValueTuple) o2).getSource().getMetadata().getColumnFamily().equals(cf)));
        if (o1Matches == o2Matches) {
            return new CompareToBuilder().append(o1, o2).toComparison();
        } else if (o1Matches) {
            return -1;
        } else {
            return 1;
        }
    }
}
 
Example #2
Source File: ValueTuple.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(ValueTuple o) {
    CompareToBuilder builder = new CompareToBuilder().append(first(), o.first());
    
    // for the values, lets compare the string variants as the actual values could be of differing types
    builder.append(stringOf(second()), stringOf(o.second())).append(stringOf(third()), stringOf(o.third()));
    
    // for the source, we cannot append(getSource, o.getSource()) because they may be different attribute types
    // and as a result the underlying compareTo method will throw an exception.
    if (getSource() == null || o.getSource() == null) {
        // safe in this case because one of them is null
        builder.append(getSource(), o.getSource());
    } else {
        // otherwise
        builder.append(getSource().getMetadata(), o.getSource().getMetadata()).append(stringOf(getSource().getData()), stringOf(o.getSource().getData()));
    }
    return builder.toComparison();
}
 
Example #3
Source File: QueryIterator.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
    if (fi.getLength() == 0) {
        return new CompareToBuilder().append(o1, o2).toComparison();
    } else {
        boolean o1Matches = (o1 instanceof ValueTuple && (((ValueTuple) o1).first().indexOf('.') != -1));
        boolean o2Matches = (o2 instanceof ValueTuple && (((ValueTuple) o2).first().indexOf('.') != -1));
        if (o1Matches == o2Matches) {
            return new CompareToBuilder().append(o1, o2).toComparison();
        } else if (o1Matches) {
            return -1;
        } else {
            return 1;
        }
    }
}
 
Example #4
Source File: HashUID.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(final UID uid) {
    int result;
    if (uid instanceof HashUID) {
        final HashUID o = (HashUID) uid;
        final CompareToBuilder compare = new CompareToBuilder();
        compare.append(this.optionalPrefix, o.optionalPrefix);
        compare.append(this.h1, o.h1);
        compare.append(this.h2, o.h2);
        compare.append(this.time, o.time);
        compare.append(this.extra, o.extra);
        result = compare.toComparison();
    } else if (null != uid) {
        result = toString().compareTo(uid.toString());
    } else {
        result = -1;
    }
    
    return result;
}
 
Example #5
Source File: SnowflakeUID.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(final UID uid) {
    int result;
    if (uid instanceof SnowflakeUID) {
        final SnowflakeUID o = (SnowflakeUID) uid;
        final CompareToBuilder compare = new CompareToBuilder();
        if (null == this.snowflake) {
            compare.append(TOO_BIG_BIGINT, o.snowflake);
        } else if (null == o.snowflake) {
            compare.append(this.snowflake, TOO_BIG_BIGINT);
        } else {
            compare.append(this.snowflake, o.snowflake);
        }
        compare.append(this.extra, o.extra);
        result = compare.toComparison();
    } else if (null != uid) {
        result = toString().compareTo(uid.toString());
    } else {
        result = -1;
    }
    
    return result;
}
 
Example #6
Source File: QualifiedPathKey.java    From hraven with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(Object other) {
  if (other == null) {
    return -1;
  }
  QualifiedPathKey otherKey = (QualifiedPathKey) other;
  if (StringUtils.isNotBlank(this.namespace)) {
    return new CompareToBuilder()
        .append(this.cluster, otherKey.getCluster())
        .append(getPath(), otherKey.getPath())
        .append(this.namespace, otherKey.getNamespace())
        .toComparison();
  } else {
    return new CompareToBuilder()
      .append(this.cluster, otherKey.getCluster())
      .append(getPath(), otherKey.getPath())
      .toComparison();
  }
}
 
Example #7
Source File: RyaStatementWritable.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Comparison method for natural ordering. Compares based on the logical
 * triple (the s/p/o/context information in the underlying RyaStatement)
 * and then by the metadata contained in the RyaStatement if the triples are
 * the same.
 * @return  Zero if both RyaStatementWritables contain equivalent statements
 *          or both have null statements; otherwise, an integer whose sign
 *          corresponds to a consistent ordering.
 */
@Override
public int compareTo(RyaStatementWritable other) {
    CompareToBuilder builder = new CompareToBuilder();
    RyaStatement rsThis = this.getRyaStatement();
    RyaStatement rsOther = other.getRyaStatement(); // should throw NPE if other is null, as per Comparable contract
    builder.append(rsThis == null, rsOther == null);
    if (rsThis != null && rsOther != null) {
        builder.append(rsThis.getSubject(), rsOther.getSubject());
        builder.append(rsThis.getPredicate(), rsOther.getPredicate());
        builder.append(rsThis.getObject(), rsOther.getObject());
        builder.append(rsThis.getContext(), rsOther.getContext());
        builder.append(rsThis.getQualifer(), rsOther.getQualifer());
        builder.append(rsThis.getColumnVisibility(), rsOther.getColumnVisibility());
        builder.append(rsThis.getValue(), rsOther.getValue());
        builder.append(rsThis.getTimestamp(), rsOther.getTimestamp());
    }
    return builder.toComparison();
}
 
Example #8
Source File: Tag.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Tag tag) {
	return new CompareToBuilder()
			.append(getName(), tag.getName())
			.append(getId(), tag.getId())
			.toComparison();
}
 
Example #9
Source File: ConcreteKeyValue.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public int compareTo(KeyValue o) {
	if (o == null) {
		throw new NullPointerException("o is null");
	}

	return new CompareToBuilder()
		.append(this.getValue(), o.getValue(), String.CASE_INSENSITIVE_ORDER)
		.append(this.getKey(), o.getKey(), String.CASE_INSENSITIVE_ORDER)
		.toComparison();
}
 
Example #10
Source File: PopularPost.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(PopularPost o) {
	return new CompareToBuilder()
			.append(getLanguage(), o.getLanguage())
			.append(getType(), o.getType())
			.append(getRank(), o.getRank())
			.append(getId(), o.getId())
			.toComparison();
}
 
Example #11
Source File: GroupedRow.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Natural ordering; compares based on group and then key.
 */
@Override
public int compareTo(final GroupedRow o) {
    if (o == null) {
        return 1;
    }
    return new CompareToBuilder().append(group, o.group).append(key, o.key).append(value, o.value).toComparison();
}
 
Example #12
Source File: RyaType.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Define a natural ordering based on data, datatype, and language.
 * @param o The object to compare with
 * @return 0 if the data string, the datatype string, and the language
 * string representation match between the objects, where matching is
 * defined by string comparison or all being null;
 * Otherwise, an integer whose sign yields a consistent ordering.
 */
@Override
public int compareTo(final RyaType o) {
    if (o == null) {
        return 1;
    }
    final String dataTypeStr = getDataType() != null ? getDataType().stringValue() : null;
    final String otherDataTypeStr = o.getDataType() != null ? o.getDataType().stringValue() : null;
    final CompareToBuilder builder = new CompareToBuilder()
            .append(getData(), o.getData())
            .append(dataTypeStr, otherDataTypeStr)
            .append(getLanguage(), o.getLanguage());
    return builder.toComparison();
}
 
Example #13
Source File: ValueRange.java    From training with MIT License 5 votes vote down vote up
@Override
public int compareTo(ValueRange<V> obj) {
	if (obj == this) {
		return 0;
	} else {
		return new CompareToBuilder().append(this.getMin(), obj.getMin()).append(this.getMax(), obj.getMax()).toComparison();
	}
}
 
Example #14
Source File: ValidationResult.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compare ValidationResults so they will be listed in the desired
 * order: by validationRule, period, attributeOptionCombo and orgUnit.
 *
 * @param other The other ValidationResult to compare with.
 * @return a negative integer, zero, or a positive integer as this object
 *         is less than, equal to, or greater than the specified object.
 */
@Override
public int compareTo( ValidationResult other )
{
    return new CompareToBuilder()
        .append( this.validationRule, other.getValidationRule() )
        .append( this.period, other.getPeriod() )
        .append( this.attributeOptionCombo, other.getAttributeOptionCombo() )
        .append( this.organisationUnit, other.getOrganisationUnit() )
        .append( this.id, other.getId() )
        .toComparison();
}
 
Example #15
Source File: MavenArtifact.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Override
public int compareTo(MavenArtifact o) {
    return new CompareToBuilder().
            append(this.getGroupId(), o.getGroupId()).
            append(this.getArtifactId(), o.getArtifactId()).
            append(this.getBaseVersion(), o.getBaseVersion()).
            append(this.getVersion(), o.getVersion()).
            append(this.getType(), o.getType()).
            append(this.getClassifier(), o.getClassifier()).
            toComparison();
}
 
Example #16
Source File: Step.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Step other) {
  // Sort steps by file and then sequentially within the file to achieve the
  // desired order.  There is no concurrent map structure in the JDK that
  // maintains insertion order, so instead we attach a sequence number to each
  // step and sort on read.
  return new CompareToBuilder().append(file, other.file)
    .append(sequenceNumber, other.sequenceNumber).toComparison();
}
 
Example #17
Source File: TaggedMetric.java    From timely with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(TaggedMetric o) {
    CompareToBuilder ctb = new CompareToBuilder();
    ctb.append(this.columnVisibility, o.columnVisibility);
    ctb.append(this.orderedTags, o.orderedTags);
    return ctb.toComparison();
}
 
Example #18
Source File: GenomicOrderComparator.java    From Drop-seq with MIT License 5 votes vote down vote up
public int compare(GTFRecord g1, GTFRecord g2) {
	int i1 = refDict.getSequenceIndex(g1.getChromosome());
	int i2 = refDict.getSequenceIndex(g2.getChromosome());
	return new CompareToBuilder().append(i1, i2)
			.append(g1.getStart(), g2.getStart())
			.append(g1.getEnd(), g2.getEnd())
               .append(g1.getTranscriptType(), g2.getTranscriptType())
			.toComparison();
}
 
Example #19
Source File: CustomField.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(CustomField field) {
	return new CompareToBuilder()
			.append(getIdx(), field.getIdx())
			.append(getId(), field.getId())
			.toComparison();
}
 
Example #20
Source File: VendorGroupingHelper.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see java.lang.Comparable#compareTo(Object)
 */
public int compareTo(Object object) {
	VendorGroupingHelper myClass = (VendorGroupingHelper)object;
	return new CompareToBuilder().append( this.vendorPostalCode, myClass.vendorPostalCode )
			.append( this.vendorHeaderGeneratedIdentifier,
					myClass.vendorHeaderGeneratedIdentifier )
			.append( this.vendorDetailAssignedIdentifier,
					myClass.vendorDetailAssignedIdentifier ).append( this.vendorCountry,
					myClass.vendorCountry ).toComparison();
}
 
Example #21
Source File: ComponentServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Calculates the checksum for the list of components.  The list of components should be sorted in a
 * consistent way prior to generation of the checksum to ensure that the checksum value comes out the same regardless
 * of the ordering of components contained therein.  The checksum allows us to easily determine if the component set
 * has been updated or not.
 */
protected String calculateChecksum(List<Component> components) {
    Collections.sort(components, new Comparator<Component>() {
        @Override
        public int compare(Component component1, Component component2) {
            return CompareToBuilder.reflectionCompare(component1, component2);
        }
    });
    return ChecksumUtils.calculateChecksum(components);
}
 
Example #22
Source File: JavaTerm.java    From Siamese with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(JavaTerm o) {
    JavaTerm jt = (JavaTerm) o;
    return new CompareToBuilder()
            .append(this.getFreq(), jt.getFreq())
            .toComparison();
}
 
Example #23
Source File: StateChange.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int compareTo(StateChange rhs) {
    CompareToBuilder builder = new CompareToBuilder();
    builder.append(getDate(), rhs.getDate());
    builder.append(getId(), rhs.getId());
    builder.append(this.getState(), rhs.getState());
    builder.append(this.getUser(), rhs.getUser());
    builder.append(this.getChangedBy(), rhs.getChangedBy());
    return builder.toComparison();
}
 
Example #24
Source File: HdfsStatsKey.java    From hraven with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Object other) {
  if (other == null) {
    return -1;
  }
  HdfsStatsKey otherKey = (HdfsStatsKey) other;
  return new CompareToBuilder()
      .append(this.pathKey, otherKey.getQualifiedPathKey())
      .append(this.encodedRunId, otherKey.getEncodedRunId())
      .toComparison();
}
 
Example #25
Source File: TaskKey.java    From hraven with Apache License 2.0 5 votes vote down vote up
/**
 * Compares two TaskKey objects on the basis of their taskId
 *
 * @param other
 * @return 0 if the taskIds are equal,
 * 		 1 if this taskId is greater than other taskId,
 * 		-1 if this taskId is less than other taskId
 */
@Override
public int compareTo(Object other) {
  if (other == null) {
    return -1;
  }
  TaskKey otherKey = (TaskKey) other;
  return new CompareToBuilder().appendSuper(super.compareTo(otherKey))
      .append(this.taskId, otherKey.getTaskId())
      .toComparison();
}
 
Example #26
Source File: HdfsStats.java    From hraven with Apache License 2.0 5 votes vote down vote up
public int compareTo(HdfsStats other) {
  if (other == null) {
    return -1;
  }
  return new CompareToBuilder()
      .append(this.hdfsStatsKey, other.getHdfsStatsKey())
      .toComparison();
}
 
Example #27
Source File: TaskDetails.java    From hraven with Apache License 2.0 5 votes vote down vote up
/**
 * Compares two TaskDetails objects on the basis of their TaskKey
 *
 * @param other
 * @return 0 if this TaskKey is equal to the other TaskKey,
 * 		 1 if this TaskKey greater than other TaskKey,
 * 		-1 if this TaskKey is less than other TaskKey
 *
 */
@Override
public int compareTo(TaskDetails otherTask) {
  if (otherTask == null) {
    return -1;
  }

  return new CompareToBuilder().append(this.taskKey, otherTask.getTaskKey())
      .toComparison();
}
 
Example #28
Source File: AppKey.java    From hraven with Apache License 2.0 5 votes vote down vote up
/**
 * Compares two AppKey objects on the basis of their cluster, userName, appId and encodedRunId
 * @param other
 * @return 0 if this cluster, userName, appId are equal to the other's
 *                   cluster, userName, appId,
 *         1 if this cluster or userName or appId are less than the other's
 *                   cluster, userName, appId,
 *        -1 if this cluster and userName and appId are greater the other's
 *                   cluster, userName, appId
 */
@Override
public int compareTo(Object other) {
  if (other == null) {
    return -1;
  }
  AppKey otherKey = (AppKey) other;
  return new CompareToBuilder()
      .append(this.cluster, otherKey.getCluster())
      .append(this.userName, otherKey.getUserName())
      .append(this.appId, otherKey.getAppId())
      .toComparison();
}
 
Example #29
Source File: JobKey.java    From hraven with Apache License 2.0 5 votes vote down vote up
/**
 * Compares two JobKey QualifiedJobId
 *
 * @param other
 * @return 0 if the Qualified Job Ids are equal,
 * 		 1 if this QualifiedJobId greater than other QualifiedJobId,
 * 		-1 if this QualifiedJobId is less than other QualifiedJobId
 */
@Override
public int compareTo(Object other) {
  if (other == null) {
    return -1;
  }
  JobKey otherKey = (JobKey)other;
  return new CompareToBuilder().appendSuper(super.compareTo(otherKey))
      .append(this.jobId, otherKey.getJobId())
      .toComparison();
}
 
Example #30
Source File: AbstractTaggerTest.java    From SolrTextTagger with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Object o) {
  TestTag that = (TestTag) o;
  return new CompareToBuilder()
      .append(this.startOffset, that.startOffset)
      .append(this.endOffset, that.endOffset)
      .append(this.docName,that.docName)
      .toComparison();
}