Package java.nio

Examples of java.nio.ShortBuffer


    private BoundedShortArray array;

    @Before
    public void setUp() throws Exception {
        short[] a = new short[] {0, 1, 1, 2, 1, 2, 3, 3, 4, 0, 0};
        ShortBuffer buffer = ShortBuffer.wrap(a, 1, 8);
        array = BoundedShortArray.valueOf(buffer);
        array = serializeAndDeserialize(array); // Test serialization.
        short[] b = new short[11];
        array.toArray(b, 1, 8);
        buffer = ShortBuffer.wrap(b, 1, 8);
View Full Code Here


        array.addShort((short) 4);
        MutableShortArray backedByArray = MutableShortArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 8).asShortBuffer();
        MutableShortArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedShortArray bigger = UnboundedShortArray.copyOf(array);
View Full Code Here

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

    @Test
    public void testAddAllNoBackingArray0() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 10).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(ShortArray.unsafeValueOf());
        assertEquals(8, notBackedByArray.length());
        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray());
View Full Code Here

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

    @Test
    public void testAddAllNoBackingArray1() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 11).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(ShortArray.unsafeValueOf((short) 5));
        assertEquals(9, notBackedByArray.length());
        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray());
View Full Code Here

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

    @Test
    public void testAddAllNoBackingArray2() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 11).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(ShortArray.unsafeValueOf((short) 5, (short) 5));
        assertEquals(10, notBackedByArray.length());
        assertArrayEquals(new short[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());
View Full Code Here

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

    @Test
    public void testAddAllNoBackingArray3() throws Exception {
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 11).asShortBuffer();
        buffer.position(1).limit(9);
        BoundedShortArray notBackedByArray = BoundedShortArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        try {
            notBackedByArray.addAll(ShortArray.unsafeValueOf((short) 5, (short) 5, (short) 5));
            fail();
View Full Code Here

        int offset = array.offset();
        array.setAll(ShortArray.unsafeValueOf());
        assertArrayEquals(new short[]{}, array.toArray());
        assertEquals(0, array.length());
        assertEquals(offset, array.offset());
        ShortBuffer buffer = array.buffer();
        buffer.rewind().limit(buffer.capacity());
        while (buffer.hasRemaining()) {
            assertEquals(0, buffer.get());
        }
    }
View Full Code Here

            array.shortRemove();
        }
        assertArrayEquals(new short[]{}, array.toArray());
        assertEquals(0, array.length());
        assertEquals(offset, array.offset());
        ShortBuffer buffer = array.buffer();
        buffer.rewind().limit(buffer.capacity());
        while (buffer.hasRemaining()) {
            assertEquals(0, buffer.get());
        }
    }
View Full Code Here

        int offset = array.offset();
        array.clear();
        assertArrayEquals(new short[]{}, array.toArray());
        assertEquals(0, array.length());
        assertEquals(offset, array.offset());
        ShortBuffer buffer = array.buffer();
        buffer.rewind().limit(buffer.capacity());
        while (buffer.hasRemaining()) {
            assertEquals(0, buffer.get());
        }
    }
View Full Code Here

        array.addShort((short) 4);
        MutableShortArray backedByArray = MutableShortArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        ShortBuffer buffer = ByteBuffer.allocateDirect(Short.SIZE / Byte.SIZE * 8).asShortBuffer();
        MutableShortArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new short[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedShortArray bigger = UnboundedShortArray.copyOf(array);
View Full Code Here

TOP

Related Classes of java.nio.ShortBuffer

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.