@Public public class StringValue extends Object implements NormalizableKey<StringValue>, CharSequence, ResettableValue<StringValue>, CopyableValue<StringValue>, Appendable
String
, in a serializable and mutable way.
The mutability allows to reuse the object inside the user code, also across invocations. Reusing a StringValue object helps to increase the performance, as string objects are rather heavy-weight objects and incur a lot of garbage collection overhead, if created and destroyed en masse.
NormalizableKey
,
String
,
CharSequence
,
Serialized FormConstructor and Description |
---|
StringValue()
Initializes the encapsulated String object with an empty string.
|
StringValue(CharSequence value)
Initializes this StringValue to the value of the given string.
|
StringValue(StringValue value)
Initializes this StringValue to a copy the given StringValue.
|
StringValue(StringValue value,
int offset,
int len)
Initializes the StringValue to a sub-string of the given StringValue.
|
Modifier and Type | Method and Description |
---|---|
Appendable |
append(char c) |
Appendable |
append(CharSequence csq) |
Appendable |
append(CharSequence csq,
int start,
int end) |
Appendable |
append(StringValue csq) |
Appendable |
append(StringValue csq,
int start,
int end) |
char |
charAt(int index) |
int |
compareTo(StringValue other) |
StringValue |
copy()
Performs a deep copy of this object into a new instance.
|
void |
copy(DataInputView in,
DataOutputView target)
Copies the next serialized instance from
source to target . |
void |
copyNormalizedKey(MemorySegment target,
int offset,
int len)
Writes a normalized key for the given record into the target byte array, starting at the
specified position an writing exactly the given number of bytes.
|
static void |
copyString(DataInput in,
DataOutput out) |
void |
copyTo(StringValue target)
Performs a deep copy of this object into the
target instance. |
boolean |
equals(Object obj)
Compares the object on equality with another object.
|
int |
find(CharSequence str)
Finds any occurrence of the
str character sequence in this StringValue. |
int |
find(CharSequence str,
int start)
Finds any occurrence of the
str character sequence in this StringValue. |
int |
getBinaryLength()
Gets the length of the data type when it is serialized, in bytes.
|
char[] |
getCharArray()
Returns this StringValue's internal character data.
|
int |
getMaxNormalizedKeyLen()
Gets the maximal length of normalized keys that the data type would produce to determine the
order of instances solely by the normalized key.
|
String |
getValue()
Gets this StringValue as a String.
|
int |
hashCode()
All keys must override the hash-code function to generate proper deterministic hash codes,
based on their contents.
|
int |
length() |
void |
read(DataInputView in)
Reads the object's internal data from the given data input view.
|
static String |
readString(DataInput in) |
void |
setLength(int len)
Sets a new length for the string.
|
void |
setValue(char[] chars,
int offset,
int len)
Sets the value of the StringValue to a substring of the given value.
|
void |
setValue(CharBuffer buffer)
Sets the contents of this string to the contents of the given CharBuffer.
|
void |
setValue(CharSequence value)
Sets the value of the StringValue to the given string.
|
void |
setValue(CharSequence value,
int offset,
int len)
Sets the value of the StringValue to a substring of the given string.
|
void |
setValue(StringValue value)
Sets the value of the StringValue to the given string.
|
void |
setValue(StringValue value,
int offset,
int len)
Sets the value of the StringValue to a substring of the given string.
|
void |
setValueAscii(byte[] bytes,
int offset,
int len)
Sets the value of this
StringValue , assuming that the binary data is ASCII
coded. |
boolean |
startsWith(CharSequence prefix)
Checks whether this StringValue starts with the given prefix string.
|
boolean |
startsWith(CharSequence prefix,
int startIndex)
Checks whether the substring, starting at the specified index, starts with the given prefix
string.
|
CharSequence |
subSequence(int start,
int end) |
StringValue |
substring(int start)
Returns a new StringValuestring that is a substring of this string.
|
StringValue |
substring(int start,
int end)
Returns a new StringValuestring that is a substring of this string.
|
void |
substring(StringValue target,
int start)
Copies a substring of this string into the given target StringValue.
|
void |
substring(StringValue target,
int start,
int end)
Copies a substring of this string into the given target StringValue.
|
String |
toString() |
void |
write(DataOutputView out)
Writes the object's internal data to the given data output view.
|
static void |
writeString(CharSequence cs,
DataOutput out) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
chars, codePoints
public StringValue()
public StringValue(CharSequence value)
value
- The string containing the value for this StringValue.public StringValue(StringValue value)
value
- The initial value.public StringValue(StringValue value, int offset, int len)
value
- The string containing the substring.offset
- The offset of the substring.len
- The length of the substring.public void setLength(int len)
len
- The new length.public char[] getCharArray()
public String getValue()
public void setValue(CharSequence value)
value
- The new string value.public void setValue(StringValue value)
setValue
in interface ResettableValue<StringValue>
value
- The new string value.public void setValue(StringValue value, int offset, int len)
value
- The new string value.offset
- The position to start the substring.len
- The length of the substring.public void setValue(CharSequence value, int offset, int len)
value
- The new string value.offset
- The position to start the substring.len
- The length of the substring.public void setValue(CharBuffer buffer)
buffer
- The character buffer to read the characters from.public void setValue(char[] chars, int offset, int len)
chars
- The new string value (as a character array).offset
- The position to start the substring.len
- The length of the substring.public void setValueAscii(byte[] bytes, int offset, int len)
StringValue
, assuming that the binary data is ASCII
coded. The n-th character of the StringValue
corresponds directly to the n-th
byte in the given array after the offset.bytes
- The binary character data.offset
- The offset in the array.len
- The number of bytes to read from the array.public StringValue substring(int start)
start
index and ends at end of the stringstart
- The beginning index, inclusive.IndexOutOfBoundsException
- Thrown, if the start is negative.public StringValue substring(int start, int end)
start
index and ends at end - 1
.start
- The beginning index, inclusive.end
- The ending index, exclusive.IndexOutOfBoundsException
- Thrown, if the start is negative, or the end is larger
than the length.public void substring(StringValue target, int start)
start
index and ends at end of the stringtarget
- The StringValue object to copy the substring to.start
- The beginning index, inclusive.IndexOutOfBoundsException
- Thrown, if the start is negative.public void substring(StringValue target, int start, int end)
start
index and ends at end - 1
.target
- The StringValue object to copy the substring to.start
- The beginning index, inclusive.end
- The ending index, exclusive.IndexOutOfBoundsException
- Thrown, if the start is negative, or the end is larger
than the length.public int find(CharSequence str)
str
character sequence in this StringValue.-1
, if the character sequence was not found.public int find(CharSequence str, int start)
str
character sequence in this StringValue. The
search starts at position start
.-1
, if the character sequence was not found.public boolean startsWith(CharSequence prefix, int startIndex)
prefix
- The prefix character sequence.startIndex
- The position to start checking for the prefix.startIndex
has
prefix
as its prefix.public boolean startsWith(CharSequence prefix)
prefix
- The prefix character sequence.prefix
as its prefix.public Appendable append(char c)
append
in interface Appendable
public Appendable append(CharSequence csq)
append
in interface Appendable
public Appendable append(CharSequence csq, int start, int end)
append
in interface Appendable
public Appendable append(StringValue csq)
public Appendable append(StringValue csq, int start, int end)
public void read(DataInputView in) throws IOException
IOReadableWritable
read
in interface IOReadableWritable
in
- the input view to read the data fromIOException
- thrown if any error occurs while reading from the input streampublic void write(DataOutputView out) throws IOException
IOReadableWritable
write
in interface IOReadableWritable
out
- the output view to receive the data.IOException
- thrown if any error occurs while writing to the output streampublic String toString()
toString
in interface CharSequence
toString
in class Object
public int compareTo(StringValue other)
compareTo
in interface Comparable<StringValue>
public int hashCode()
Key
hashCode
in interface Key<StringValue>
hashCode
in class Object
public boolean equals(Object obj)
Key
equals
in interface Key<StringValue>
equals
in class Object
obj
- The other object to compare against.public int length()
length
in interface CharSequence
public char charAt(int index)
charAt
in interface CharSequence
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public int getMaxNormalizedKeyLen()
NormalizableKey
Integer
.MAX_VALUE is interpreted as infinite.
For example, 32 bit integers return four, while Strings (potentially unlimited in length)
return Integer
.MAX_VALUE.
getMaxNormalizedKeyLen
in interface NormalizableKey<StringValue>
public void copyNormalizedKey(MemorySegment target, int offset, int len)
NormalizableKey
int byteI = bytes[i] & 0xFF;
If the meaningful part of the normalized key takes less than the given number of bytes,
then it must be padded. Padding is typically required for variable length data types, such as
strings. The padding uses a special character, either 0
or 0xff
, depending on
whether shorter values are sorted to the beginning or the end.
copyNormalizedKey
in interface NormalizableKey<StringValue>
target
- The memory segment to put the normalized key bytes into.offset
- The offset in the byte array where the normalized key's bytes should start.len
- The number of bytes to put.public int getBinaryLength()
CopyableValue
getBinaryLength
in interface CopyableValue<StringValue>
-1
, if variable length.public void copyTo(StringValue target)
CopyableValue
target
instance.copyTo
in interface CopyableValue<StringValue>
target
- Object to copy into.public StringValue copy()
CopyableValue
This method is useful for generic user-defined functions to clone a CopyableValue
when storing multiple objects. With object reuse a deep copy must be created and type erasure
prevents calling new.
copy
in interface CopyableValue<StringValue>
public void copy(DataInputView in, DataOutputView target) throws IOException
CopyableValue
source
to target
.
This method is equivalent to calling IOReadableWritable.read(DataInputView)
followed by IOReadableWritable.write(DataOutputView)
but does not require
intermediate deserialization.
copy
in interface CopyableValue<StringValue>
in
- Data source for serialized instance.target
- Data target for serialized instance.IOException
IOReadableWritable
public static String readString(DataInput in) throws IOException
IOException
public static final void writeString(CharSequence cs, DataOutput out) throws IOException
IOException
public static final void copyString(DataInput in, DataOutput out) throws IOException
IOException
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.