Class SimpleString
- java.lang.Object
-
- org.apache.activemq.artemis.api.core.SimpleString
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,java.lang.Comparable<SimpleString>
public final class SimpleString extends java.lang.Object implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<SimpleString>
A simple String class that can store all characters, and stores as simplebyte[], this minimises expensive copying between String objects.This object is used heavily throughout ActiveMQ Artemis for performance reasons.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimpleString.ByteBufSimpleStringPoolstatic classSimpleString.StringSimpleStringPool
-
Constructor Summary
Constructors Constructor Description SimpleString(byte[] data)creates a SimpleString from a byte arraySimpleString(char c)SimpleString(java.lang.String string)creates a SimpleString from a conventional String
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int pos)intcompareTo(SimpleString o)SimpleStringconcat(char c)Concatenates a SimpleString and a charSimpleStringconcat(java.lang.String toAdd)Concatenates a SimpleString and a StringSimpleStringconcat(SimpleString toAdd)Concatenates 2 SimpleString'sbooleancontains(char c)checks to see if this SimpleString contains the char parameter passed inbooleancontainsEitherOf(char c, char d)booleanequals(io.netty.buffer.ByteBuf byteBuf, int offset, int length)booleanequals(java.lang.Object other)voidgetChars(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 SimpleStringjava.lang.String[]getPaths(char separator)note the result of the first use is cached, the separator is configured on the postoffice so will be static for the duration of a server instance.inthashCode()booleanisEmpty()intlength()static SimpleStringreadNullableSimpleString(io.netty.buffer.ByteBuf buffer)static SimpleStringreadNullableSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString.ByteBufSimpleStringPool pool)static SimpleStringreadSimpleString(io.netty.buffer.ByteBuf buffer)static SimpleStringreadSimpleString(io.netty.buffer.ByteBuf buffer, int length)static SimpleStringreadSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString.ByteBufSimpleStringPool pool)intsizeof()returns the size of this SimpleStringstatic intsizeofNullableString(SimpleString str)returns the size of a SimpleString which could be nullstatic intsizeofString(SimpleString str)returns the size of a SimpleStringSimpleString[]split(char delim)Splits this SimpleString into an array of SimpleString using the char param as the delimiter.booleanstartsWith(char other)returns true if the SimpleString parameter starts with the same char.booleanstartsWith(SimpleString other)returns true if the SimpleString parameter starts with the same data as this one.SimpleStringsubSeq(int start, int end)java.lang.CharSequencesubSequence(int start, int end)static SimpleStringtoSimpleString(java.lang.String string)Returns a SimpleString constructed from thestringparameter.static SimpleStringtoSimpleString(java.lang.String string, SimpleString.StringSimpleStringPool pool)java.lang.StringtoString()static voidwriteNullableSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString val)static voidwriteSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString val)
-
-
-
Constructor Detail
-
SimpleString
public SimpleString(java.lang.String string)
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 Detail
-
toSimpleString
public static SimpleString toSimpleString(java.lang.String string)
Returns a SimpleString constructed from thestringparameter.If
stringisnull, the return value will benulltoo.- Parameters:
string- String used to instantiate a SimpleString.- Returns:
- A new SimpleString
-
toSimpleString
public static SimpleString toSimpleString(java.lang.String string, SimpleString.StringSimpleStringPool pool)
-
isEmpty
public boolean isEmpty()
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int pos)
- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence
-
readNullableSimpleString
public static SimpleString readNullableSimpleString(io.netty.buffer.ByteBuf buffer)
-
readNullableSimpleString
public static SimpleString readNullableSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString.ByteBufSimpleStringPool pool)
-
readSimpleString
public static SimpleString readSimpleString(io.netty.buffer.ByteBuf buffer)
-
readSimpleString
public static SimpleString readSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString.ByteBufSimpleStringPool pool)
-
readSimpleString
public static SimpleString readSimpleString(io.netty.buffer.ByteBuf buffer, int length)
-
writeNullableSimpleString
public static void writeNullableSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString val)
-
writeSimpleString
public static void writeSimpleString(io.netty.buffer.ByteBuf buffer, SimpleString val)
-
subSeq
public SimpleString subSeq(int start, int end)
-
compareTo
public int compareTo(SimpleString o)
- Specified by:
compareToin interfacejava.lang.Comparable<SimpleString>
-
getData
public byte[] getData()
returns the underlying byte array of this SimpleString- Returns:
- the byte array
-
startsWith
public boolean startsWith(SimpleString other)
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
-
startsWith
public boolean startsWith(char other)
returns true if the SimpleString parameter starts with the same char. false if not.- Parameters:
other- the char to look for- Returns:
- true if this SimpleString starts with the same data
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
getPaths
public java.lang.String[] getPaths(char separator)
note the result of the first use is cached, the separator is configured on the postoffice so will be static for the duration of a server instance. calling with different separator values could give invalid results- Parameters:
separator- value from wildcardConfiguration- Returns:
- String[] reference to the split paths or the cached value if previously called
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
equals
public boolean equals(io.netty.buffer.ByteBuf byteBuf, int offset, int length)Returnstrueif theSimpleStringencoded content intobytesis equals tos,falseotherwise.It assumes that the
bytescontent is read usingreadSimpleString(ByteBuf, int)ie starting right after the length field.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
split
public SimpleString[] split(char delim)
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.
-
containsEitherOf
public boolean containsEitherOf(char c, char d)
-
concat
public SimpleString concat(java.lang.String toAdd)
Concatenates a SimpleString and a String- Parameters:
toAdd- the String to concatenate with.- Returns:
- the concatenated SimpleString
-
concat
public SimpleString concat(SimpleString toAdd)
Concatenates 2 SimpleString's- Parameters:
toAdd- the SimpleString to concatenate with.- Returns:
- the concatenated SimpleString
-
concat
public SimpleString concat(char c)
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
public static int sizeofString(SimpleString str)
returns the size of a SimpleString- Parameters:
str- the SimpleString to check- Returns:
- the size
-
sizeofNullableString
public static int sizeofNullableString(SimpleString str)
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
-
-