Example usage for java.nio LongBuffer wrap

List of usage examples for java.nio LongBuffer wrap

Introduction

In this page you can find the example usage for java.nio LongBuffer wrap.

Prototype

public static LongBuffer wrap(long[] array) 

Source Link

Document

Creates a new long buffer by wrapping the given long array.

Usage

From source file:Main.java

public static void main(String[] args) {
    LongBuffer bb = LongBuffer.wrap(new long[] { 0, 1, 2, 3, 4, 5, 6 });
    bb.put(100);//from ww  w .  ja  v  a2  s .c  om
    System.out.println(Arrays.toString(bb.array()));

}

From source file:Main.java

public static void main(String[] args) {

    LongBuffer byteBuffer = LongBuffer.wrap(new long[] { 1L, 2L, 3L });
    BitSet bitset1 = BitSet.valueOf(byteBuffer);

    // print the sets
    System.out.println("Bitset1:" + bitset1);

}

From source file:io.druid.segment.IndexMaker.java

private static void makeTimeColumn(final FileSmoosher v9Smoosher, final ProgressIndicator progress,
        final Iterable<Rowboat> theRows, final int rowCount) throws IOException {
    final String section = "make time column";
    progress.startSection(section);/*  ww w  .  j a v a  2 s.  co  m*/

    long[] longs = new long[rowCount];

    int rowNum = 0;
    for (Rowboat theRow : theRows) {
        longs[rowNum++] = theRow.getTimestamp();
    }

    CompressedLongsIndexedSupplier timestamps = CompressedLongsIndexedSupplier.fromLongBuffer(
            LongBuffer.wrap(longs), IndexIO.BYTE_ORDER, CompressedObjectStrategy.DEFAULT_COMPRESSION_STRATEGY

    );

    final ColumnDescriptor.Builder timeBuilder = ColumnDescriptor.builder();
    timeBuilder.setValueType(ValueType.LONG);

    writeColumn(v9Smoosher, new LongGenericColumnPartSerde(timestamps, IndexIO.BYTE_ORDER), timeBuilder,
            "__time");

    progress.stopSection(section);
}

From source file:io.druid.segment.IndexMaker.java

private static void makeMetricColumn(final FileSmoosher v9Smoosher, final ProgressIndicator progress,
        final Iterable<Rowboat> theRows, final int metricIndex, final String metric,
        final Map<String, ValueType> valueTypes, final Map<String, String> metricTypeNames, final int rowCount,
        final CompressedObjectStrategy.CompressionStrategy compressionStrategy) throws IOException {
    final String section = String.format("make column[%s]", metric);
    progress.startSection(section);/*from   www  . j  a va 2 s .c  o  m*/

    final ColumnDescriptor.Builder metBuilder = ColumnDescriptor.builder();
    ValueType type = valueTypes.get(metric);

    switch (type) {
    case FLOAT: {
        metBuilder.setValueType(ValueType.FLOAT);

        float[] arr = new float[rowCount];
        int rowNum = 0;
        for (Rowboat theRow : theRows) {
            Object obj = theRow.getMetrics()[metricIndex];
            arr[rowNum++] = (obj == null) ? 0 : ((Number) obj).floatValue();
        }

        CompressedFloatsIndexedSupplier compressedFloats = CompressedFloatsIndexedSupplier
                .fromFloatBuffer(FloatBuffer.wrap(arr), IndexIO.BYTE_ORDER, compressionStrategy);

        writeColumn(v9Smoosher, new FloatGenericColumnPartSerde(compressedFloats, IndexIO.BYTE_ORDER),
                metBuilder, metric);
        break;
    }
    case LONG: {
        metBuilder.setValueType(ValueType.LONG);

        long[] arr = new long[rowCount];
        int rowNum = 0;
        for (Rowboat theRow : theRows) {
            Object obj = theRow.getMetrics()[metricIndex];
            arr[rowNum++] = (obj == null) ? 0 : ((Number) obj).longValue();
        }

        CompressedLongsIndexedSupplier compressedLongs = CompressedLongsIndexedSupplier
                .fromLongBuffer(LongBuffer.wrap(arr), IndexIO.BYTE_ORDER, compressionStrategy);

        writeColumn(v9Smoosher, new LongGenericColumnPartSerde(compressedLongs, IndexIO.BYTE_ORDER), metBuilder,
                metric);
        break;
    }
    case COMPLEX:
        String complexType = metricTypeNames.get(metric);

        ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(complexType);

        if (serde == null) {
            throw new ISE("Unknown type[%s]", complexType);
        }

        final GenericIndexed metricColumn = GenericIndexed
                .fromIterable(Iterables.transform(theRows, new Function<Rowboat, Object>() {
                    @Override
                    public Object apply(Rowboat input) {
                        return input.getMetrics()[metricIndex];
                    }
                }), serde.getObjectStrategy());

        metBuilder.setValueType(ValueType.COMPLEX);
        writeColumn(v9Smoosher, new ComplexColumnPartSerde(metricColumn, complexType), metBuilder, metric);
        break;
    default:
        throw new ISE("Unknown type[%s]", type);
    }

    progress.stopSection(section);
}