Package com.swiftmq.ms.artemis.util
Class SimpleString
java.lang.Object
com.swiftmq.ms.artemis.util.SimpleString
- All Implemented Interfaces:
Serializable
,CharSequence
,Comparable<SimpleString>
public final class SimpleString
extends Object
implements CharSequence, Serializable, Comparable<SimpleString>
A simple String class that can store all characters, and stores as simple
byte[]
, this
minimises expensive copying between String objects.
This object is used heavily throughout ActiveMQ Artemis for performance reasons.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleString
(byte[] data) creates a SimpleString from a byte arraySimpleString
(char c) SimpleString
(String string) creates a SimpleString from a conventional String -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int pos) int
concat
(char c) Concatenates a SimpleString and a charconcat
(SimpleString toAdd) Concatenates 2 SimpleString'sConcatenates a SimpleString and a Stringboolean
contains
(char c) checks to see if this SimpleString contains the char parameter passed inboolean
void
getChars
(int srcBegin, int srcEnd, char[] dst, int dstPos) This method performs a similar function toString.getChars(int, int, char[], int)
.byte[]
getData()
returns the underlying byte array of this SimpleStringint
hashCode()
boolean
isEmpty()
int
length()
int
sizeof()
returns the size of this SimpleStringstatic int
returns the size of a SimpleString which could be nullstatic int
sizeofString
(SimpleString str) returns the size of a SimpleStringsplit
(char delim) Splits this SimpleString into an array of SimpleString using the char param as the delimiter.boolean
startsWith
(SimpleString other) returns true if the SimpleString parameter starts with the same data as this one.subSeq
(int start, int end) subSequence
(int start, int end) static SimpleString
toSimpleString
(String string) Returns a SimpleString constructed from thestring
parameter.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
Constructor Details
-
SimpleString
creates a SimpleString from a conventional String- Parameters:
string
- the string to transform
-
SimpleString
public SimpleString(byte[] data) creates a SimpleString from a byte array- Parameters:
data
- the byte array to use
-
SimpleString
public SimpleString(char c)
-
-
Method Details
-
toSimpleString
Returns a SimpleString constructed from thestring
parameter.If
string
isnull
, the return value will benull
too.- Parameters:
string
- String used to instantiate a SimpleString.- Returns:
- A new SimpleString
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCharSequence
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int pos) - Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
subSeq
-
compareTo
- Specified by:
compareTo
in interfaceComparable<SimpleString>
-
getData
public byte[] getData()returns the underlying byte array of this SimpleString- Returns:
- the byte array
-
startsWith
returns true if the SimpleString parameter starts with the same data as this one. false if not.- Parameters:
other
- the SimpleString to look for- Returns:
- true if this SimpleString starts with the same data
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
equals
-
hashCode
public int hashCode() -
split
Splits this SimpleString into an array of SimpleString using the char param as the delimiter. i.e. "a.b" would return "a" and "b" if . was the delimiter- Parameters:
delim
- The delimiter to split this SimpleString on.- Returns:
- An array of SimpleStrings
-
contains
public boolean contains(char c) checks to see if this SimpleString contains the char parameter passed in- Parameters:
c
- the char to check for- Returns:
- true if the char is found, false otherwise.
-
concat
Concatenates a SimpleString and a String- Parameters:
toAdd
- the String to concatenate with.- Returns:
- the concatenated SimpleString
-
concat
Concatenates 2 SimpleString's- Parameters:
toAdd
- the SimpleString to concatenate with.- Returns:
- the concatenated SimpleString
-
concat
Concatenates a SimpleString and a char- Parameters:
c
- the char to concate with.- Returns:
- the concatenated SimpleString
-
sizeof
public int sizeof()returns the size of this SimpleString- Returns:
- the size
-
sizeofString
returns the size of a SimpleString- Parameters:
str
- the SimpleString to check- Returns:
- the size
-
sizeofNullableString
returns the size of a SimpleString which could be null- Parameters:
str
- the SimpleString to check- Returns:
- the size
-
getChars
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstPos) This method performs a similar function toString.getChars(int, int, char[], int)
. This is mainly used by the Parsers on Filters- Parameters:
srcBegin
- The srcBeginsrcEnd
- The srcEnddst
- The destination arraydstPos
- The destination position
-