public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { // TODO create more efficient impl return ByteBuffer.wrap(bs.toArray()); } } }
public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { // TODO create more efficient impl return ByteBuffer.wrap(bs.toArray()); } } }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
@Override public int hashCode() { int hash = 1; if (isBackedByArray()) { byte[] data = getBackingArray(); int end = offset() + length(); for (int i = offset(); i < end; i++) hash = (31 * hash) + data[i]; } else { for (int i = 0; i < length(); i++) hash = (31 * hash) + byteAt(i); } return hash; }
@Override public int hashCode() { int hash = 1; if (isBackedByArray()) { byte[] data = getBackingArray(); int end = offset() + length(); for (int i = offset(); i < end; i++) hash = (31 * hash) + data[i]; } else { for (int i = 0; i < length(); i++) hash = (31 * hash) + byteAt(i); } return hash; }