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

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

Introduction

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

Prototype

public static int compare(boolean a, boolean b) 

Source Link

Document

Compares the two specified boolean values in the standard way ( false is considered less than true ).

Usage

From source file:org.n52.iceland.util.Comparables.java

public static int compare(boolean x, boolean y) {
    return Booleans.compare(x, y);
}

From source file:org.apache.hadoop.hdfs.qjournal.client.SegmentRecoveryComparator.java

@Override
public int compare(Entry<AsyncLogger, PrepareRecoveryResponseProto> a,
        Entry<AsyncLogger, PrepareRecoveryResponseProto> b) {

    PrepareRecoveryResponseProto r1 = a.getValue();
    PrepareRecoveryResponseProto r2 = b.getValue();

    // A response that has data for a segment is always better than one
    // that doesn't.
    if (r1.hasSegmentState() != r2.hasSegmentState()) {
        return Booleans.compare(r1.hasSegmentState(), r2.hasSegmentState());
    }/*from   w ww  .  j  av a  2  s  .c  o  m*/

    if (!r1.hasSegmentState()) {
        // Neither has a segment, so neither can be used for recover.
        // Call them equal.
        return 0;
    }

    // They both have a segment.
    SegmentStateProto r1Seg = r1.getSegmentState();
    SegmentStateProto r2Seg = r2.getSegmentState();

    Preconditions.checkArgument(r1Seg.getStartTxId() == r2Seg.getStartTxId(),
            "Should only be called with responses for corresponding segments: "
                    + "%s and %s do not have the same start txid.",
            r1, r2);

    // If one is in-progress but the other is finalized,
    // the finalized one is greater.
    if (r1Seg.getIsInProgress() != r2Seg.getIsInProgress()) {
        return Booleans.compare(!r1Seg.getIsInProgress(), !r2Seg.getIsInProgress());
    }

    if (!r1Seg.getIsInProgress()) {
        // If both are finalized, they should match lengths
        if (r1Seg.getEndTxId() != r2Seg.getEndTxId()) {
            throw new AssertionError("finalized segs with different lengths: " + r1 + ", " + r2);
        }
        return 0;
    }

    // Both are in-progress.
    long r1SeenEpoch = Math.max(r1.getAcceptedInEpoch(), r1.getLastWriterEpoch());
    long r2SeenEpoch = Math.max(r2.getAcceptedInEpoch(), r2.getLastWriterEpoch());

    return ComparisonChain.start().compare(r1SeenEpoch, r2SeenEpoch)
            .compare(r1.getSegmentState().getEndTxId(), r2.getSegmentState().getEndTxId()).result();
}

From source file:com.b2international.snowowl.snomed.reasoner.server.diff.relationship.StatementFragmentOrdering.java

@Override
public int compare(final StatementFragment o1, final StatementFragment o2) {

    final int attributeDelta = Longs.compare(o1.getTypeId(), o2.getTypeId());
    if (attributeDelta != 0)
        return attributeDelta;

    final int valueDelta = Longs.compare(o1.getDestinationId(), o2.getDestinationId());
    if (valueDelta != 0)
        return valueDelta;

    final int groupDelta = o1.getGroup() - o2.getGroup();
    if (groupDelta != 0)
        return groupDelta;

    final int unionGroupDelta = o1.getUnionGroup() - o2.getUnionGroup();
    if (unionGroupDelta != 0)
        return unionGroupDelta;

    final int isUniversalDelta = Booleans.compare(o1.isUniversal(), o2.isUniversal());
    if (isUniversalDelta != 0)
        return isUniversalDelta;

    final int isDestinationNegatedDelta = Booleans.compare(o1.isDestinationNegated(),
            o2.isDestinationNegated());/* w ww.  j  ava2  s .  c  om*/
    return isDestinationNegatedDelta;
}

From source file:org.spongepowered.common.data.manipulator.mutable.item.SpongePlaceableData.java

@Override
public int compareTo(PlaceableData o) {
    return Booleans.compare(o.placeable().containsAll(getValue()), getValue().containsAll(o.placeable().get()));
}

From source file:org.spongepowered.common.data.manipulator.mutable.item.SpongeBreakableData.java

@Override
public int compareTo(BreakableData o) {
    return Booleans.compare(o.breakable().containsAll(getValue()), getValue().containsAll(o.breakable().get()));
}

From source file:org.spongepowered.common.data.manipulator.immutable.item.ImmutableSpongePlaceableData.java

@Override
public int compareTo(ImmutablePlaceableData o) {
    return Booleans.compare(o.placeable().containsAll(getValue()), getValue().containsAll(o.placeable().get()));
}

From source file:com.sk89q.guavabackport.collect.Cut.java

@Override
public int compareTo(final Cut<C> that) {
    if (that == belowAll()) {
        return 1;
    }/* w  w  w  .  ja va2s  .c  om*/
    if (that == aboveAll()) {
        return -1;
    }
    final int result = Range.compareOrThrow(this.endpoint, that.endpoint);
    if (result != 0) {
        return result;
    }
    return Booleans.compare(this instanceof AboveValue, that instanceof AboveValue);
}

From source file:chess_.engine.classic.player.ai.MoveOrdering.java

private static Collection<Move> calculateSimpleMoveOrder(final Collection<Move> moves) {

    final List<Move> sortedMoves = new ArrayList<>();
    sortedMoves.addAll(moves);/*  w w w  . j  a  va2s  .c o m*/
    Collections.sort(sortedMoves, new Comparator<Move>() {
        @Override
        public int compare(final Move m1, final Move m2) {
            return Booleans.compare(m2.isAttack(), m1.isAttack());
        }
    });

    return sortedMoves;
}

From source file:com.cloudera.oryx.rdf.common.tree.TreePath.java

@Override
public int compareTo(TreePath o) {
    int maxLength = FastMath.max(pathLength, o.pathLength);
    for (int i = 0; i < maxLength; i++) {
        if (i < pathLength) {
            boolean thisLeft = isLeftAt(i);
            if (i < o.pathLength) {
                boolean thatLeft = o.isLeftAt(i);
                if (thisLeft != thatLeft) {
                    return Booleans.compare(thatLeft, thisLeft);
                }//from  w w w . j ava  2  s  . c o m
                // else continue
            } else {
                return thisLeft ? -1 : 1;
            }
        } else {
            // i < o.pathLength
            boolean thatLeft = o.isLeftAt(i);
            return thatLeft ? 1 : -1;
        }
    }
    return 0;
}

From source file:org.summer.dsl.xbase.lib.BooleanExtensions.java

/**
 * The binary <code>lessThan</code> operator for boolean values.
 * {@code false} is considered less than {@code true}.
 * //from   www .  j  a  v  a 2  s .  co  m
 * @see Boolean#compareTo(Boolean)
 * @see Booleans#compare(boolean, boolean)
 * @param a  a boolean.
 * @param b  another boolean.
 * @return   <code>Booleans.compare(a, b)&lt;0</code>
 * @since 2.4
 */
@Pure
@Inline(value = "($3.compare($1, $2) < 0)", imported = Booleans.class)
public static boolean operator_lessThan(boolean a, boolean b) {
    return Booleans.compare(a, b) < 0;
}