Package java.nio

Examples of java.nio.LongBuffer


        int offset = array.offset();
        array.setAll(LongArray.unsafeValueOf());
        assertArrayEquals(new long[]{}, array.toArray());
        assertEquals(0, array.length());
        assertEquals(offset, array.offset());
        LongBuffer buffer = array.buffer();
        buffer.rewind().limit(buffer.capacity());
        while (buffer.hasRemaining()) {
            assertEquals(0, buffer.get());
        }
    }


            array.longRemove();
        }
        assertArrayEquals(new long[]{}, array.toArray());
        assertEquals(0, array.length());
        assertEquals(offset, array.offset());
        LongBuffer buffer = array.buffer();
        buffer.rewind().limit(buffer.capacity());
        while (buffer.hasRemaining()) {
            assertEquals(0, buffer.get());
        }
    }

        int offset = array.offset();
        array.clear();
        assertArrayEquals(new long[]{}, array.toArray());
        assertEquals(0, array.length());
        assertEquals(offset, array.offset());
        LongBuffer buffer = array.buffer();
        buffer.rewind().limit(buffer.capacity());
        while (buffer.hasRemaining()) {
            assertEquals(0, buffer.get());
        }
    }

        array.addLong((long) 4);
        MutableLongArray backedByArray = MutableLongArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 8).asLongBuffer();
        MutableLongArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedLongArray bigger = UnboundedLongArray.copyOf(array);

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray());
    }

    @Test
    public void testAddAllNoBackingArray0() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 10).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(LongArray.unsafeValueOf());
        assertEquals(8, notBackedByArray.length());
        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray());

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray2() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 11).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(LongArray.unsafeValueOf((long) 5, (long) 5));
        assertEquals(10, notBackedByArray.length());
        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray3() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 11).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        try {
            notBackedByArray.addAll(LongArray.unsafeValueOf((long) 5, (long) 5, (long) 5));
            fail();

        array.addLong(4);
        MutableLongArray backedByArray = MutableLongArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 8).asLongBuffer();
        MutableLongArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedLongArray bigger = UnboundedLongArray.copyOf(array);

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray());
        MutableLongArray backedByArray = MutableLongArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 8).asLongBuffer();
        MutableLongArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedLongArray tooBig = UnboundedLongArray.copyOf(array);

            return this;
        }
        int newOffset = elements.position() + offset;
        int newLength = elements.remaining() - offset;
        subArrayCheck(newOffset, newLength);
        LongBuffer copy = elements.duplicate();
        copy.position(newOffset);
        return new LongBufferArrayImpl(copy, characteristics, false);
    }

TOP

Related Classes of java.nio.LongBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.