public class XString extends Object implements Appendable, CharSequence
XString provides the
ability to manipulate String values without generating the garbage associated with
Java's String implementation.
XStringXString created is immutable from the point that it is initialized. Once initialized
via a setter method, an XString is threadsafe.
However, not all XStrings are threadsafe or immutable: platform created XString
may not always be immutable. Applications can test for immutability and initialization of an XString
via canMutate() and hasValue(). When dealing with XStrings returned
by platform classes the documentation of the class should be consulted to determine what thread safety and
immutability guarantees are provided. In cases where the platform doesn't guaranteed immutability, applications
can make use of getTo(XString) to create an immutable version of the XString if
needs be.
XString implements Appendable and CharSequence. Currently
XString only supports ascii encdodable characters when working with these interfaces, or any
of the other char based methods it supports. An XString can opaquely wrap and and pass
non ascii encodabled XStrings, but for performance reasons direct character manipulation of
non ascii text is not supported.
XString implements CharSequence. The hashCode() and equals(Object)
implementations of this view and those returned by subSequence(int, int) are not guaranteed to
be remain stable when an XString is mutable or not yet initialized.
XStrings that are immutable obey the contract for object equality and hashCode. Additionally,
an XString will equal another subSequence(int, int) if they have the same
value. An XString will not equal another String of the same value.XStrings are mutable; they along with their backing storages are not safe for
mutative access by multiple threads.| Modifier and Type | Class and Description |
|---|---|
static class |
XString.ImmutableExtension
|
| Modifier and Type | Method and Description |
|---|---|
XString |
append(boolean value)
Appends the given boolean value in string format to the end of an
XString. |
XString |
append(byte[] value)
Append the given bytes bytes to the end of this
XString. |
XString |
append(byte[] value,
int valueOffset,
int valueLength)
Append the given bytes bytes to the end of this
XString. |
XString |
append(ByteBuffer value)
Appends the contents of the given
ByteBuffer into this XString. |
XString |
append(ByteBuffer value,
int valueOffset,
int valueLength)
Appends the contents of the given
ByteBuffer into this XString. |
XString |
append(char value)
Append the given char to the end of this
XString. |
XString |
append(char[] value)
Append the given char [] to the end of this
XString. |
XString |
append(char[] value,
int valueOffset,
int valueLength)
Append the given char [] to the end of this
XString. |
XString |
append(CharSequence value)
Append the given
CharSequence to the end of this XString. |
Appendable |
append(CharSequence value,
int start,
int end) |
XString |
append(long value)
Appends the given long value in String format to the end of this
XString. |
XString |
append(XString value)
|
boolean |
canMutate()
Checks if an
XString can be mutated. |
int |
capacity()
Returns the capacity of the backing storage
|
char |
charAt(int index)
Returns the character at the given position.
|
void |
clear()
Clear the value of the
XString. |
void |
clear(boolean freeMemory)
Clear an
XString. |
void |
close()
This method should be invoked when the user is done working with
an XString that it owns i.e. one that it has created for its own
use or one that has been handed to the user for ownership by the
Rumi runtime.
|
int |
compareTo(CharSequence other)
Compares two strings lexicographically.
|
void |
copyFrom(char[] val)
Set the value of the String to the given characters.
|
void |
copyFrom(XString value)
|
void |
copyFromMemory(long addr,
int len)
Copy a serialized string from a memory address into an
XString. |
void |
copyFromNative(long addr,
int len)
Copy a serialized string from a memory address into an
XString. |
int |
copyInto(ByteBuffer target,
int offset)
Deprecated.
Use
getTo(ByteBuffer, int) instead |
int |
copyInto(IOBuffer target,
int offset)
Deprecated.
Use
getTo(IOBuffer, int) instead |
int |
copyInto(IOElasticBuffer target,
int offset)
Deprecated.
Use
getTo(IOElasticBuffer, int) instead |
int |
copyInto(XString val)
Deprecated.
Use
#getTo(XString} instead |
static XString |
create()
Create a mutable, uninitialized
XString. |
static XString |
create(boolean mutable,
int initialCapacity)
Deprecated.
Please use create(int, boolean) instead
|
static XString |
create(int initialCapacity)
Create an
XString. |
static XString |
create(int initialCapacity,
boolean mutable)
Create an
XString. |
static XString |
create(short initialCapacity)
Create an
XString. |
static XString |
create(short initialCapacity,
boolean mutable)
Create an
XString. |
static XString |
create(String value)
|
static XString |
create(String value,
boolean mutable)
|
void |
ensureCapacity(short val)
Ensure an
XStrings backing storage is large enough to accommodate data |
boolean |
equals(Object object)
|
long |
getAsLong()
Get an
XString as a long value. |
long |
getAsLong(int radix)
Get an
XString as a long value. |
long |
getAsLongDecimal()
Get an
XString as a long value. |
String |
getAsString()
|
int |
getSerializedLength()
Deprecated.
Use
serializedLength() instead |
int |
getTo(byte[] val,
int offset)
Copy the serialized bytes of an
XString into an byte array |
int |
getTo(ByteBuffer target,
int offset)
Copy the serialized bytes of an
XString to a ByteBuffer |
int |
getTo(IOBuffer target,
int offset)
|
int |
getTo(IOElasticBuffer target,
int offset)
Copy the serialized bytes of an
XString to an IOElasticBuffer |
int |
getTo(long addr,
int offset)
Copy the serialized bytes of an
XString to a memory location |
int |
getTo(XString val)
|
String |
getValue()
|
long |
getValueAsLong()
Zero garbage method to parses the string as a long value.
|
int |
hashCode()
Return the current hash code of this
XString. |
boolean |
hasValue()
Get if an
XStringhas a value set |
int |
indexOf(char c)
Returns the first index of the given character in an
XString. |
int |
indexOf(char c,
int offset)
Returns the first index of the given character in q
XString
starting from the provided offset. |
int |
indexOf(CharSequence str)
Returns the first index of the given character sequence in an
XString |
int |
indexOf(CharSequence str,
int offset)
Returns the first index of the given character sequence in an
XString
starting from the provided offset. |
void |
initialize(String value)
Initializes an uninitialized
XString with the given String value. |
void |
initializeFrom(XString value)
Initialize an uninitialized
XString with the given value. |
boolean |
isEmpty()
Checks if an
XString is empty |
boolean |
isImmutable()
Test if this
XString cannot be mutated. |
boolean |
isInitialized()
Deprecated.
Use
hasValue() instead |
boolean |
isMutable()
Get if an
XString was marked as mutable on creation. |
boolean |
isNull()
Return if the
XString's represents a null string. |
int |
length()
Returns the length in characters of the XString.
|
long |
nativeAddress()
Return an
XString's backing store address. |
void |
reset()
Deprecated.
Use
clear() instead |
int |
serializedLength()
Return an
XString's serialized length. |
void |
setCharAt(int position,
char value)
Replaces the character at the given index in a with the provided value.
|
void |
setFrom(byte[] value)
Set the value of the String to the given bytes.
|
void |
setFrom(byte[] value,
int valueOffset,
int valueLength)
Set the value of the String to the given bytes.
|
void |
setFrom(ByteBuffer source)
Copy a serialized string from a
ByteBuffer into an XString. |
void |
setFrom(ByteBuffer source,
int offset,
int len)
Copy a serialized string from a
ByteBuffer into an XString. |
void |
setFrom(char[] value)
Set the value of the String to the given characters.
|
void |
setFrom(char[] value,
int valueOffset,
int valueLength)
Set the value of the String to the given characters.
|
void |
setFrom(CharSequence value)
Set the value of the
XString to that of the given CharSequence |
void |
setFrom(IOBuffer source,
int offset,
int len)
|
void |
setFrom(IOElasticBuffer source,
int offset,
int len)
Copy a serialized string from an
IOElasticBuffer into an XString. |
void |
setFrom(long value)
Set the raw value of the String to the String value of the given long in decimal radix.
|
void |
setFrom(long addr,
int offset,
int len)
Copy a serialized string from a memory address into an
XString. |
void |
setFrom(String val)
Set the value from a
String. |
void |
setFrom(XString value)
|
void |
setFrom(XStringDeserializer value)
Set the value of an
XString from an XStringDeserializer |
void |
setValue(byte[] value)
Set the value of the String to the given bytes.
|
void |
setValue(byte[] value,
int valueOffset,
int valueLength)
Set the value of the String to the given bytes.
|
void |
setValue(ByteBuffer value)
Copy a serialized string from a
ByteBuffer into an XString. |
void |
setValue(ByteBuffer value,
int offset,
int len)
Copy a serialized string from a
ByteBuffer into an XString. |
void |
setValue(char[] value)
Set the value of the String to the given chars.
|
void |
setValue(char[] value,
int valueOffset,
int valueLength)
Set the value of the String to the given chars.
|
void |
setValue(CharSequence value)
Set the value of the String to the given char sequence.
|
void |
setValue(IOBuffer value,
int offset,
int len)
|
void |
setValue(IOElasticBuffer value,
int offset,
int len)
Copy a serialized string from an
IOElasticBuffer into an XString. |
void |
setValue(long value)
Set the raw value of the String to the String value of the given long in decimal radix.
|
void |
setValue(long addr,
int offset,
int len)
Copy a serialized string from a memory address into an
XString. |
void |
setValue(String value)
Set the value of from a
String
Equivalent to invoking setFrom(String) |
void |
setValue(XString value)
|
void |
setValueFromMemory(long addr,
int len)
Copy a serialized string from a memory address into an
XString. |
boolean |
startsWith(CharSequence prefix)
Tests if this
XString starts with the characters in the provided sequence. |
boolean |
startsWith(CharSequence prefix,
int offset)
Tests if an
XString starts with the characters in the provided sequence
starting from the provided offset. |
static int |
stringSize(long val)
Determine the size of a long value in String form.
|
CharSequence |
subSequence(int start,
int end)
Implementation of CharSequence#subSequence(int, int).
|
String |
toDiagnosticString()
A diagnostic string.
|
String |
toString()
Return the String value of this
XString as returned by getAsString() |
chars, codePointspublic static XString create(short initialCapacity, boolean mutable)
XString.initialCapacity - Specifies the initial capacity of the string's backing storage.
A XStrings does not allocate the backing storage until a value is set in it.
Subsequent changes in the XString value will dynamicaly resize the backing
storage if need be. The backing storage initial capacity specifies the minimum size
of the storage to allocate on the first allocation. This parameter should be provided
if the XStrings created by this factory is expected to undergo several value
changes of a variety of sizes. In such a case, this property should be set as the upper
bound of the set of values expected to be set so the backing storage does not go through
excessive resizingmutable - Specifies whether the constructed XString is mutable. An
XString's mutability only comes into play after the first value is set in
the XStringpublic static XString create(short initialCapacity)
XString.
This method invokes create(initialCapacity, true)
public static XString create(int initialCapacity, boolean mutable)
XString.IllegalArgumentException - thrown if value of initialCapacity is
greater than Short.MAX_VALUE
This method is equivalent to #create(short, boolean} and except that it
accepts the initialCapacity as an integer parameter instead of a short.
This method is provided for backwards compatibility. It performs a validation
check on initialCapacity that the supplied value is less or equal to
Short.MAX_VALUE and throws an IllegalArgumentException if it
is not.
@Deprecated public static XString create(boolean mutable, int initialCapacity)
XString.public static XString create(int initialCapacity)
XString.
This method invokes create(initialCapacity, true)
public static XString create()
XString.XStringpublic static final int stringSize(long val)
val - The long for which to calculate String lengthpublic final void ensureCapacity(short val)
XStrings backing storage is large enough to accommodate datapublic final boolean startsWith(CharSequence prefix)
XString starts with the characters in the provided sequence.prefix - The prefixXString starts with the characters in the provided sequence.
If this string and the provided string are both empty Strings this method will return true.
If this string is null or unitialized this method will return false.NullPointerException - if the provided prefix is null;public final boolean startsWith(CharSequence prefix, int offset)
XString starts with the characters in the provided sequence
starting from the provided offset.prefix - The prefixoffset - the offset in this XString.XString, a string of length longer than this XString,
or if the offset is either negative, or greater than the length of this XString.NullPointerException - if the provided prefix is nullpublic final int indexOf(CharSequence str)
XStringstr - The string to search for.public final int indexOf(CharSequence str, int offset)
XString
starting from the provided offset.str - The string to search for.public final int indexOf(char c)
XString.c - The string to search for.public final int indexOf(char c,
int offset)
XString
starting from the provided offset.c - The string to search for.public final int compareTo(CharSequence other)
If a XStringis null or uninitialized it will lexigraphically precede another
XString that is initialized, otherwise the comparison produces the same results
as that for String.compareTo(String).
other - The character sequence to compare against.String.compareTo(String) for this and the CharSequence as
StringsString.compareTo(String)public final boolean isMutable()
XString was marked as mutable on creation.
A string marked as immmutable can still have a value set on it.
Once set, a string marked as immutable will not permit changing
the value. This method only returns if a string marked as mutable.
To check if a value can be set on the string, use canMutate()
@Deprecated public final boolean isInitialized()
hasValue() insteadXString has been initialized.public final boolean hasValue()
XStringhas a value setpublic final boolean canMutate()
XString can be mutated.
A XString is mutable till a value is set after which it
becomes immutable if created with the immutability flag. Use
isMutable() to check if the XString was created
as mutable.XString can be mutated. A return value
of true means the string was created as mutable or a value has not yet
been set on the string. A value of false means that the string was set
as immutable on creation and a value has been set on the string.public final boolean isImmutable()
XString cannot be mutated.
This method is equivalent to invoking !canMutate()
public final boolean isEmpty()
XString is emptypublic final boolean isNull()
XString's represents a null string.XString's represents a null string.
Being null is synonymous with not possessing a value i.e. this
method returns true if and only if hasValue() returns falsepublic final void clear(boolean freeMemory)
throws IllegalStateException
XString.freeMemory - Indicates whether to free underlying memory or notIllegalStateException - If the XString cannot be mutatedpublic final void clear()
throws IllegalStateException
XString.IllegalStateException - If the XString cannot be mutated
This method executes clear(Config.conserveMemory()) i.e.
the XString is cleared but the backing stored is freed only if
the system is configured to optimize memory usage. Freeing and reallocating
memory on demand for the backing store can be expensive for ultra low
latency applications. Such applications should carefully consider this
and use this method or clear(boolean) accordingly.
@Deprecated public final void reset() throws IllegalStateException
clear() insteadXString.IllegalStateExceptionpublic final void setCharAt(int position,
char value)
position - The position of the character to overwrite (0 based).value - The value to overwrite the character with.IndexOutOfBoundsException - if the position is negative or greater than the length of this string.IllegalStateException - if the string cannot be mutated.IllegalArgumentException - If the value is not a us-ascii character.public final void initialize(String value)
XString with the given String value.value - The value with which to initialize the XStringIllegalStateException - if the XString already has a value.public final void initializeFrom(XString value)
XString with the given value.value - The value with which to initialize the XStringIllegalStateException - if the XString already has a value.public final void setFrom(long value)
value - the value to convert to a StringIllegalStateException - if the string cannot be mutated.public final void setFrom(byte[] value)
value - The String value.IllegalStateException - if the string cannot be mutated.public final void setFrom(byte[] value,
int valueOffset,
int valueLength)
If the value is null, the value of the string is cleared.
value - The String value.valueOffset - The offset into the provided value from which to copy (0 based, inclusive).valueLength - The number of of bytes from the valueOffset to copy.IllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the source character's can't be encoded in ascii.IllegalArgumentException - if the valueOffset or valueLength is outside the bounds of the provided array.public void setFrom(char[] value)
value - The String value.IllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the source character's can't be encoded in ascii.public void setFrom(char[] value,
int valueOffset,
int valueLength)
If the value is null, the value of the string is cleared.
value - The String value.valueOffset - The offset into the provided value from which to copy (0 based, inclusive).valueLength - The number of of bytes from the valueOffset to copy.IllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the source character's can't be encoded in ascii.IllegalArgumentException - if the valueOffset or valueLength is outside the bounds of the provided array.public void setFrom(CharSequence value)
XString to that of the given CharSequencevalue - The CharSequence value.IllegalStateException - if the string cannot be mutated.public final void setFrom(String val)
String.val - The value to set.IllegalStateException - if the XString cannot be mutated.public final void setFrom(XString value)
value - The XString valueIllegalStateException - if the XString cannot be mutated.public final void setFrom(XStringDeserializer value)
XString from an XStringDeserializervalue - The XStringDeserializer valueIllegalStateException - if the XString cannot be mutated.public final void setFrom(long addr,
int offset,
int len)
XString.
The source bytes are expected to be UTF-8 encoded characters.
addr - The source address from which to set.len - The number of bytes to set.IllegalStateException - if the XString cannot be mutated.public final void setFrom(ByteBuffer source, int offset, int len)
ByteBuffer into an XString.
The source bytes are expected to be UTF-8 encoded characters.
source - The bufferoffset - The offset into the bufferlen - The length of the serialized stringIllegalStateException - if the value is not mutable.public final void setFrom(ByteBuffer source)
ByteBuffer into an XString.
The data is copied from the buffer's current position to the buffer's limit. The buffer's position and limit markers are left unchanged after the copy.
The source bytes are expected to be UTF-8 encoded characters.
source - The bufferIllegalStateException - if the value is not mutable.public final void setFrom(IOBuffer source, int offset, int len)
IOBuffer into an XString.
The source bytes are expected to be UTF-8 encoded characters.
source - The bufferoffset - The offset into the bufferlen - The length of the serialized stringIllegalStateException - if the value is not mutable.public final void setFrom(IOElasticBuffer source, int offset, int len)
IOElasticBuffer into an XString.
The source bytes are expected to be UTF-8 encoded characters.
source - The bufferoffset - The offset into the bufferlen - The length of the serialized stringIllegalStateException - if the value is not mutable.public final void setValue(long value)
Equivalent to invoking setFrom(long)
public final void setValue(byte[] value)
Equivalent to invoking setFrom(byte[])
public final void setValue(byte[] value,
int valueOffset,
int valueLength)
Equivalent to invoking setFrom(byte[], int, int)
public final void setValue(char[] value)
Equivalent to invoking setFrom(char[])
public final void setValue(char[] value,
int valueOffset,
int valueLength)
Equivalent to invoking setFrom(char[], int, int)
public final void setValue(CharSequence value)
Equivalent to invoking setFrom(CharSequence)
public final void setValue(String value)
String
Equivalent to invoking setFrom(String)
public final void setValue(XString value)
public final void setValue(ByteBuffer value, int offset, int len)
ByteBuffer into an XString.
Equivalent to invoking setFrom(ByteBuffer, int, int)
public final void setValue(ByteBuffer value)
ByteBuffer into an XString.
Equivalent to invoking setFrom(ByteBuffer)
public final void setValue(IOBuffer value, int offset, int len)
IOBuffer into an XString.
Equivalent to invoking setFrom(IOBuffer, int, int)
public final void setValue(IOElasticBuffer value, int offset, int len)
IOElasticBuffer into an XString.
Equivalent to invoking setFrom(IOElasticBuffer, int, int)
public final void setValue(long addr,
int offset,
int len)
XString.
Equivalent to invoking setFrom(long, int, int)instead
public final void setValueFromMemory(long addr,
int len)
XString.
Equivalent to invoking setFrom(long, int, int)instead
public final void copyFrom(char[] val)
Equivalent to invoking setFrom(char[])instead.
public final void copyFrom(XString value)
public final void copyFromNative(long addr,
int len)
XString.
Equivalent to invoking setFrom(long, int, int)instead
public final void copyFromMemory(long addr,
int len)
XString.
Equivalent to invoking setFrom(long, int, int)instead
public final XString append(boolean value)
XString.value - The boolean to append.XString for invocation chainingIllegalStateException - if this string cannot be mutated.public final XString append(char value) throws IllegalArgumentException
XString.append in interface Appendablevalue - The character to append.XString for invocation chainingIllegalStateException - if the string cannot be mutated.IllegalArgumentException - If the character is not a us-ascii character.public final XString append(long value)
XString.value - The value to append.XString for invocation chainingIllegalStateException - if the string cannot be mutated.IllegalArgumentException - If the character is not a us-ascii character.public final XString append(byte[] value)
XString.
This method is equivalent to calling append(char[], int, int) with values of 0
and value.length respectively ... see javadoc for additional details.
value - The ByteBuffer value.XString for invocation chainingIllegalStateException - if the string cannot be mutated.public final XString append(byte[] value, int valueOffset, int valueLength)
XString.
Calling this method with a null value has no effect other than throwing an IllegalStateException if this XString cannot be mutated.
value - The ByteBuffer value.valueOffset - The offset into the provided value from which to append (0 based, inclusive).valueLength - The number of of bytes from the valueOffset to append.XString for invocation chainingIllegalStateException - if the string cannot be mutated.IllegalArgumentException - if the valueOffset or valueLength is outside the bounds of the provided array.public final XString append(char[] value) throws IllegalArgumentException
XString.
This method is equivalent to calling append(char[], int, int) with values of 0
and value.length respectively ... see javadoc for additional details.
value - The characters to append.XString for invocation chainingIllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the characters is not a us-ascii character.public final XString append(char[] value, int valueOffset, int valueLength) throws IllegalArgumentException
XString.value - The characters to append.valueOffset - The offset into the provided value from which to append (0 based, inclusive).valueLength - The number of of bytes from the valueOffset to append.XString for invocation chainingIllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the characters is not a us-ascii character.IllegalArgumentException - if the valueOffset or valueLength is outside the bounds of the provided array.public final XString append(CharSequence value) throws IllegalArgumentException
CharSequence to the end of this XString.append in interface Appendablevalue - The characters to append.XString for invocation chainingIllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the characters is not a us-ascii character.public final Appendable append(CharSequence value, int start, int end) throws IllegalArgumentException
append in interface AppendableIllegalStateException - if the string cannot be mutated.IllegalArgumentException - If any of the characters is not a us-ascii character.public final XString append(XString value)
XString into this XString.
If the source XString is null then this XString is left
unchanged.
source - The XString to append to this XStringXString for invocation chainingIllegalStateException - if the string cannot be mutated.public final XString append(ByteBuffer value, int valueOffset, int valueLength)
ByteBuffer into this XString.
If the source ByteBuffer is null, then this XString is left
unchanged.
value - The source buffervalueOffset - The offset into the buffer to append fronvalueLength - The length to appendXString for invocation chainingIllegalStateException - if the string cannot be mutated.public final XString append(ByteBuffer value)
ByteBuffer into this XString.
This method appends the remaining bytes in the source ByteBuffer
If the source ByteBuffer is null, then this XString is left
unchanged.
value - The source bufferXString for invocation chainingIllegalStateException - if the string cannot be mutated.public String getAsString()
public final long getAsLong()
throws NumberFormatException
XString as a long value.XString as a long value.NumberFormatException - If the XString can't be parsed as a long.public final long getAsLongDecimal()
XString as a long value.XString as a long value.
Unlike getAsLong(int) this method does not perform
number format checking and is more efficient.
public final long getAsLong(int radix)
throws NumberFormatException
XString as a long value.radix - The radix to use when parsing the long value. Valid values
are between 2 and 36 both inclusiveXString as a long value.NumberFormatException - If the XString can't be parsed as a long.public final int getTo(XString val)
public final int getTo(byte[] val,
int offset)
XString into an byte arrayval - The array into which the bytes are to be copied.offset - The offset into the array to copy toisNull()
to differentiate between these two scenariospublic final int getTo(long addr,
int offset)
XString to a memory locationaddr - The base memory location into which the bytes are to be copied.offset - The offset to the memory location to copy toisNull()
to differentiate between these two scenariospublic final int getTo(ByteBuffer target, int offset)
XString to a ByteBufferbuffer - The buffer to copy the bytes tooffset - The offset into the buffer to copy toisNull()
to differentiate between these two scenariospublic final int getTo(IOElasticBuffer target, int offset)
XString to an IOElasticBufferbuffer - The buffer to copy the bytes tooffset - The offset into the buffer to copy toisNull()
to differentiate between these two scenariospublic final String getValue()
public final long getValueAsLong()
throws NumberFormatException
Equivalent to getAsLong()
NumberFormatException@Deprecated public final int copyInto(XString val)
#getTo(XString} instead@Deprecated public final int copyInto(ByteBuffer target, int offset)
getTo(ByteBuffer, int) insteadXString to an ByteBufferpublic final int getTo(IOBuffer target, int offset)
buffer - The buffer to copy the bytes tooffset - The offset into the buffer to copy toisNull()
to differentiate between these two scenarios@Deprecated public final int copyInto(IOBuffer target, int offset)
getTo(IOBuffer, int) instead@Deprecated public final int copyInto(IOElasticBuffer target, int offset)
getTo(IOElasticBuffer, int) insteadXString to an IOElasticBufferpublic final int length()
length in interface CharSequencepublic final int capacity()
public final int serializedLength()
XString's serialized length.
Given it's character encoding, this may be different than
it's length().
public final long nativeAddress()
XString's backing store address.@Deprecated public final int getSerializedLength()
serializedLength() insteadXString's serialized length.public final char charAt(int index)
throws IndexOutOfBoundsException
charAt in interface CharSequenceindex - The character position.IndexOutOfBoundsException - If the position is greater than or
equal to this XString's length()public final CharSequence subSequence(int start, int end)
subSequence in interface CharSequenceXStringCharSequence.subSequence(int, int)public String toString()
XString as returned by getAsString()toString in interface CharSequencetoString in class Objectpublic final String toDiagnosticString()
public boolean equals(Object object)
XString is equal to another XString. Two
XStrings that are initialized are equal if their backing byte
representations are the equivalent.
an XString will also equal a CharSequence that is a subsequence of another
XString if they have the same characters, but equality will not hold true for
CharSequences that are not XString char sequences. This limitation
is necessary because it isn't possible to guarantee that symmetric equality with other
CharSequence implementations. For example a String will only equal another
String CharSequence.
public int hashCode()
XString.
The hash code of an XString is based on the backing byte representation
The hashcode of a mutable XString will change if the underlying String
or bytes are modified.
Because mutable XString hash codes are content-dependent, it is inadvisable
to use mutable unitialized immutable XStrings as keys in hash maps or similar
data structures unless it is known that their contents will not change.
XString Hash Algorithm
The hashing algorithm for an XString is as follows:
if (isNull()) {
return 0;
}
if (length == 0) {
return 0;
}
int h = 1;
for (int p = 0; p < length; p++) {
h = 31 * h + IOBuffer.getByte(addr, p);
}
return h;
public final void close()
Copyright © 2019 N5 Technologies, Inc. All Rights Reserved.