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.apache.druid.query.aggregation.distinctcount.DistinctCountAggregatorFactory.java

@Override
public Comparator getComparator() {
    return new Comparator() {
        @Override/*  w  ww  . j a va  2s  .c om*/
        public int compare(Object o, Object o1) {
            return Longs.compare(((Number) o).longValue(), ((Number) o1).longValue());
        }
    };
}

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

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

From source file:org.apache.phoenix.hbase.index.covered.data.LocalTable.java

protected long getOldestTimestamp(Collection<List<Cell>> cellLists) {
    Ordering<List<Cell>> cellListOrdering = new Ordering<List<Cell>>() {
        @Override/* w  ww  . ja  va 2s.  c o m*/
        public int compare(List<Cell> left, List<Cell> right) {
            // compare the last element of each list, since that is the smallest in that list
            return Longs.compare(Iterables.getLast(left).getTimestamp(),
                    Iterables.getLast(right).getTimestamp());
        }
    };
    List<Cell> minList = cellListOrdering.min(cellLists);
    return Iterables.getLast(minList).getTimestamp();
}

From source file:io.opencensus.common.Duration.java

/**
 * Compares this {@code Duration} to the specified {@code Duration}.
 *
 * @param otherDuration the other {@code Duration} to compare to, not {@code null}.
 * @return the comparator value: zero if equal, negative if this duration is smaller than
 *     otherDuration, positive if larger.
 * @throws NullPointerException if otherDuration is {@code null}.
 *//*from   w  w w.ja  v  a  2 s  . c o m*/
@Override
public int compareTo(Duration otherDuration) {
    int cmp = Longs.compare(getSeconds(), otherDuration.getSeconds());
    if (cmp != 0) {
        return cmp;
    }
    return Longs.compare(getNanos(), otherDuration.getNanos());
}

From source file:org.onosproject.provider.nil.cli.CreateNullEntity.java

/**
 * Finds an available connect points among edge ports of the specified device.
 *
 * @param deviceId device identifier//w w  w  .jav  a 2  s  . c  o m
 * @return list of connect points available for link or host attachments
 */
protected List<ConnectPoint> findAvailablePorts(DeviceId deviceId) {
    EdgePortService eps = get(EdgePortService.class);

    // As there may be a slight delay in edge service getting updated, retry a few times
    for (int i = 0; i < MAX_EDGE_PORT_TRIES; i++) {
        List<ConnectPoint> points = ImmutableList.sortedCopyOf(
                (l, r) -> Longs.compare(l.port().toLong(), r.port().toLong()), eps.getEdgePoints(deviceId));
        if (!points.isEmpty()) {
            return points;
        }
        Tools.delay(100);
    }
    return ImmutableList.of();
}

From source file:org.apache.phoenix.schema.types.PUnsignedLong.java

@Override
public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
    if (rhsType == PDecimal.INSTANCE) {
        return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
    } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE,
            PUnsignedFloat.INSTANCE)) {//  w w  w.j a  v  a 2 s .  c o m
        return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
    }
    return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
}

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

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

From source file:eugene.market.book.OrderStatus.java

/**
 * Executes this <code>quantity</code> of this {@link Order} at this <code>price</code>.
 *
 * @param price    price to execute at./*from  w  w  w.  j  a v a 2s.  c  o  m*/
 * @param quantity quantity to execute
 *
 * @return status of execution.
 */
// TODO: check if the status is executable.
public OrderStatus execute(final BigDecimal price, final Long quantity) {
    checkNotNull(price);
    checkArgument(price.compareTo(Order.NO_PRICE) == 1);
    checkNotNull(quantity);
    checkArgument(Longs.compare(quantity, Order.NO_QTY) == 1);
    checkArgument(Longs.compare(quantity, this.leavesQty) <= 0);

    final BigDecimal quantityPrice = price.multiply(BigDecimal.valueOf(quantity));
    final BigDecimal avgPxCumQty = this.avgPx.multiply(BigDecimal.valueOf(this.cumQty));
    final BigDecimal quantityCumQty = BigDecimal.valueOf(quantity).add(BigDecimal.valueOf(this.cumQty));

    final BigDecimal newAvgPx = quantityPrice.add(avgPxCumQty).divide(quantityCumQty, RoundingMode.HALF_UP);
    final Long newLeavesQty = this.leavesQty - quantity;
    final Long newCumQty = this.cumQty + quantity;
    final OrdStatus newOrdStatus = newLeavesQty.equals(Long.valueOf(0L)) ? FILLED : PARTIALLY_FILLED;
    return new OrderStatus(order, newAvgPx, newLeavesQty, newCumQty, newOrdStatus);
}

From source file:org.apache.hbase.cell.CellComparator.java

/**
 * special case for KeyValue.equals// w w  w.j  a  v  a 2 s .c  o m
 */
private static int compareStaticIgnoreMvccVersion(Cell a, Cell b) {
    //row
    int c = Bytes.compareTo(a.getRowArray(), a.getRowOffset(), a.getRowLength(), b.getRowArray(),
            b.getRowOffset(), b.getRowLength());
    if (c != 0)
        return c;

    //family
    c = Bytes.compareTo(a.getFamilyArray(), a.getFamilyOffset(), a.getFamilyLength(), b.getFamilyArray(),
            b.getFamilyOffset(), b.getFamilyLength());
    if (c != 0)
        return c;

    //qualifier
    c = Bytes.compareTo(a.getQualifierArray(), a.getQualifierOffset(), a.getQualifierLength(),
            b.getQualifierArray(), b.getQualifierOffset(), b.getQualifierLength());
    if (c != 0)
        return c;

    //timestamp: later sorts first
    c = -Longs.compare(a.getTimestamp(), b.getTimestamp());
    if (c != 0)
        return c;

    //type
    c = (0xff & a.getTypeByte()) - (0xff & b.getTypeByte());
    return c;
}

From source file:org.apache.tajo.datum.TimestampDatum.java

@Override
public int compareTo(Datum datum) {
    if (datum.kind() == TajoDataTypes.Type.TIMESTAMP) {
        TimestampDatum another = (TimestampDatum) datum;
        return Longs.compare(timestamp, another.timestamp);
    } else if (datum.isNull()) {
        return -1;
    } else {/*w  ww.  j  a va 2 s  .  c o  m*/
        throw new InvalidOperationException(datum.type());
    }
}