Package one.microstream.chars
Class VarString
- java.lang.Object
-
- one.microstream.chars.VarString
-
- All Implemented Interfaces:
Serializable
,Appendable
,CharSequence
public final class VarString extends Object implements CharSequence, Appendable, Serializable
Faster implementation of a StringBuilder with richer functionality. Note that this class is NOT synchronized and only meant for single-threaded or thread-safe (i.e. read only or explicitly synchronized) use.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
VarString.Appendable
Implementors of this interface handle appending their specific string representation directly.
This is useful for preventing the instantiation and copying of potentially large temporary strings which can have unnecessary and devastatingly negative effects on performance.
-
Constructor Summary
Constructors Constructor Description VarString()
-
Method Summary
Modifier and Type Method Description VarString
add(boolean value)
VarString
add(byte value)
VarString
add(char c)
VarString
add(char[] chars)
void
add(char[] chars, int offset, int length)
VarString
add(char c1, char c2)
VarString
add(char c1, char c2, char c3)
VarString
add(double value)
VarString
add(float value)
VarString
add(int value)
VarString
add(long value)
VarString
add(short value)
<E> VarString
add(E element, BiConsumer<VarString,? super E> joiner)
VarString
add(Character c)
VarString
add(CharSequence cs)
VarString
add(Object o)
VarString
add(String s)
VarString
add(VarString vs)
<E> VarString
addAll(E[] elements, BiConsumer<VarString,? super E> joiner)
<E> VarString
addAll(Iterable<? extends E> elements, BiConsumer<VarString,? super E> joiner)
VarString
addChars(char... chars)
VarString
addCharSequences(CharSequence... csqs)
VarString
addFalse()
VarString
addHexDec(byte value)
VarString
addHexDec(byte... bytes)
VarString
addMapped(boolean value, String trueValue, String falseValue)
VarString
addMapped(Boolean value, String trueValue, String falseValue)
static void
addNonNull(VarString vs, Object object)
VarString
addNull()
VarString
addObjects(Object... objects)
VarString
addTrue()
VarString
append(char c)
VarString
append(CharSequence csq)
VarString
append(CharSequence csq, int start, int end)
VarString
append(VarString.Appendable appendable)
VarString
apply(Consumer<? super VarString> procedure)
VarString
blank()
VarString
blank(int amount)
char
charAt(int index)
VarString
clear()
Fills this instance's char storage completely with zeros and sets its size to 0.VarString
consolidate()
boolean
contains(char c)
boolean
contains(char[] chars)
boolean
contains(String s)
boolean
contains(VarString vc)
VarString
copyTo(char[] target, int targetOffset)
VarString
copyTo(int offset, char[] target, int targetOffset, int length)
int
count(char c)
int
count(char[] chars)
int
count(String s)
int
count(VarString vc)
VarString
cr()
VarString
cr(int amount)
VarString
crlf()
VarString
deleteAt(int index)
VarString
deleteLast()
VarString
deleteLast(int n)
byte[]
encode()
Alias forthis.encodeBy(XFiles.standardCharset());
for general purpose encoding, with the "standard" being UTF-8 (XFiles.utf8()
), because any other charset is nonsense for a general case.byte[]
encodeBy(Charset charset)
boolean
endsWith(char c)
boolean
endsWith(char[] chars)
boolean
endsWith(String string)
void
ensureCapacity(int minimumCapacity)
void
ensureFreeCapacity(int minimumFreeCapacity)
boolean
equalsAt(int index, char[] chars, int charsOffset, int charsLength)
char
first()
int
indexOf(char c)
int
indexOf(char[] chars)
int
indexOf(char[] chars, int offset)
int
indexOf(char c, int offset)
int
indexOf(String s)
int
indexOf(String s, int offset)
int
indexOf(VarString vc)
int
indexOf(VarString vc, int offset)
boolean
isEmpty()
void
iterate(_charProcedure iterator)
char
last()
int
lastIndexOf(char c)
int
lastIndexOf(char c, int offset)
int
length()
VarString
lf()
VarString
lf(int amount)
VarString
list(String separator, boolean... listElements)
VarString
list(String separator, byte... listElements)
VarString
list(String separator, char... listElements)
VarString
list(String separator, double... listElements)
VarString
list(String separator, float... listElements)
VarString
list(String separator, int... listElements)
VarString
list(String separator, long... listElements)
VarString
list(String separator, short... listElements)
VarString
list(String separator, Object... listElements)
VarString
list(String separator, String... listElements)
VarString
list(String separator, VarString... listElements)
VarString
list(String separator, VarString.Appendable... listElements)
VarString
list(String separator, XGettingCollection<?> listElements)
static VarString
New()
static VarString
New(int initialMinimumCapacity)
static VarString
New(String s)
VarString
padLeft(String s, int totalLength, char paddingChar)
VarString
padRight(String s, int totalLength, char paddingChar)
VarString
repeat(int amount, char c)
VarString
repeat(int amount, char[] chars)
VarString
repeat(int amount, String string)
String
replace(CharSequence target, CharSequence replacement)
VarString
replaceAll(char sample, char replacement)
VarString
replaceAll(char sample, char replacement, int offset)
VarString
replaceAll(char sample, char replacement, int offset, int length)
String
replaceAll(String regex, String replacement)
VarString
replaceFirst(char sample, char replacement)
VarString
replaceFirst(char sample, char replacement, int offset)
VarString
replaceFirst(char sample, char replacement, int offset, int length)
String
replaceFirst(String regex, String replacement)
VarString
reset()
Simply resets this instance by setting its size to 0 while leaving the actual char storage untouched.VarString
reverse()
VarString
set(int index, char c)
VarString
setChars(int index, char... c)
VarString
setLast(char c)
VarString
shrinkTo(int n)
String[]
split(String regex)
String[]
split(String regex, int limit)
VarString
subsequence(int beginIndex, int endIndex)
VarString
subSequence(int start, int end)
String
substring(int beginIndex, int endIndex)
VarString
surrogateCharReverse()
Deprecated.not implemented yet.VarString
tab()
VarString
tab(int amount)
char[]
toArray()
String
toString()
VarString
trim()
VarString
truncateTo(int newLength)
void
validateIndex(int index)
void
validateRange(int offset, int length)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Method Detail
-
New
public static final VarString New()
-
New
public static final VarString New(int initialMinimumCapacity)
-
add
public final void add(char[] chars, int offset, int length)
-
validateIndex
public final void validateIndex(int index)
-
validateRange
public final void validateRange(int offset, int length)
-
last
public final char last()
-
first
public final char first()
-
add
public final VarString add(char c)
-
add
public final VarString add(char c1, char c2)
-
add
public final VarString add(char c1, char c2, char c3)
-
add
public final VarString add(byte value)
-
add
public final VarString add(boolean value)
-
add
public final VarString add(short value)
-
add
public final VarString add(int value)
-
add
public final VarString add(float value)
-
add
public final VarString add(long value)
-
add
public final VarString add(double value)
-
add
public final VarString add(char[] chars)
-
add
public final VarString add(CharSequence cs)
-
addHexDec
public final VarString addHexDec(byte value)
-
addHexDec
public final VarString addHexDec(byte... bytes)
-
ensureFreeCapacity
public final void ensureFreeCapacity(int minimumFreeCapacity)
-
ensureCapacity
public final void ensureCapacity(int minimumCapacity)
-
addChars
public final VarString addChars(char... chars)
-
addCharSequences
public final VarString addCharSequences(CharSequence... csqs)
-
addNull
public final VarString addNull()
-
addTrue
public final VarString addTrue()
-
addFalse
public final VarString addFalse()
-
append
public final VarString append(VarString.Appendable appendable)
-
add
public final <E> VarString add(E element, BiConsumer<VarString,? super E> joiner)
-
addAll
public final <E> VarString addAll(E[] elements, BiConsumer<VarString,? super E> joiner)
-
addAll
public final <E> VarString addAll(Iterable<? extends E> elements, BiConsumer<VarString,? super E> joiner)
-
set
public final VarString set(int index, char c)
-
setChars
public final VarString setChars(int index, char... c)
-
setLast
public final VarString setLast(char c)
-
reverse
public final VarString reverse()
-
surrogateCharReverse
@Deprecated public final VarString surrogateCharReverse()
Deprecated.not implemented yet. Currently just callsreverse()
.Not implemented yet.
-
indexOf
public final int indexOf(char c)
-
indexOf
public final int indexOf(char c, int offset)
-
indexOf
public final int indexOf(char[] chars)
-
indexOf
public final int indexOf(char[] chars, int offset)
-
indexOf
public final int indexOf(String s)
-
indexOf
public final int indexOf(String s, int offset)
-
indexOf
public final int indexOf(VarString vc)
-
indexOf
public final int indexOf(VarString vc, int offset)
-
contains
public final boolean contains(char c)
-
contains
public final boolean contains(char[] chars)
-
contains
public final boolean contains(String s)
-
contains
public final boolean contains(VarString vc)
-
lastIndexOf
public final int lastIndexOf(char c)
-
lastIndexOf
public final int lastIndexOf(char c, int offset)
-
count
public final int count(char c)
-
count
public final int count(char[] chars)
-
count
public final int count(String s)
-
count
public final int count(VarString vc)
-
deleteAt
public final VarString deleteAt(int index)
-
deleteLast
public final VarString deleteLast()
-
deleteLast
public final VarString deleteLast(int n)
-
shrinkTo
public final VarString shrinkTo(int n)
-
toArray
public final char[] toArray()
-
copyTo
public final VarString copyTo(char[] target, int targetOffset)
-
copyTo
public final VarString copyTo(int offset, char[] target, int targetOffset, int length)
-
isEmpty
public final boolean isEmpty()
-
consolidate
public final VarString consolidate()
-
trim
public final VarString trim()
-
truncateTo
public final VarString truncateTo(int newLength)
-
subsequence
public final VarString subsequence(int beginIndex, int endIndex)
-
substring
public final String substring(int beginIndex, int endIndex)
-
iterate
public final void iterate(_charProcedure iterator)
-
list
public final VarString list(String separator, XGettingCollection<?> listElements)
-
list
public final VarString list(String separator, VarString.Appendable... listElements)
-
clear
public final VarString clear()
Fills this instance's char storage completely with zeros and sets its size to 0. Only preferable toreset()
for in-memory security reasons.- Returns:
- this
-
reset
public final VarString reset()
Simply resets this instance by setting its size to 0 while leaving the actual char storage untouched.- Returns:
- this
-
blank
public final VarString blank()
-
blank
public final VarString blank(int amount)
-
tab
public final VarString tab()
-
tab
public final VarString tab(int amount)
-
cr
public final VarString cr()
-
cr
public final VarString cr(int amount)
-
lf
public final VarString lf()
-
lf
public final VarString lf(int amount)
-
crlf
public final VarString crlf()
-
repeat
public final VarString repeat(int amount, char c)
-
repeat
public final VarString repeat(int amount, char[] chars)
-
equalsAt
public final boolean equalsAt(int index, char[] chars, int charsOffset, int charsLength)
-
endsWith
public final boolean endsWith(char c)
-
endsWith
public final boolean endsWith(char[] chars)
-
endsWith
public final boolean endsWith(String string)
-
replaceFirst
public final VarString replaceFirst(char sample, char replacement)
-
replaceFirst
public final VarString replaceFirst(char sample, char replacement, int offset)
-
replaceFirst
public final VarString replaceFirst(char sample, char replacement, int offset, int length)
-
replaceAll
public final VarString replaceAll(char sample, char replacement)
-
replaceAll
public final VarString replaceAll(char sample, char replacement, int offset)
-
replaceAll
public final VarString replaceAll(char sample, char replacement, int offset, int length)
-
replace
public final String replace(CharSequence target, CharSequence replacement)
-
encode
public final byte[] encode()
Alias forthis.encodeBy(XFiles.standardCharset());
for general purpose encoding, with the "standard" being UTF-8 (XFiles.utf8()
), because any other charset is nonsense for a general case.- Returns:
- the character data of this instance as an UTF-8 byte array.
- See Also:
encodeBy(Charset)
-
encodeBy
public final byte[] encodeBy(Charset charset)
-
charAt
public final char charAt(int index)
- Specified by:
charAt
in interfaceCharSequence
-
length
public final int length()
- Specified by:
length
in interfaceCharSequence
-
subSequence
public final VarString subSequence(int start, int end)
- Specified by:
subSequence
in interfaceCharSequence
-
append
public final VarString append(CharSequence csq)
- Specified by:
append
in interfaceAppendable
-
append
public final VarString append(char c)
- Specified by:
append
in interfaceAppendable
-
append
public final VarString append(CharSequence csq, int start, int end)
- Specified by:
append
in interfaceAppendable
-
toString
public final String toString()
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
-