/** Reads shorts from the current position into the specified short array and increases the position by the number of shorts * read. * <p> * Calling this method has the same effect as {@code get(dest, 0, dest.length)}. * </p> * * @param dest the destination short array. * @return this buffer. * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}. * @since Android 1.0 */ public ShortBuffer get (short[] dest) { return get(dest, 0, dest.length); }
/** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash * code. * * @return the hash code calculated from the remaining shorts. * @since Android 1.0 */ public int hashCode () { int myPosition = position; int hash = 0; while (myPosition < limit) { hash = hash + get(myPosition++); } return hash; }
/** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash * code. * * @return the hash code calculated from the remaining shorts. * @since Android 1.0 */ public int hashCode () { int myPosition = position; int hash = 0; while (myPosition < limit) { hash = hash + get(myPosition++); } return hash; }
/** Reads shorts from the current position into the specified short array and increases the position by the number of shorts * read. * <p> * Calling this method has the same effect as {@code get(dest, 0, dest.length)}. * </p> * * @param dest the destination short array. * @return this buffer. * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}. * @since Android 1.0 */ public ShortBuffer get (short[] dest) { return get(dest, 0, dest.length); }
byte[] bytes = {}; short[] shorts = new short[bytes.length/2]; // to turn bytes to shorts as either big endian or little endian. ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts); // to turn shorts back to bytes. byte[] bytes2 = new byte[shortsA.length * 2]; ByteBuffer.wrap(bytes2).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(shortsA);
/** Checks whether this short buffer is equal to another object. * <p> * If {@code other} is not a short buffer then {@code false} is returned. Two short buffers are equal if and only if their * remaining shorts are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this short buffer. * @return {@code true} if this short buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof ShortBuffer)) { return false; } ShortBuffer otherBuffer = (ShortBuffer)other; if (remaining() != otherBuffer.remaining()) { return false; } int myPosition = position; int otherPosition = otherBuffer.position; boolean equalSoFar = true; while (equalSoFar && (myPosition < limit)) { equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); } return equalSoFar; }
/** Checks whether this short buffer is equal to another object. * <p> * If {@code other} is not a short buffer then {@code false} is returned. Two short buffers are equal if and only if their * remaining shorts are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this short buffer. * @return {@code true} if this short buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof ShortBuffer)) { return false; } ShortBuffer otherBuffer = (ShortBuffer)other; if (remaining() != otherBuffer.remaining()) { return false; } int myPosition = position; int otherPosition = otherBuffer.position; boolean equalSoFar = true; while (equalSoFar && (myPosition < limit)) { equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); } return equalSoFar; }
@Override public UShortIndexer get(long[] indices, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { s[offset + n] = buffer.get((int)index(indices) + n) & 0xFFFF; } return this; }
/** Reads shorts from the current position into the specified short array, starting from the specified offset, and increases the * position by the number of shorts read. * * @param dest the target short array. * @param off the offset of the short array, must not be negative and not greater than {@code dest.length}. * @param len the number of shorts to read, must be no less than zero and not greater than {@code dest.length - off}. * @return this buffer. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}. * @since Android 1.0 */ public ShortBuffer get (short[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = off; i < off + len; i++) { dest[i] = get(); } return this; }
/** Reads shorts from the current position into the specified short array, starting from the specified offset, and increases the * position by the number of shorts read. * * @param dest the target short array. * @param off the offset of the short array, must not be negative and not greater than {@code dest.length}. * @param len the number of shorts to read, must be no less than zero and not greater than {@code dest.length - off}. * @return this buffer. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}. * @since Android 1.0 */ public ShortBuffer get (short[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = off; i < off + len; i++) { dest[i] = get(); } return this; }
@Override public Bfloat16Indexer get(long[] indices, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { h[offset + n] = toFloat(buffer.get((int)index(indices) + n)); } return this; }
/** Writes all the remaining shorts of the {@code src} short buffer to this buffer's current position, and increases both * buffers' position by the number of shorts copied. * * @param src the source short buffer. * @return this buffer. * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}. * @exception IllegalArgumentException if {@code src} is this buffer. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public ShortBuffer put (ShortBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } short[] contents = new short[src.remaining()]; src.get(contents); put(contents); return this; }
/** Writes all the remaining shorts of the {@code src} short buffer to this buffer's current position, and increases both * buffers' position by the number of shorts copied. * * @param src the source short buffer. * @return this buffer. * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}. * @exception IllegalArgumentException if {@code src} is this buffer. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public ShortBuffer put (ShortBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } short[] contents = new short[src.remaining()]; src.get(contents); put(contents); return this; }
/** * Queues remaining data from {@code buffer}, and advances its position by the number of bytes * consumed. * * @param buffer A {@link ShortBuffer} containing input data between its position and limit. */ public void queueInput(ShortBuffer buffer) { int framesToWrite = buffer.remaining() / channelCount; int bytesToWrite = framesToWrite * channelCount * 2; inputBuffer = ensureSpaceForAdditionalFrames(inputBuffer, inputFrameCount, framesToWrite); buffer.get(inputBuffer, inputFrameCount * channelCount, bytesToWrite / 2); inputFrameCount += framesToWrite; processStreamInput(); }
/** Compare the remaining shorts of this buffer to another short buffer's remaining shorts. * * @param otherBuffer another short buffer. * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value * if this is greater than {@code otherBuffer}. * @exception ClassCastException if {@code otherBuffer} is not a short buffer. * @since Android 1.0 */ public int compareTo (ShortBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; short thisByte, otherByte; while (compareRemaining > 0) { thisByte = get(thisPos); otherByte = otherBuffer.get(otherPos); if (thisByte != otherByte) { return thisByte < otherByte ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } return remaining() - otherBuffer.remaining(); }
/** Compare the remaining shorts of this buffer to another short buffer's remaining shorts. * * @param otherBuffer another short buffer. * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value * if this is greater than {@code otherBuffer}. * @exception ClassCastException if {@code otherBuffer} is not a short buffer. * @since Android 1.0 */ public int compareTo (ShortBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; short thisByte, otherByte; while (compareRemaining > 0) { thisByte = get(thisPos); otherByte = otherBuffer.get(otherPos); if (thisByte != otherByte) { return thisByte < otherByte ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } return remaining() - otherBuffer.remaining(); }
/** Copies the indices from the Mesh to the short array. The short array must be large enough to hold destOffset + count * indices. * @param srcOffset the zero-based offset of the first index to fetch * @param count the total amount of indices to copy * @param indices the array to copy the indices to * @param destOffset the offset in the indices array to start copying */ public void getIndices (int srcOffset, int count, short[] indices, int destOffset) { int max = getNumIndices(); if (count < 0) count = max - srcOffset; if (srcOffset < 0 || srcOffset >= max || srcOffset + count > max) throw new IllegalArgumentException("Invalid range specified, offset: " + srcOffset + ", count: " + count + ", max: " + max); if ((indices.length - destOffset) < count) throw new IllegalArgumentException("not enough room in indices array, has " + indices.length + " shorts, needs " + count); int pos = getIndicesBuffer().position(); getIndicesBuffer().position(srcOffset); getIndicesBuffer().get(indices, destOffset, count); getIndicesBuffer().position(pos); }
/** Copies the indices from the Mesh to the short array. The short array must be large enough to hold destOffset + count * indices. * @param srcOffset the zero-based offset of the first index to fetch * @param count the total amount of indices to copy * @param indices the array to copy the indices to * @param destOffset the offset in the indices array to start copying */ public void getIndices (int srcOffset, int count, short[] indices, int destOffset) { int max = getNumIndices(); if (count < 0) count = max - srcOffset; if (srcOffset < 0 || srcOffset >= max || srcOffset + count > max) throw new IllegalArgumentException("Invalid range specified, offset: " + srcOffset + ", count: " + count + ", max: " + max); if ((indices.length - destOffset) < count) throw new IllegalArgumentException("not enough room in indices array, has " + indices.length + " shorts, needs " + count); int pos = getIndicesBuffer().position(); getIndicesBuffer().position(srcOffset); getIndicesBuffer().get(indices, destOffset, count); getIndicesBuffer().position(pos); }
public Int16Array copy (ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } }
public Int16Array copy (ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } }