Java Code Examples for java.nio.ByteBuffer.compareTo()

The following are Jave code examples for showing how to use compareTo() of the java.nio.ByteBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sstable-adaptor   File: Conflicts.java   View Source Code Vote up 6 votes
public static Resolution resolveRegular(long leftTimestamp,
                                        boolean leftLive,
                                        int leftLocalDeletionTime,
                                        ByteBuffer leftValue,
                                        long rightTimestamp,
                                        boolean rightLive,
                                        int rightLocalDeletionTime,
                                        ByteBuffer rightValue)
{
    if (leftTimestamp != rightTimestamp)
        return leftTimestamp < rightTimestamp ? Resolution.RIGHT_WINS : Resolution.LEFT_WINS;

    if (leftLive != rightLive)
        return leftLive ? Resolution.RIGHT_WINS : Resolution.LEFT_WINS;

    int c = leftValue.compareTo(rightValue);
    if (c < 0)
        return Resolution.RIGHT_WINS;
    else if (c > 0)
        return Resolution.LEFT_WINS;

    // Prefer the longest ttl if relevant
    return leftLocalDeletionTime < rightLocalDeletionTime ? Resolution.RIGHT_WINS : Resolution.LEFT_WINS;
}
 
Example 2
Project: athena   File: BgpFsDestinationPrefix.java   View Source Code Vote up 6 votes
@Override
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }

    if (o instanceof BgpFsDestinationPrefix) {
        BgpFsDestinationPrefix that = (BgpFsDestinationPrefix) o;

        if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) {
            ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets());
            ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets());
            return value1.compareTo(value2);
        }

        if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) {
            return 1;
        } else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) {
            return -1;
        }
    }
    return 1;
}
 
Example 3
Project: athena   File: BgpFsSourcePrefix.java   View Source Code Vote up 6 votes
@Override
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }

    if (o instanceof BgpFsSourcePrefix) {
        BgpFsSourcePrefix that = (BgpFsSourcePrefix) o;

        if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) {
            ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets());
            ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets());
            return value1.compareTo(value2);
        }

        if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) {
            return 1;
        } else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) {
            return -1;
        }
    }
    return 1;
}
 
Example 4
Project: athena   File: IPReachabilityInformationTlv.java   View Source Code Vote up 5 votes
@Override
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }
    ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix);
    ByteBuffer value2 = ByteBuffer.wrap(((IPReachabilityInformationTlv) o).ipPrefix);
    return value1.compareTo(value2);
}
 
Example 5
Project: athena   File: IsIsNonPseudonode.java   View Source Code Vote up 5 votes
@Override
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }
    ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
    ByteBuffer value2 = ByteBuffer.wrap(((IsIsNonPseudonode) o).isoNodeID);
    return value1.compareTo(value2);
}
 
Example 6
Project: athena   File: IsIsPseudonode.java   View Source Code Vote up 5 votes
@Override
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }
    ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
    ByteBuffer value2 = ByteBuffer.wrap(((IsIsPseudonode) o).isoNodeID);
    if (value1.compareTo(value2) != 0) {
        return value1.compareTo(value2);
    }
    return ((Byte) (this.psnIdentifier)).compareTo((Byte) (((IsIsPseudonode) o).psnIdentifier));
}