Java FloatBuffer to String toString(FloatBuffer buffer)

Here you can find the source of toString(FloatBuffer buffer)

Description

Returns a String representation of the remaining elements of the given buffer.

License

Open Source License

Parameter

Parameter Description
buffer The buffer

Return

A String representation of the buffer

Declaration

public static String toString(FloatBuffer buffer) 

Method Source Code

//package com.java2s;
/*/*from   w ww .jav  a 2s .c  om*/
 * www.javagl.de - Rendering
 * 
 * Copyright 2010-2016 Marco Hutter - http://www.javagl.de
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

import java.nio.FloatBuffer;

public class Main {
    /**
     * Returns a String representation of the remaining elements
     * of the given buffer.
     * 
     * @param buffer The buffer
     * @return A String representation of the buffer
     */
    public static String toString(FloatBuffer buffer) {
        return toString(buffer, buffer.remaining());
    }

    /**
     * Returns a String representation of the remaining elements
     * of the given buffer, up to the given maximum number of 
     * elements.
     * 
     * @param buffer The buffer
     * @param maxElements The maximum number of elements to include
     * @return A String representation of the buffer
     */
    public static String toString(FloatBuffer buffer, int maxElements) {
        StringBuilder sb = new StringBuilder();
        sb.append("(");
        int n = Math.min(buffer.remaining(), maxElements);
        for (int i = 0; i < n; i++) {
            sb.append(buffer.get(i));
            if (i < n - 1) {
                sb.append(", ");
            }
        }
        if (buffer.remaining() > maxElements) {
            sb.append("...");
        }
        sb.append(")");
        return sb.toString();
    }
}

Related

  1. print(FloatBuffer buffer)
  2. printFloatBuffer(FloatBuffer fb)
  3. show(final FloatBuffer buffer)
  4. toString(FloatBuffer buffer)
  5. toString(FloatBuffer floatBuffer)