Package java.nio

Examples of java.nio.DoubleBuffer


    }

    public void testEquals() {
        // equal to self
        assertTrue(buf.equals(buf));
        DoubleBuffer readonly = buf.asReadOnlyBuffer();
        assertTrue(buf.equals(readonly));
        DoubleBuffer duplicate = buf.duplicate();
        assertTrue(buf.equals(duplicate));

        // always false, if type mismatch
        assertFalse(buf.equals(Boolean.TRUE));

        assertTrue(buf.capacity() > 5);

        buf.limit(buf.capacity()).position(0);
        readonly.limit(readonly.capacity()).position(1);
        assertFalse(buf.equals(readonly));

        buf.limit(buf.capacity() - 1).position(0);
        duplicate.limit(duplicate.capacity()).position(0);
        assertFalse(buf.equals(duplicate));
    }
View Full Code Here


    public void testGetdoubleArray() {
        double array[] = new double[1];
        buf.clear();
        for (int i = 0; i < buf.capacity(); i++) {
            assertEquals(buf.position(), i);
            DoubleBuffer ret = buf.get(array);
            assertEquals(array[0], buf.get(i), 0.01);
            assertSame(ret, buf);
        }
        try {
            buf.get(array);
View Full Code Here

            // expected
        }
        assertEquals(buf.position(), 0);

        buf.clear();
        DoubleBuffer ret = buf.get(array, 0, array.length);
        assertEquals(buf.position(), buf.capacity());
        assertContentEquals(buf, array, 0, array.length);
        assertSame(ret, buf);
    }
View Full Code Here

        assertTrue(buf.hasArray());
    }

    public void testHashCode() {
        buf.clear();
        DoubleBuffer readonly = buf.asReadOnlyBuffer();
        DoubleBuffer duplicate = buf.duplicate();
        assertTrue(buf.hashCode() == readonly.hashCode());

        assertTrue(buf.capacity() > 5);
        duplicate.position(buf.capacity() / 2);
        assertTrue(buf.hashCode() != duplicate.hashCode());
    }
View Full Code Here

    public void testPutdouble() {

        buf.clear();
        for (int i = 0; i < buf.capacity(); i++) {
            assertEquals(buf.position(), i);
            DoubleBuffer ret = buf.put((double) i);
            assertEquals(buf.get(i), (double) i, 0.0);
            assertSame(ret, buf);
        }
        try {
            buf.put(0);
View Full Code Here

        buf.clear();
        for (int i = 0; i < buf.capacity(); i++) {
            assertEquals(buf.position(), i);
            array[0] = (double) i;
            DoubleBuffer ret = buf.put(array);
            assertEquals(buf.get(i), (double) i, 0.0);
            assertSame(ret, buf);
        }
        try {
            buf.put(array);
View Full Code Here

            // expected
        }
        assertEquals(buf.position(), 0);

        loadTestData2(array, 0, array.length);
        DoubleBuffer ret = buf.put(array, 0, array.length);
        assertEquals(buf.position(), buf.capacity());
        assertContentEquals(buf, array, 0, array.length);
        assertSame(ret, buf);
    }
View Full Code Here

    /*
     * Class under test for java.nio.DoubleBuffer put(java.nio.DoubleBuffer)
     */
    public void testPutDoubleBuffer() {
        DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());

        try {
            buf.put(buf);
            fail("Should throw Exception"); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // expected
        }
        try {
            buf.put(DoubleBuffer.allocate(buf.capacity() + 1));
            fail("Should throw Exception"); //$NON-NLS-1$
        } catch (BufferOverflowException e) {
            // expected
        }

        loadTestData2(other);
        other.clear();
        buf.clear();
        DoubleBuffer ret = buf.put(other);
        assertEquals(other.position(), other.capacity());
        assertEquals(buf.position(), buf.capacity());
        assertContentEquals(other, buf);
        assertSame(ret, buf);
    }
View Full Code Here

     */
    public void testPutintdouble() {
        buf.clear();
        for (int i = 0; i < buf.capacity(); i++) {
            assertEquals(buf.position(), 0);
            DoubleBuffer ret = buf.put(i, (double) i);
            assertEquals(buf.get(i), (double) i, 0.0);
            assertSame(ret, buf);
        }
        try {
            buf.put(-1, 0);
View Full Code Here

    public void testSlice() {
        assertTrue(buf.capacity() > 5);
        buf.position(1);
        buf.limit(buf.capacity() - 1);

        DoubleBuffer slice = buf.slice();
        assertEquals(buf.isReadOnly(), slice.isReadOnly());
        assertEquals(buf.isDirect(), slice.isDirect());
        assertEquals(buf.order(), slice.order());
        assertEquals(slice.position(), 0);
        assertEquals(slice.limit(), buf.remaining());
        assertEquals(slice.capacity(), buf.remaining());
        try {
            slice.reset();
            fail("Should throw Exception"); //$NON-NLS-1$
        } catch (InvalidMarkException e) {
            // expected
        }

        // slice share the same content with buf
        // FIXME:
        if (!slice.isReadOnly()) {
            loadTestData1(slice);
            assertContentLikeTestData1(buf, 1, 0, slice.capacity());
            buf.put(2, 500);
            assertEquals(slice.get(1), 500, 0.0);
        }
    }
View Full Code Here

TOP

Related Classes of java.nio.DoubleBuffer

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.