Example usage for org.apache.cassandra.db Clustering getRawValues

List of usage examples for org.apache.cassandra.db Clustering getRawValues

Introduction

In this page you can find the example usage for org.apache.cassandra.db Clustering getRawValues.

Prototype

public ByteBuffer[] getRawValues();

Source Link

Document

The values of this prefix as an array.

Usage

From source file:com.stratio.cassandra.lucene.IndexPagingState.java

License:Apache License

/**
 * Returns a byte buffer representation of this. Thew returned result can be read with {@link #build(ByteBuffer)}.
 *
 * @return a byte buffer representing this
 *//*from w ww  .  j a  v  a  2 s  . c  om*/
public ByteBuffer toByteBuffer() {
    ByteBuffer[] entryValues = new ByteBuffer[entries.size()];
    entries.entrySet().stream().map(entry -> {
        DecoratedKey key = entry.getKey();
        Clustering clustering = entry.getValue();
        ByteBuffer[] clusteringValues = clustering.getRawValues();
        ByteBuffer[] values = new ByteBuffer[1 + clusteringValues.length];
        values[0] = key.getKey();
        System.arraycopy(clusteringValues, 0, values, 1, clusteringValues.length);
        return compose(values);
    }).collect(toList()).toArray(entryValues);
    ByteBuffer values = compose(entryValues);
    ByteBuffer out = ByteBuffer.allocate(2 + values.remaining());
    writeShortLength(out, remaining);
    out.put(values);
    out.flip();
    return out;
}

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

License:Apache License

/**
 * Returns a {@link ByteBuffer} representing the specified clustering key
 *
 * @param clustering the clustering key/*  ww w .j a v a  2  s. c om*/
 * @return the byte buffer representing {@code clustering}
 */
public ByteBuffer byteBuffer(Clustering clustering) {
    CompositeType.Builder builder = type.builder();
    for (ByteBuffer component : clustering.getRawValues()) {
        builder.add(component);
    }
    return builder.build();
}