Example usage for org.apache.cassandra.utils ByteBufferUtil compareUnsigned

List of usage examples for org.apache.cassandra.utils ByteBufferUtil compareUnsigned

Introduction

In this page you can find the example usage for org.apache.cassandra.utils ByteBufferUtil compareUnsigned.

Prototype

@Inline
    public static int compareUnsigned(ByteBuffer o1, ByteBuffer o2) 

Source Link

Usage

From source file:andromache.hadoop.CassandraRecordWriter.java

License:Apache License

/**
 * Checks for null or emptiness within a key.
 *
 * @param keyBuff/*  w  w  w  . j  a v a  2s. c o m*/
 * @return
 * @throws java.nio.charset.CharacterCodingException
 */
private boolean isKeyEmpty(ByteBuffer keyBuff) throws CharacterCodingException {

    if (keyBuff == null) {
        return true;
    }

    boolean isEmptyBuffer = false;

    try {
        isEmptyBuffer = ByteBufferUtil.compareUnsigned(ByteBufferUtil.EMPTY_BYTE_BUFFER, keyBuff) == 0;
    } catch (Exception e) {
        isEmptyBuffer = false; // if we could not determine it, then we don't touch the logic
    }

    return isEmptyBuffer;
}

From source file:com.protectwise.cassandra.db.compaction.example.ConfigurableDeleter.java

License:Apache License

/**
 * Returns true if value is found inside one of the ranges defined.
 *
 * @param ranges/*from   w ww  .  ja  v a 2s .c  o m*/
 * @param value
 * @return
 */
protected boolean testRule(ByteBuffer[][] ranges, ByteBuffer value) {
    if (value == null) {
        logger.warn("Null value");
        return false;
    }
    for (ByteBuffer[] range : ranges) {
        // Null values indicate unbounded.  range[0] is the lower bound inclusive, range[1] is the upper bound inclusive.
        // We are guaranteed both values exist before we get to this point.
        if ((range[0] == null || ByteBufferUtil.compareUnsigned(range[0], value) <= 0)
                && (range[1] == null || ByteBufferUtil.compareUnsigned(range[1], value) >= 0)) {
            return true;
        }
    }
    return false;
}

From source file:com.stratio.cassandra.lucene.key.PartitionMapper.java

License:Apache License

/**
 * Returns a Lucene {@link SortField} for sorting documents/rows according to the partition key.
 *
 * @return a sort field for sorting by partition key
 *///w ww.j a  v  a2  s  .c  o m
public SortField sortField() {
    return new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    ByteBuffer bb1 = ByteBufferUtils.byteBuffer(val1);
                    ByteBuffer bb2 = ByteBufferUtils.byteBuffer(val2);
                    return ByteBufferUtil.compareUnsigned(bb1, bb2);
                }
            };
        }
    });
}

From source file:com.stratio.cassandra.lucene.util.ByteBufferUtilsTest.java

License:Apache License

@Test
public void testBytesRef() throws Exception {
    CompositeType type = CompositeType.getInstance(UTF8Type.instance, Int32Type.instance);
    ByteBuffer in = type.decompose("monkey", 1);
    BytesRef bytesRef = ByteBufferUtils.bytesRef(in);
    ByteBuffer out = ByteBufferUtils.byteBuffer(bytesRef);
    assertEquals("Failing conversion between ByteBuffer and BytesRef", 0,
            ByteBufferUtil.compareUnsigned(in, out));
}