Java 8 DoubleBuffer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DoubleBuffer class.

This code example shows how to use the following methods:capacity, rewind, get, hasArray
	 * @param buffer {@link DoubleBuffer} the data source. 
	 * @return double array containing the data of the buffer. 
	 */ 
	public static double[] getDoubleArrayFromBuffer(DoubleBuffer buffer) {
		double[] array = null;
		if (buffer.hasArray()) {
			array = buffer.array();
		} else { 
			buffer.rewind();
			array = new double[buffer.capacity()];
			buffer.get(array);		
		} 
		return array;
	} 
 
	/** 
	 * Creates a float array from the provided {@link FloatBuffer}. 
	 *  
	 * @param buffer {@link FloatBuffer} the data source. 
	 * @return float array containing the data of the buffer. 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:position, remaining
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	public static void zeroBuffer(DoubleBuffer b) {
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	private static native void zeroBuffer0(Buffer b, long off, long size);
 
	/** 
	 * Returns the memory address of the specified buffer. 
	 * 
	 * @param buffer the buffer 
	 * 
	 * @return the memory address 
	 */ 
	static native long getBufferAddress(Buffer buffer);
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasRemaining, limit, position, remaining, get
			pos += nr;
			len -= nr;
			ret += nr;
			if (len == 0)
			{ 
				if (remaining == 0 && !tb.hasRemaining())
					copyFileIntoBuffer(); 
				return ret;
			} 
		} 
		// Now copy ints directly from buffer 
		while (tb.remaining() < len)
		{ 
			int nr = tb.remaining();
			tb.get(dst, pos, nr);
			pos += nr;
			len -= nr;
			ret += nr;
			if (!copyFileIntoBuffer()) 
				return ret;

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:capacity, limit, asReadOnlyBuffer, duplicate, equals
        } 
    } 
 
    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));
 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:position, get, put
   * @param v 
   */ 
  private static void normalize(final DoubleBuffer v) {
    double r;
 
    final int vPos = v.position();
 
    r = Math.sqrt(v.get(0+vPos) * v.get(0+vPos) +
                  v.get(1+vPos) * v.get(1+vPos) +
                  v.get(2+vPos) * v.get(2+vPos));
    if ( r == 0.0 )
      return; 
 
    r = 1.0 / r;
 
    v.put(0+vPos, v.get(0+vPos) * r);
    v.put(1+vPos, v.get(1+vPos) * r);
    v.put(2+vPos, v.get(2+vPos) * r);
 
    return; 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:limit, position, remaining, isDirect, order
			return doNoCopyWrap(buffer);
		return buffer;
	} 
 
	public static DoubleBuffer wrapNoCopyDirect(DoubleBuffer buffer) {
		if (!buffer.isDirect())
			return doNoCopyWrap(buffer);
		return buffer;
	} 
 
	public static void copy(ByteBuffer src, ByteBuffer dst) {
		if (dst != null && !dst.isDirect()) {
			int saved_position = dst.position();
			dst.put(src);
			dst.position(saved_position);
		} 
	} 
 
	public static void copy(ShortBuffer src, ShortBuffer dst) {
		if (dst != null && !dst.isDirect()) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:position, remaining
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	public static void zeroBuffer(DoubleBuffer b) {
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	private static native void zeroBuffer0(Buffer b, long off, long size);
 
	/** 
	 * Returns the memory address of the specified buffer. 
	 * 
	 * @param buffer the buffer 
	 * 
	 * @return the memory address 
	 */ 
	static native long getBufferAddress(Buffer buffer);
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:limit, position, array, hasArray
     * 
     * @param buffer the Buffer to reference or copy 
     * @see #put(double[]) 
     */ 
    public DoublePointer(DoubleBuffer buffer) {
        super(buffer);
        if (buffer != null && buffer.hasArray()) {
            double[] array = buffer.array();
            allocateArray(array.length);
            put(array);
            position(buffer.position());
            limit(buffer.limit());
        } 
    } 
    /** 
     * Allocates a native {@code double} array of the given size. 
     * 
     * @param size the number of {@code double} elements to allocate 
     */ 
    public DoublePointer(int size) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:capacity, clear
    private static DoubleBuffer allocateVertexBuffer(int numVertices, DoubleBuffer buffer)
    { 
        int numCoords = 2 * numVertices;
 
        if (buffer != null)
            buffer.clear();
 
        if (buffer == null || buffer.capacity() < numCoords)
            buffer = Buffers.newDirectDoubleBuffer(numCoords);
 
        return buffer;
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:remaining, get
		return get(dst, 0, dst.length);
	} 
 
	public final int get(double[] dst, int offset, int len) throws IOException
	{ 
		if (tb.remaining() < len)
			len = tb.remaining();
		tb.get(dst, offset, len);
		return len;
	} 
 
	public int get(int index, double[] dst) throws IOException
	{ 
		return get(index, dst, 0, dst.length);
	} 
 
	public final int get(int index, double[] dst, int offset, int len) throws IOExceptionfc.position(index * 4L);
		return get(dst, offset, len);
5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 DoubleBuffer Questions & Answers:

See Code Examples for Java 8 DoubleBuffer Methods: