@Override public ByteRange set(byte[] bytes) { if (null == bytes) return unset(); clearHashCache(); this.bytes = bytes; this.offset = 0; this.length = bytes.length; return this; }
@Override public PositionedByteRange get(int index, byte[] dst) { super.get(index, dst); return this; }
@Override public int hashCode() { if (isHashCached()) {// hash is already calculated and cached return hash; } if (this.isEmpty()) {// return 0 for empty ByteRange hash = 0; return hash; } int off = offset; hash = 0; for (int i = 0; i < length; i++) { hash = 31 * hash + bytes[off++]; } return hash; }
@Override public PositionedByteRange set(byte[] bytes, int offset, int length) { this.position = 0; super.set(bytes, offset, length); limit = length; return this; }
@Override public ByteRange setLength(int length) { clearHashCache(); this.length = length; return this; }
@Override public boolean isEmpty() { return isEmpty(this); }
/** * Update the beginning of this range. {@code offset + length} may not be * greater than {@code bytes.length}. Resets {@code position} to 0. * * @param offset * the new start of this range. * @return this. */ @Override public PositionedByteRange setOffset(int offset) { this.position = 0; super.setOffset(offset); return this; }
/** * Update the length of this range. {@code offset + length} should not be * greater than {@code bytes.length}. If {@code position} is greater than the * new {@code length}, sets {@code position} to {@code length}. * * @param length * The new length of this range. * @return this. */ @Override public PositionedByteRange setLength(int length) { this.position = Math.min(position, length); super.setLength(length); return this; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof ByteRange)) { return false; } return compareTo((ByteRange) obj) == 0; }
@Override public PositionedByteRange set(byte[] bytes) { this.position = 0; super.set(bytes); this.limit = bytes.length; return this; }
@Override public ByteRange setOffset(int offset) { clearHashCache(); this.offset = offset; return this; }
@Override public boolean isEmpty() { return isEmpty(this); }
/** * Update the beginning of this range. {@code offset + length} may not be * greater than {@code bytes.length}. Resets {@code position} to 0. * * @param offset * the new start of this range. * @return this. */ @Override public PositionedByteRange setOffset(int offset) { this.position = 0; super.setOffset(offset); return this; }
/** * Update the length of this range. {@code offset + length} should not be * greater than {@code bytes.length}. If {@code position} is greater than the * new {@code length}, sets {@code position} to {@code length}. * * @param length * The new length of this range. * @return this. */ @Override public PositionedByteRange setLength(int length) { this.position = Math.min(position, length); super.setLength(length); return this; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof ByteRange)) { return false; } return compareTo((ByteRange) obj) == 0; }
@Override public ByteRange set(byte[] bytes, int offset, int length) { if (null == bytes) return unset(); clearHashCache(); this.bytes = bytes; this.offset = offset; this.length = length; return this; }
@Override public PositionedByteRange set(int capacity) { this.position = 0; super.set(capacity); this.limit = capacity; return this; }
@Override public PositionedByteRange get(int index, byte[] dst, int offset, int length) { super.get(index, dst, offset, length); return this; }
@Override public int hashCode() { if (isHashCached()) {// hash is already calculated and cached return hash; } if (this.isEmpty()) {// return 0 for empty ByteRange hash = 0; return hash; } int off = offset; hash = 0; for (int i = 0; i < length; i++) { hash = 31 * hash + bytes[off++]; } return hash; }
@Override public ByteRange setOffset(int offset) { clearHashCache(); this.offset = offset; return this; }