Refine search
/** Compare the remaining chars of this buffer to another char buffer's remaining chars. * * @param otherBuffer another char 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 char buffer. * @since Android 1.0 */ public int compareTo (CharBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; char 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 chars of this buffer to another char buffer's remaining chars. * * @param otherBuffer another char 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 char buffer. * @since Android 1.0 */ public int compareTo (CharBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; char 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(); }
/** Returns the character located at the specified index in the buffer. The index value is referenced from the current buffer * position. * * @param index the index referenced from the current buffer position. It must not be less than zero but less than the value * obtained from a call to {@code remaining()}. * @return the character located at the specified index (referenced from the current position) in the buffer. * @exception IndexOutOfBoundsException if the index is invalid. * @since Android 1.0 */ public final char charAt (int index) { if (index < 0 || index >= remaining()) { throw new IndexOutOfBoundsException(); } return get(position + index); }
/** Returns the character located at the specified index in the buffer. The index value is referenced from the current buffer * position. * * @param index the index referenced from the current buffer position. It must not be less than zero but less than the value * obtained from a call to {@code remaining()}. * @return the character located at the specified index (referenced from the current position) in the buffer. * @exception IndexOutOfBoundsException if the index is invalid. * @since Android 1.0 */ public final char charAt (int index) { if (index < 0 || index >= remaining()) { throw new IndexOutOfBoundsException(); } return get(position + index); }
/** Reads characters from this buffer and puts them into {@code target}. The number of chars that are copied is either the * number of remaining chars in this buffer or the number of remaining chars in {@code target}, whichever is smaller. * * @param target the target char buffer. * @throws IllegalArgumentException if {@code target} is this buffer. * @throws IOException if an I/O error occurs. * @throws ReadOnlyBufferException if no changes may be made to the contents of {@code target}. * @return the number of chars copied or -1 if there are no chars left to be read from this buffer. * @since Android 1.0 */ public int read (CharBuffer target) throws IOException { if (target == this) { throw new IllegalArgumentException(); } if (remaining() == 0) { return target.remaining() == 0 ? 0 : -1; } int result = Math.min(target.remaining(), remaining()); char[] chars = new char[result]; get(chars); target.put(chars); return result; } }
/** Reads characters from this buffer and puts them into {@code target}. The number of chars that are copied is either the * number of remaining chars in this buffer or the number of remaining chars in {@code target}, whichever is smaller. * * @param target the target char buffer. * @throws IllegalArgumentException if {@code target} is this buffer. * @throws IOException if an I/O error occurs. * @throws ReadOnlyBufferException if no changes may be made to the contents of {@code target}. * @return the number of chars copied or -1 if there are no chars left to be read from this buffer. * @since Android 1.0 */ public int read (CharBuffer target) throws IOException { if (target == this) { throw new IllegalArgumentException(); } if (remaining() == 0) { return target.remaining() == 0 ? 0 : -1; } int result = Math.min(target.remaining(), remaining()); char[] chars = new char[result]; get(chars); target.put(chars); return result; } }
/** Checks whether this char buffer is equal to another object. * <p> * If {@code other} is not a char buffer then {@code false} is returned. Two char buffers are equal if and only if their * remaining chars are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this char buffer. * @return {@code true} if this char buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof CharBuffer)) { return false; } CharBuffer otherBuffer = (CharBuffer)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 char buffer is equal to another object. * <p> * If {@code other} is not a char buffer then {@code false} is returned. Two char buffers are equal if and only if their * remaining chars are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this char buffer. * @return {@code true} if this char buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof CharBuffer)) { return false; } CharBuffer otherBuffer = (CharBuffer)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 all the remaining chars of the {@code src} char buffer to this buffer's current position, and increases both buffers' * position by the number of chars copied. * * @param src the source char 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 CharBuffer put (CharBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } char[] contents = new char[src.remaining()]; src.get(contents); put(contents); return this; }
/** Writes all the remaining chars of the {@code src} char buffer to this buffer's current position, and increases both buffers' * position by the number of chars copied. * * @param src the source char 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 CharBuffer put (CharBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } char[] contents = new char[src.remaining()]; src.get(contents); put(contents); return this; }
/** * Returns the character located at the specified index in the buffer. The * index value is referenced from the current buffer position. * * @param index * the index referenced from the current buffer position. It must * not be less than zero but less than the value obtained from a * call to {@code remaining()}. * @return the character located at the specified index (referenced from the * current position) in the buffer. * @exception IndexOutOfBoundsException * if the index is invalid. */ public final char charAt(int index) { if (index < 0 || index >= remaining()) { throw new IndexOutOfBoundsException("index=" + index + ", remaining()=" + remaining()); } return get(position + index); }
/** * Compare the remaining chars of this buffer to another char * buffer's remaining chars. * * @param otherBuffer * another char 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 char buffer. */ public int compareTo(CharBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; char 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(); }
/** Reads chars from the current position into the specified char array, starting from the specified offset, and increases the * position by the number of chars read. * * @param dest the target char array. * @param off the offset of the char array, must not be negative and not greater than {@code dest.length}. * @param len The number of chars to read, must be no less than zero and no 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 CharBuffer get (char[] 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 chars from the current position into the specified char array, starting from the specified offset, and increases the * position by the number of chars read. * * @param dest the target char array. * @param off the offset of the char array, must not be negative and not greater than {@code dest.length}. * @param len The number of chars to read, must be no less than zero and no 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 CharBuffer get (char[] 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; }
/** * Checks whether this char buffer is equal to another object. * <p> * If {@code other} is not a char buffer then {@code false} is returned. Two * char buffers are equal if and only if their remaining chars are exactly * the same. Position, limit, capacity and mark are not considered. * * @param other * the object to compare with this char buffer. * @return {@code true} if this char buffer is equal to {@code other}, * {@code false} otherwise. */ @Override public boolean equals(Object other) { if (!(other instanceof CharBuffer)) { return false; } CharBuffer otherBuffer = (CharBuffer) 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; }