@Override public void copyTo(StringValue target) { target.len = this.len; target.hashCode = this.hashCode; target.ensureSize(this.len); System.arraycopy(this.value, 0, target.value, 0, this.len); }
@Override public void copyTo(StringValue target) { target.len = this.len; target.hashCode = this.hashCode; target.ensureSize(this.len); System.arraycopy(this.value, 0, target.value, 0, this.len); }
/** * Sets the value of the StringValue to a substring of the given value. * * @param chars The new string value (as a character array). * @param offset The position to start the substring. * @param len The length of the substring. */ public void setValue(char[] chars, int offset, int len) { Validate.notNull(chars); if (offset < 0 || len < 0 || offset > chars.length - len) { throw new IndexOutOfBoundsException(); } ensureSize(len); System.arraycopy(chars, offset, this.value, 0, len); this.len = len; this.hashCode = 0; }
/** * Sets the value of the StringValue to a substring of the given value. * * @param chars The new string value (as a character array). * @param offset The position to start the substring. * @param len The length of the substring. */ public void setValue(char[] chars, int offset, int len) { Validate.notNull(chars); if (offset < 0 || len < 0 || offset > chars.length - len) { throw new IndexOutOfBoundsException(); } ensureSize(len); System.arraycopy(chars, offset, this.value, 0, len); this.len = len; this.hashCode = 0; }
/** * Sets the value of this <code>StringValue</code>, assuming that the binary data is ASCII coded. The n-th character of the * <code>StringValue</code> corresponds directly to the n-th byte in the given array after the offset. * * @param bytes The binary character data. * @param offset The offset in the array. * @param len The number of bytes to read from the array. */ public void setValueAscii(byte[] bytes, int offset, int len) { if (bytes == null) { throw new NullPointerException("Bytes must not be null"); } if (len < 0 | offset < 0 | offset > bytes.length - len) { throw new IndexOutOfBoundsException(); } ensureSize(len); this.len = len; this.hashCode = 0; final char[] chars = this.value; for (int i = 0, limit = offset + len; offset < limit; offset++, i++) { chars[i] = (char) (bytes[offset] & 0xff); } }
/** * Sets the value of this <code>StringValue</code>, assuming that the binary data is ASCII coded. The n-th character of the * <code>StringValue</code> corresponds directly to the n-th byte in the given array after the offset. * * @param bytes The binary character data. * @param offset The offset in the array. * @param len The number of bytes to read from the array. */ public void setValueAscii(byte[] bytes, int offset, int len) { if (bytes == null) { throw new NullPointerException("Bytes must not be null"); } if (len < 0 | offset < 0 | offset > bytes.length - len) { throw new IndexOutOfBoundsException(); } ensureSize(len); this.len = len; this.hashCode = 0; final char[] chars = this.value; for (int i = 0, limit = offset + len; offset < limit; offset++, i++) { chars[i] = (char) (bytes[offset] & 0xff); } }
/** * Sets the value of the StringValue to a substring of the given string. * * @param value The new string value. * @param offset The position to start the substring. * @param len The length of the substring. */ public void setValue(CharSequence value, int offset, int len) { Validate.notNull(value); if (offset < 0 || len < 0 || offset > value.length() - len) { throw new IndexOutOfBoundsException("offset: " + offset + " len: " + len + " value.len: " + len); } ensureSize(len); this.len = len; for (int i = 0; i < len; i++) { this.value[i] = value.charAt(offset + i); } this.len = len; this.hashCode = 0; }
/** * Sets the value of the StringValue to a substring of the given string. * * @param value The new string value. * @param offset The position to start the substring. * @param len The length of the substring. */ public void setValue(CharSequence value, int offset, int len) { Validate.notNull(value); if (offset < 0 || len < 0 || offset > value.length() - len) { throw new IndexOutOfBoundsException("offset: " + offset + " len: " + len + " value.len: " + len); } ensureSize(len); this.len = len; for (int i = 0; i < len; i++) { this.value[i] = value.charAt(offset + i); } this.len = len; this.hashCode = 0; }
/** * Sets the contents of this string to the contents of the given <tt>CharBuffer</tt>. * The characters between the buffer's current position (inclusive) and the buffer's * limit (exclusive) will be stored in this string. * * @param buffer The character buffer to read the characters from. */ public void setValue(CharBuffer buffer) { Validate.notNull(buffer); final int len = buffer.length(); ensureSize(len); buffer.get(this.value, 0, len); this.len = len; this.hashCode = 0; }
/** * Sets the contents of this string to the contents of the given <tt>CharBuffer</tt>. * The characters between the buffer's current position (inclusive) and the buffer's * limit (exclusive) will be stored in this string. * * @param buffer The character buffer to read the characters from. */ public void setValue(CharBuffer buffer) { Validate.notNull(buffer); final int len = buffer.length(); ensureSize(len); buffer.get(this.value, 0, len); this.len = len; this.hashCode = 0; }
ensureSize(len); final char[] data = this.value;
ensureSize(len); final char[] data = this.value;