Example usage for com.google.common.primitives Longs compare

List of usage examples for com.google.common.primitives Longs compare

Introduction

In this page you can find the example usage for com.google.common.primitives Longs compare.

Prototype

public static int compare(long a, long b) 

Source Link

Document

Compares the two specified long values.

Usage

From source file:org.ow2.proactive.scheduler.job.JobIdImpl.java

/**
 * {@inheritDoc}
 */
@Override
public int compareTo(JobId jobId) {
    return Longs.compare(id, ((JobIdImpl) jobId).id);
}

From source file:co.cask.cdap.explore.executor.AbstractQueryExecutorHttpHandler.java

protected List<QueryInfo> filterQueries(List<QueryInfo> queries, final long offset, final boolean isForward,
        final int limit) {
    // Reverse the list if the pagination is in the reverse from the offset until the max limit
    if (!isForward) {
        queries = Lists.reverse(queries);
    }/*w  w  w. ja v a  2s  .  c o m*/

    return FluentIterable.from(queries).filter(new Predicate<QueryInfo>() {
        @Override
        public boolean apply(@Nullable QueryInfo queryInfo) {
            if (isForward) {
                return queryInfo.getTimestamp() < offset;
            } else {
                return queryInfo.getTimestamp() > offset;
            }
        }
    }).limit(limit).toSortedImmutableList(new Comparator<QueryInfo>() {
        @Override
        public int compare(QueryInfo first, QueryInfo second) {
            //sort descending.
            return Longs.compare(second.getTimestamp(), first.getTimestamp());
        }
    });
}

From source file:org.guldenj.utils.ExponentialBackoff.java

@Override
public int compareTo(ExponentialBackoff other) {
    // note that in this implementation compareTo() is not consistent with equals()
    return Longs.compare(retryTime, other.retryTime);
}

From source file:com.cinchapi.concourse.server.model.PrimaryKey.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof PrimaryKey) {
        final PrimaryKey other = (PrimaryKey) obj;
        return Longs.compare(data, other.data) == 0;
    }//www.  j  a  va  2s  .  c o  m
    return false;
}

From source file:org.jclouds.gogrid.domain.IpPortPair.java

@Override
public int compareTo(IpPortPair o) {
    if (ip != null && o.getIp() != null)
        return Longs.compare(ip.getId(), o.getIp().getId());
    return Ints.compare(port, o.getPort());
}

From source file:io.druid.java.util.common.granularity.Granularity.java

public static List<Granularity> granularitiesFinerThan(final Granularity gran0) {
    final List<Granularity> retVal = Lists.newArrayList();
    final DateTime origin = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getOrigin()
            : null;/*from  ww  w . jav a2s  .co m*/
    final DateTimeZone tz = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getTimeZone()
            : null;
    for (GranularityType gran : GranularityType.values()) {
        /**
         * All and None are excluded b/c when asked to give all granularities finer
         * than "TEN_MINUTE", you want the answer to be "FIVE_MINUTE, MINUTE and SECOND"
         * it doesn't make sense to include ALL or None to be part of this.
         */
        if (gran == GranularityType.ALL || gran == GranularityType.NONE) {
            continue;
        }
        final Granularity segmentGranularity = gran.create(origin, tz);
        final long segmentGranularityDurationMillis = segmentGranularity.bucket(DateTimes.EPOCH)
                .toDurationMillis();
        final long gran0DurationMillis = gran0.bucket(DateTimes.EPOCH).toDurationMillis();
        if (segmentGranularityDurationMillis <= gran0DurationMillis) {
            retVal.add(segmentGranularity);
        }
    }
    retVal.sort((g1, g2) -> {
        long duration1 = g2.bucket(DateTimes.EPOCH).toDurationMillis();
        long duration2 = g1.bucket(DateTimes.EPOCH).toDurationMillis();
        return Longs.compare(duration1, duration2);
    });
    return retVal;
}

From source file:com.metamx.druid.query.group.orderby.DefaultLimitSpec.java

private Ordering<Row> makeComparator(List<DimensionSpec> dimensions, List<AggregatorFactory> aggs,
        List<PostAggregator> postAggs) {
    Ordering<Row> ordering = new Ordering<Row>() {
        @Override//from   w  w w .  j  av a2 s . c o m
        public int compare(Row left, Row right) {
            return Longs.compare(left.getTimestampFromEpoch(), right.getTimestampFromEpoch());
        }
    };

    Map<String, Ordering<Row>> possibleOrderings = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
    for (DimensionSpec spec : dimensions) {
        final String dimension = spec.getOutputName();
        possibleOrderings.put(dimension, dimensionOrdering(dimension));
    }

    for (final AggregatorFactory agg : aggs) {
        final String column = agg.getName();
        possibleOrderings.put(column, metricOrdering(column, agg.getComparator()));
    }

    for (PostAggregator postAgg : postAggs) {
        final String column = postAgg.getName();
        possibleOrderings.put(column, metricOrdering(column, postAgg.getComparator()));
    }

    for (OrderByColumnSpec columnSpec : columns) {
        Ordering<Row> nextOrdering = possibleOrderings.get(columnSpec.getDimension());

        if (nextOrdering == null) {
            throw new ISE("Unknown column in order clause[%s]", columnSpec);
        }

        switch (columnSpec.getDirection()) {
        case DESCENDING:
            nextOrdering = nextOrdering.reverse();
        }

        ordering = ordering.compound(nextOrdering);
    }

    return ordering;
}

From source file:org.apache.tajo.tuple.memory.OffHeapRowBlockUtils.java

public static final int compareColumn(UnSafeTuple tuple1, UnSafeTuple tuple2, int index,
        TajoDataTypes.Type type, boolean ascending, boolean nullFirst) {
    final boolean n1 = tuple1.isBlankOrNull(index);
    final boolean n2 = tuple2.isBlankOrNull(index);
    if (n1 && n2) {
        return 0;
    }//from  w ww. ja  v a  2s .  c  om

    if (n1 ^ n2) {
        return nullFirst ? (n1 ? -1 : 1) : (n1 ? 1 : -1);
    }

    int compare;
    switch (type) {
    case BOOLEAN:
        compare = Booleans.compare(tuple1.getBool(index), tuple2.getBool(index));
        break;
    case BIT:
        compare = tuple1.getByte(index) - tuple2.getByte(index);
        break;
    case INT1:
    case INT2:
        compare = Shorts.compare(tuple1.getInt2(index), tuple2.getInt2(index));
        break;
    case DATE:
    case INT4:
        compare = Ints.compare(tuple1.getInt4(index), tuple2.getInt4(index));
        break;
    case TIME:
    case TIMESTAMP:
    case INT8:
        compare = Longs.compare(tuple1.getInt8(index), tuple2.getInt8(index));
        break;
    case FLOAT4:
        compare = Floats.compare(tuple1.getFloat4(index), tuple2.getFloat4(index));
        break;
    case FLOAT8:
        compare = Doubles.compare(tuple1.getFloat8(index), tuple2.getFloat8(index));
        break;
    case CHAR:
    case TEXT:
    case BLOB:
        compare = UnSafeTupleBytesComparator.compare(tuple1.getFieldAddr(index), tuple2.getFieldAddr(index));
        break;
    default:
        throw new TajoRuntimeException(new UnsupportedException("unknown data type '" + type.name() + "'"));
    }
    return ascending ? compare : -compare;
}

From source file:com.palantir.atlasdb.schema.SchemaVersion.java

public static Ordering<SchemaVersion> getOrdering() {
    return new Ordering<SchemaVersion>() {
        @Override//from   w  w  w.ja va  2s.  c o  m
        public int compare(SchemaVersion left, SchemaVersion right) {
            if (left.version != right.version) {
                return Longs.compare(left.version, right.version);
            } else if (left.hotfix != right.hotfix) {
                return Longs.compare(left.hotfix, right.hotfix);
            } else {
                return Longs.compare(left.hotfixHotfix, right.hotfixHotfix);
            }
        }
    };
}

From source file:org.jclouds.ecs.domain.BillingToken.java

@Override
public int compareTo(BillingToken o) {
    return Longs.compare(id, o.getId());
}