/** Compare the remaining longs of this buffer to another long buffer's remaining longs. * * @param otherBuffer another long 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 long buffer. * @since Android 1.0 */ public int compareTo (LongBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; // BEGIN android-changed long thisLong, otherLong; while (compareRemaining > 0) { thisLong = get(thisPos); otherLong = otherBuffer.get(otherPos); if (thisLong != otherLong) { return thisLong < otherLong ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } // END android-changed return remaining() - otherBuffer.remaining(); }
/** Compare the remaining longs of this buffer to another long buffer's remaining longs. * * @param otherBuffer another long 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 long buffer. * @since Android 1.0 */ public int compareTo (LongBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; // BEGIN android-changed long thisLong, otherLong; while (compareRemaining > 0) { thisLong = get(thisPos); otherLong = otherBuffer.get(otherPos); if (thisLong != otherLong) { return thisLong < otherLong ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } // END android-changed return remaining() - otherBuffer.remaining(); }
/** Checks whether this long buffer is equal to another object. * <p> * If {@code other} is not a long buffer then {@code false} is returned. Two long buffers are equal if and only if their * remaining longs are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this long buffer. * @return {@code true} if this long buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof LongBuffer)) { return false; } LongBuffer otherBuffer = (LongBuffer)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 long buffer is equal to another object. * <p> * If {@code other} is not a long buffer then {@code false} is returned. Two long buffers are equal if and only if their * remaining longs are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this long buffer. * @return {@code true} if this long buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof LongBuffer)) { return false; } LongBuffer otherBuffer = (LongBuffer)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; }
/** * Take all of the remaining longs from the buffer and return them in an array. * * @param buffer the buffer to read * @return the longs */ public static long[] take(LongBuffer buffer) { final long[] longs = new long[buffer.remaining()]; buffer.get(longs); return longs; }
/** Writes all the remaining longs of the {@code src} long buffer to this buffer's current position, and increases both buffers' * position by the number of longs copied. * * @param src the source long 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 LongBuffer put (LongBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } long[] contents = new long[src.remaining()]; src.get(contents); put(contents); return this; }
/** Writes all the remaining longs of the {@code src} long buffer to this buffer's current position, and increases both buffers' * position by the number of longs copied. * * @param src the source long 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 LongBuffer put (LongBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } long[] contents = new long[src.remaining()]; src.get(contents); put(contents); return this; }
/** * Compare the remaining longs of this buffer to another long buffer's * remaining longs. * * @param otherBuffer * another long 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 long buffer. */ public int compareTo(LongBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; long thisLong, otherLong; while (compareRemaining > 0) { thisLong = get(thisPos); otherLong = otherBuffer.get(otherPos); if (thisLong != otherLong) { return thisLong < otherLong ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } return remaining() - otherBuffer.remaining(); }
/** Reads longs from the current position into the specified long array, starting from the specified offset, and increase the * position by the number of longs read. * * @param dest the target long array. * @param off the offset of the long array, must not be negative and not greater than {@code dest.length}. * @param len the number of longs 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 LongBuffer get (long[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)len + (long)off > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = off; i < off + len; i++) { dest[i] = get(); } return this; }
/** Reads longs from the current position into the specified long array, starting from the specified offset, and increase the * position by the number of longs read. * * @param dest the target long array. * @param off the offset of the long array, must not be negative and not greater than {@code dest.length}. * @param len the number of longs 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 LongBuffer get (long[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)len + (long)off > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = off; i < off + len; i++) { dest[i] = get(); } return this; }
/** * Checks whether this long buffer is equal to another object. * <p> * If {@code other} is not a long buffer then {@code false} is returned. Two * long buffers are equal if and only if their remaining longs are exactly * the same. Position, limit, capacity and mark are not considered. * * @param other * the object to compare with this long buffer. * @return {@code true} if this long buffer is equal to {@code other}, * {@code false} otherwise. */ @Override public boolean equals(Object other) { if (!(other instanceof LongBuffer)) { return false; } LongBuffer otherBuffer = (LongBuffer) 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; }
/** Writes longs from the given long array, starting from the specified offset, to the current position and increases the * position by the number of longs written. * * @param src the source long array. * @param off the offset of long array, must not be negative and not greater than {@code src.length}. * @param len the number of longs to write, must be no less than zero and not greater than {@code src.length - off}. * @return this buffer. * @exception BufferOverflowException if {@code remaining()} is less than {@code len}. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public LongBuffer put (long[] src, int off, int len) { int length = src.length; if (off < 0 || len < 0 || (long)len + (long)off > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferOverflowException(); } for (int i = off; i < off + len; i++) { put(src[i]); } return this; }
/** Writes longs from the given long array, starting from the specified offset, to the current position and increases the * position by the number of longs written. * * @param src the source long array. * @param off the offset of long array, must not be negative and not greater than {@code src.length}. * @param len the number of longs to write, must be no less than zero and not greater than {@code src.length - off}. * @return this buffer. * @exception BufferOverflowException if {@code remaining()} is less than {@code len}. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public LongBuffer put (long[] src, int off, int len) { int length = src.length; if (off < 0 || len < 0 || (long)len + (long)off > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferOverflowException(); } for (int i = off; i < off + len; i++) { put(src[i]); } return this; }
/** * Returns a {@code BitSet} corresponding to {@code longBuffer}, interpreted as a little-endian * sequence of bits. This method does not alter the {@code LongBuffer}. * @since 1.7 */ public static BitSet valueOf(LongBuffer longBuffer) { // The bulk get would mutate LongBuffer (even if we reset position later), and it's not // clear that's allowed. My assumption is that it's the long[] variant that's the common // case anyway, so copy the buffer into a long[]. long[] longs = new long[longBuffer.remaining()]; for (int i = 0; i < longs.length; ++i) { longs[i] = longBuffer.get(longBuffer.position() + i); } return BitSet.valueOf(longs); }
/** * Reads longs from the current position into the specified long array, * starting from the specified offset, and increase the position by the * number of longs read. * * @param dst * the target long array. * @param dstOffset * the offset of the long array, must not be negative and not * greater than {@code dst.length}. * @param longCount * the number of longs to read, must be no less than zero and not * greater than {@code dst.length - dstOffset}. * @return this buffer. * @exception IndexOutOfBoundsException * if either {@code dstOffset} or {@code longCount} is invalid. * @exception BufferUnderflowException * if {@code longCount} is greater than {@code remaining()}. */ public LongBuffer get(long[] dst, int dstOffset, int longCount) { Arrays.checkOffsetAndCount(dst.length, dstOffset, longCount); if (longCount > remaining()) { throw new BufferUnderflowException(); } for (int i = dstOffset; i < dstOffset + longCount; ++i) { dst[i] = get(); } return this; }
if (longCount > remaining()) { throw new BufferOverflowException();
public long[] getA8( ) { _arys++; // Get the lengths of lead & trailing zero sections, and the non-zero // middle section. int x = getInt(); if( x == -1 ) return null; int y = getInt(); // Non-zero in the middle int z = y==0 ? 0 : getInt();// Trailing zeros long[] buf = MemoryManager.malloc8(x+y+z); switch( get1() ) { // 1,2,4 or 8 for how the middle section is passed case 1: for( int i=x; i<x+y; i++ ) buf[i] = get1(); return buf; case 2: for( int i=x; i<x+y; i++ ) buf[i] = (short)get2(); return buf; case 4: for( int i=x; i<x+y; i++ ) buf[i] = get4(); return buf; case 8: break; default: throw H2O.fail(); } int sofar = x; while( sofar < x+y ) { LongBuffer as = _bb.asLongBuffer(); int more = Math.min(as.remaining(), x+y - sofar); as.get(buf, sofar, more); sofar += more; _bb.position(_bb.position() + as.position()*8); if( sofar < x+y ) getSp(Math.min(_bb.capacity()-7, (x+y-sofar)*8)); } return buf; } public double[] getA8d( ) {
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of longs to fill * @return the buffer instance */ public static LongBuffer fill(LongBuffer buffer, long value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put(value); } } return buffer; }