Java Code Examples for org.apache.commons.lang.builder.CompareToBuilder#append()

The following examples show how to use org.apache.commons.lang.builder.CompareToBuilder#append() . 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: 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 2
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 3
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 4
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 5
Source File: DiscoveredThing.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(DiscoveredThing o) {
    CompareToBuilder cmp = new CompareToBuilder();
    if (o == null) {
        return 1;
    } else {
        cmp.append(getTerm(), o.getTerm());
        cmp.append(getField(), o.getField());
        cmp.append(getType(), o.getType());
        cmp.append(getDate(), o.getDate());
        cmp.append(getColumnVisibility(), o.getColumnVisibility());
        cmp.append(getCount(), o.getCount());
        return cmp.toComparison();
    }
}
 
Example 6
Source File: DateFieldValueCardinalityRecord.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Object o) {
    if (o instanceof DateFieldValueCardinalityRecord) {
        DateFieldValueCardinalityRecord other = (DateFieldValueCardinalityRecord) o;
        CompareToBuilder builder = new CompareToBuilder();
        builder.append(this.eventDate, other.eventDate);
        builder.append(this.dataType, other.dataType);
        builder.append(this.fieldName, other.fieldName);
        builder.append(this.fieldValue, other.fieldValue);
        return builder.toComparison();
    } else {
        throw new UnsupportedOperationException("Object " + o + " is not instanceof " + DateFieldValueCardinalityRecord.class.getCanonicalName());
    }
}
 
Example 7
Source File: CardinalityScanner.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Object obj) {
    CardinalityIntersectionRecord other = null;
    if (obj instanceof CardinalityIntersectionRecord) {
        other = (CardinalityIntersectionRecord) obj;
    } else {
        throw new IllegalArgumentException(obj + " is not a CardinalityIntersection");
    }
    CompareToBuilder builder = new CompareToBuilder();
    builder.append(this.date, other.date);
    builder.append(this.datatype, other.datatype);
    builder.append(this.tuple, other.tuple);
    return builder.toComparison();
}
 
Example 8
Source File: Connection.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Connection c) {
    CompareToBuilder b = new CompareToBuilder();
    b.append(this.state, c.state);
    b.append(c.timeInState, this.timeInState);
    return b.toComparison();
}
 
Example 9
Source File: TimeLocationValueTriple.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(TimeValuePair o) {
    CompareToBuilder compareToBuilder = new CompareToBuilder().appendSuper(super.compareTo(o));
    if (o instanceof TimeLocationValueTriple) {
        compareToBuilder.append(this.getLocation(), ((TimeLocationValueTriple) o).getLocation());
    }
    return compareToBuilder.toComparison();
}
 
Example 10
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 11
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 12
Source File: QueryMetricsWriter.java    From datawave with Apache License 2.0 4 votes vote down vote up
private void handleLegacyEvents(BaseQueryMetric queryMetric) {
    long lastUpdated;
    List<PageMetric> pages = queryMetric.getPageTimes();
    if (pages != null && !pages.isEmpty()) {
        // only old events should lack page numbers
        if (pages.get(0).getPageNumber() == -1) {
            
            Comparator<PageMetric> c = (m1, m2) -> {
                CompareToBuilder builder = new CompareToBuilder();
                builder.append(m1.getPageRequested(), m2.getPageRequested());
                builder.append(m1.getPageReturned(), m2.getPageReturned());
                return builder.toComparison();
            };
            
            // Sort by pageRequested and pageReturned
            Collections.sort(pages, c);
            
            // lastUpdated used to be set in the ShardTableQueryMetricHandler
            // Now it is done in the QueryMetricsBean.
            // If this message was stuck on the queue, then lastUpdated will not have been set yet.
            lastUpdated = pages.get(pages.size() - 1).getPageReturned();
            
            // if an older message is pulled off of the queue that does not have page numbers assigned,
            // then sort by pageRequested time and assign page numbers
            long x = 0;
            Long lastPage = lastPageMap.get(queryMetric.getQueryId());
            Iterator<PageMetric> itr = pages.iterator();
            while (itr.hasNext()) {
                x++;
                PageMetric p = itr.next();
                // if we have a record of the last page recorded, then remove that page and all
                // pages before it to limit the time necessary in updating
                if (lastPage != null && x <= lastPage) {
                    itr.remove();
                } else {
                    p.setPageNumber(x);
                }
            }
            lastPageMap.put(queryMetric.getQueryId(), x);
            queryMetric.setLastUpdated(new Date(lastUpdated));
        }
    }
}
 
Example 13
Source File: PointValuePair.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(PointValuePair o) {
    CompareToBuilder compareToBuilder = new CompareToBuilder();
    compareToBuilder.append(this.getPoint(), o.getPoint());
    return compareToBuilder.toComparison();
}