Class CharSeq
- java.lang.Object
-
- io.vavr.collection.CharSeq
-
- All Implemented Interfaces:
Foldable<java.lang.Character>
,IndexedSeq<java.lang.Character>
,Seq<java.lang.Character>
,Traversable<java.lang.Character>
,Function1<java.lang.Integer,java.lang.Character>
,Iterable<java.lang.Character>
,PartialFunction<java.lang.Integer,java.lang.Character>
,Value<java.lang.Character>
,java.io.Serializable
,java.lang.CharSequence
,java.lang.Comparable<CharSeq>
,java.lang.Iterable<java.lang.Character>
,java.util.function.Function<java.lang.Integer,java.lang.Character>
public final class CharSeq extends java.lang.Object implements java.lang.CharSequence, IndexedSeq<java.lang.Character>, java.io.Serializable, java.lang.Comparable<CharSeq>
The CharSeq (read: character sequence) collection essentially is a rich String wrapper having all operations we know from the functional Vavr collections.Note:Because CharSeq represents a sequence of primitive characters (i.e. a String), it breaks the Liskov Substitution Principle in the way, that the CharSeq cannot contain
null
elements. In future version of Java, CharSeq should extend IndexedSeq<char> instead.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CharSeq.CharFunction<R>
static interface
CharSeq.CharUnaryOperator
-
Method Summary
Modifier and Type Method Description CharSeq
append(java.lang.Character element)
Appends an element to this.CharSeq
appendAll(java.lang.Iterable<? extends java.lang.Character> elements)
Appends all given elements to this.java.util.List<java.lang.Character>
asJava()
Creates an immutableList
view on top of thisSeq
, i.e.CharSeq
asJava(java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)
Creates an immutableList
view on top of thisSeq
that is passed to the givenaction
.java.util.List<java.lang.Character>
asJavaMutable()
Creates a mutableList
view on top of thisSeq
, i.e.CharSeq
asJavaMutable(java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)
Creates a mutableList
view on top of thisSeq
that is passed to the givenaction
.CharSeq
capitalize()
Converts the first character in thisCharSeq
to upper case using the rules of the default locale.CharSeq
capitalize(java.util.Locale locale)
Converts the first character in thisCharSeq
to upper case using the rules of the givenLocale
.char
charAt(int index)
Returns thechar
value at the specified index.int
codePointAt(int index)
Returns the character (Unicode code point) at the specified index.int
codePointBefore(int index)
Returns the character (Unicode code point) before the specified index.int
codePointCount(int beginIndex, int endIndex)
Returns the number of Unicode code points in the specified text range of thisCharSeq
.<R> IndexedSeq<R>
collect(PartialFunction<? super java.lang.Character,? extends R> partialFunction)
Collects all elements that are in the domain of the givenpartialFunction
by mapping the elements to typeR
.static java.util.stream.Collector<java.lang.Character,java.util.ArrayList<java.lang.Character>,CharSeq>
collector()
Returns aCollector
which may be used in conjunction withStream.collect(java.util.stream.Collector)
to obtain aCharSeq
.IndexedSeq<CharSeq>
combinations()
Returns the union of all combinations from k = 0 to length().IndexedSeq<CharSeq>
combinations(int k)
Returns the k-combination of this traversable, i.e.int
compareTo(CharSeq anotherString)
Compares two strings lexicographically.int
compareToIgnoreCase(CharSeq str)
Compares two strings lexicographically, ignoring case differences.CharSeq
concat(CharSeq str)
Concatenates the specified string to the end of this string.boolean
contains(java.lang.CharSequence s)
Returns true if and only if this string contains the specified sequence of char values.boolean
contentEquals(java.lang.CharSequence cs)
Compares this string to the specifiedCharSequence
.boolean
contentEquals(java.lang.StringBuffer sb)
Compares this string to the specifiedStringBuffer
.Iterator<CharSeq>
crossProduct(int power)
Calculates the n-ary cartesian power (or cross product or simply product) of this.java.lang.Byte
decodeByte()
Decodes thisCharSeq
into aByte
by callingByte.decode(String)
.java.lang.Integer
decodeInteger()
Decodes thisCharSeq
into anInteger
by callingInteger.decode(String)
.java.lang.Long
decodeLong()
Decodes thisCharSeq
into aLong
by callingLong.decode(String)
.java.lang.Short
decodeShort()
Decodes thisCharSeq
into aShort
by callingShort.decode(String)
.CharSeq
distinct()
Returns a new version of this which contains no duplicates.CharSeq
distinctBy(java.util.Comparator<? super java.lang.Character> comparator)
Returns a new version of this which contains no duplicates.<U> CharSeq
distinctBy(java.util.function.Function<? super java.lang.Character,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.CharSeq
drop(int n)
Drops the first n elements of this or all elements, if this length < n.CharSeq
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.CharSeq
dropRightUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Drops elements until the predicate holds for the current element, starting from the end.CharSeq
dropRightWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Drops elements while the predicate holds for the current element, starting from the end.CharSeq
dropUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Drops elements until the predicate holds for the current element.CharSeq
dropWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Drops elements while the predicate holds for the current element.static CharSeq
empty()
boolean
endsWith(CharSeq suffix)
Tests if this string ends with the specified suffix.boolean
equals(java.lang.Object o)
In Vavr there are four basic classes of collections: Seq (sequential elements) Set (distinct elements) Map (indexed elements) Multimap (indexed collections) Two collection instances of these classes are equal if and only if both collections belong to the same basic collection class (Seq, Set, Map or Multimap) contain the same elements have the same element order, if the collections are of type Seq Two Map/Multimap elements, resp.boolean
equalsIgnoreCase(CharSeq anotherString)
Compares thisCharSeq
to anotherCharSeq
, ignoring case considerations.static CharSeq
fill(int n, java.util.function.Supplier<? extends java.lang.Character> s)
Returns a CharSeq containingn
values supplied by a given Suppliers
.CharSeq
filter(java.util.function.Predicate<? super java.lang.Character> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.CharSeq
filterNot(java.util.function.Predicate<? super java.lang.Character> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.<U> IndexedSeq<U>
flatMap(java.util.function.Function<? super java.lang.Character,? extends java.lang.Iterable<? extends U>> mapper)
FlatMaps this Traversable.CharSeq
flatMapChars(CharSeq.CharFunction<? extends java.lang.CharSequence> mapper)
java.lang.Character
get(int index)
Returns the element at the specified index.byte[]
getBytes()
Encodes thisCharSeq
into a sequence of bytes using the platform's default charset, storing the result into a new byte array.byte[]
getBytes(java.lang.String charsetName)
Encodes thisCharSeq
into a sequence of bytes using the named charset, storing the result into a new byte array.byte[]
getBytes(java.nio.charset.Charset charset)
Encodes thisCharSeq
into a sequence of bytes using the given charset, storing the result into a new byte array.void
getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Copies characters from this string into the destination character array.<C> Map<C,CharSeq>
groupBy(java.util.function.Function<? super java.lang.Character,? extends C> classifier)
Groups this elements by classifying the elements.Iterator<CharSeq>
grouped(int size)
Groups thisTraversable
into fixed size blocks.boolean
hasDefiniteSize()
Checks if this Traversable is known to have a finite size.int
hashCode()
Returns the hash code of this collection.java.lang.Character
head()
Returns the first element of a non-empty Traversable.int
indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character.int
indexOf(int ch, int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.int
indexOf(CharSeq str)
Returns the index within this string of the first occurrence of the specified substring.int
indexOf(CharSeq str, int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.int
indexOf(java.lang.Character element, int from)
Returns the index of the first occurrence of the given element after or at some start index or -1 if this does not contain the given element.Option<java.lang.Integer>
indexOfOption(CharSeq str)
Returns the index of the first occurrence of the given element as anOption
.Option<java.lang.Integer>
indexOfOption(CharSeq str, int fromIndex)
Returns the index of the first occurrence of the given element as anOption
, starting the search at the specified index.CharSeq
init()
Dual of Traversable.tail(), returning all elements except the last.Option<CharSeq>
initOption()
Dual of Traversable.tailOption(), returning all elements except the last asOption
.CharSeq
insert(int index, java.lang.Character element)
Inserts the given element at the specified index.CharSeq
insertAll(int index, java.lang.Iterable<? extends java.lang.Character> elements)
Inserts the given elements at the specified index.CharSeq
intersperse(java.lang.Character element)
Inserts an element between all elements of this Traversable.boolean
isAsync()
ACharSeq
is computed synchronously.boolean
isEmpty()
Checks if this Traversable is empty.boolean
isLazy()
ACharSeq
is computed eagerly.boolean
isTraversableAgain()
Checks if this Traversable can be repeatedly traversed.Iterator<java.lang.Character>
iterator()
An iterator by means of head() and tail().int
lastIndexOf(int ch)
Returns the index within this string of the last occurrence of the specified character.int
lastIndexOf(int ch, int fromIndex)
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.int
lastIndexOf(CharSeq str)
Returns the index within this string of the last occurrence of the specified substring.int
lastIndexOf(CharSeq str, int fromIndex)
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.int
lastIndexOf(java.lang.Character element, int end)
Returns the index of the last occurrence of the given element before or at a given end index or -1 if this does not contain the given element.Option<java.lang.Integer>
lastIndexOfOption(int ch, int fromIndex)
Returns the index of the last occurrence of the given element as anOption
, starting the search at the specified index.Option<java.lang.Integer>
lastIndexOfOption(CharSeq str)
Returns the index of the last occurrence of the given element as anOption
.Option<java.lang.Integer>
lastIndexOfOption(CharSeq str, int fromIndex)
Returns the index of the last occurrence of the given element as anOption
, starting the search at the specified index.CharSeq
leftPadTo(int length, java.lang.Character element)
A copy of this sequence with an element prepended until a given target length is reached.int
length()
Returns the length of this string.<U> IndexedSeq<U>
map(java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Maps the elements of thisTraversable
to elements of a new type preserving their order, if any.CharSeq
mapChars(CharSeq.CharUnaryOperator mapper)
boolean
matches(java.lang.String regex)
Tells whether or not this string matches the given regular expression.java.lang.String
mkString()
Joins the elements of this by concatenating their string representations.static CharSeq
of(char character)
Returns a singletonCharSeq
, i.e.static CharSeq
of(char... characters)
Creates a String of the given characters.static CharSeq
of(java.lang.CharSequence sequence)
Creates a String ofCharSequence
.static CharSeq
ofAll(java.lang.Iterable<? extends java.lang.Character> elements)
Creates a String of the given elements.int
offsetByCodePoints(int index, int codePointOffset)
Returns the index within thisCharSeq
that is offset from the givenindex
bycodePointOffset
code points.CharSeq
orElse(java.lang.Iterable<? extends java.lang.Character> other)
Returns thisTraversable
if it is nonempty, otherwise return the alternative.CharSeq
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends java.lang.Character>> supplier)
Returns thisTraversable
if it is nonempty, otherwise return the result of evaluating supplier.CharSeq
padTo(int length, java.lang.Character element)
A copy of this sequence with an element appended until a given target length is reached.boolean
parseBoolean()
Parses thisCharSeq
as a boolean by callingBoolean.parseBoolean(String)
.byte
parseByte()
Parses thisCharSeq
as a signed decimal byte by callingByte.parseByte(String)
.byte
parseByte(int radix)
Parses thisCharSeq
as a signed byte in the specified radix by callingByte.parseByte(String, int)
.double
parseDouble()
Parses thisCharSeq
as a double by callingDouble.parseDouble(String)
.float
parseFloat()
Parses thisCharSeq
as a float by callingFloat.parseFloat(String)
.int
parseInt()
Parses thisCharSeq
as a signed decimal int by callingInteger.parseInt(String)
.int
parseInt(int radix)
Parses thisCharSeq
as a signed int in the specified radix by callingInteger.parseInt(String, int)
.long
parseLong()
Parses thisCharSeq
as a signed decimal long by callingLong.parseLong(String)
.long
parseLong(int radix)
Parses thisCharSeq
as a signed long in the specified radix by callingLong.parseLong(String, int)
.short
parseShort()
Parses thisCharSeq
as a signed decimal short by callingShort.parseShort(String)
.short
parseShort(int radix)
Parses thisCharSeq
as a signed short in the specified radix by callingShort.parseShort(String, int)
.int
parseUnsignedInt()
Parses thisCharSeq
as a unsigned decimal int by callingInteger.parseUnsignedInt(String)
.int
parseUnsignedInt(int radix)
Parses thisCharSeq
as a unsigned int in the specified radix by callingInteger.parseUnsignedInt(String, int)
.long
parseUnsignedLong()
Parses thisCharSeq
as a unsigned decimal long by callingLong.parseUnsignedLong(String)
.long
parseUnsignedLong(int radix)
Parses thisCharSeq
as a unsigned long in the specified radix by callingLong.parseUnsignedLong(String, int)
.Tuple2<CharSeq,CharSeq>
partition(java.util.function.Predicate<? super java.lang.Character> predicate)
Creates a partition of thisTraversable
by splitting this elements in two in distinct traversables according to a predicate.CharSeq
patch(int from, java.lang.Iterable<? extends java.lang.Character> that, int replaced)
Produces a new list where a slice of elements in this list is replaced by another sequence.CharSeq
peek(java.util.function.Consumer<? super java.lang.Character> action)
Performs the givenaction
on the first element if this is an eager implementation.IndexedSeq<CharSeq>
permutations()
Computes all unique permutations.CharSeq
prepend(java.lang.Character element)
Prepends an element to this.CharSeq
prependAll(java.lang.Iterable<? extends java.lang.Character> elements)
Prepends all given elements to this.static CharSeq
range(char from, char toExclusive)
Creates a CharSeq starting from characterfrom
, extending to charactertoExclusive - 1
.static CharSeq
rangeBy(char from, char toExclusive, int step)
static CharSeq
rangeClosed(char from, char toInclusive)
Creates a CharSeq starting from characterfrom
, extending to charactertoInclusive
.static CharSeq
rangeClosedBy(char from, char toInclusive, int step)
Creates a CharSeq starting from characterfrom
, extending to charactertoInclusive
, withstep
.boolean
regionMatches(boolean ignoreCase, int toffset, CharSeq other, int ooffset, int len)
Tests if two string regions are equal.boolean
regionMatches(int toffset, CharSeq other, int ooffset, int len)
Tests if two string regions are equal.CharSeq
reject(java.util.function.Predicate<? super java.lang.Character> predicate)
Deprecated.CharSeq
remove(java.lang.Character element)
Removes the first occurrence of the given element.CharSeq
removeAll(java.lang.Character element)
Removes all occurrences of the given element.CharSeq
removeAll(java.lang.Iterable<? extends java.lang.Character> elements)
Removes all occurrences of the given elements.CharSeq
removeAll(java.util.function.Predicate<? super java.lang.Character> predicate)
Deprecated.CharSeq
removeAt(int index)
Removes the element at the specified position in this sequence.CharSeq
removeFirst(java.util.function.Predicate<java.lang.Character> predicate)
Removes the first occurrence that satisfy predicateCharSeq
removeLast(java.util.function.Predicate<java.lang.Character> predicate)
Removes the last occurrence that satisfy predicatestatic CharSeq
repeat(char character, int times)
Repeats a charactertimes
times.CharSeq
repeat(int times)
Repeats this CharSeqtimes
times.CharSeq
replace(java.lang.Character currentElement, java.lang.Character newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.CharSeq
replace(java.lang.CharSequence target, java.lang.CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.CharSeq
replaceAll(java.lang.Character currentElement, java.lang.Character newElement)
Replaces all occurrences of the given currentElement with newElement.CharSeq
replaceAll(java.lang.String regex, java.lang.String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.CharSeq
replaceFirst(java.lang.String regex, java.lang.String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.CharSeq
retainAll(java.lang.Iterable<? extends java.lang.Character> elements)
Keeps all occurrences of the given elements from this.CharSeq
reverse()
Reverses the order of elements.CharSeq
rotateLeft(int n)
Circular rotates the elements by the specified distance to the left direction.CharSeq
rotateRight(int n)
Circular rotates the elements by the specified distance to the right direction.CharSeq
scan(java.lang.Character zero, java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Character,? extends java.lang.Character> operation)
Computes a prefix scan of the elements of the collection.<U> IndexedSeq<U>
scanLeft(U zero, java.util.function.BiFunction<? super U,? super java.lang.Character,? extends U> operation)
Produces a collection containing cumulative results of applying the operator going left to right.<U> IndexedSeq<U>
scanRight(U zero, java.util.function.BiFunction<? super java.lang.Character,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the operator going right to left.CharSeq
shuffle()
Randomize the order of the elements in the current sequence.CharSeq
shuffle(java.util.Random random)
Randomize the order of the elements in the current sequence using the given source of randomness.CharSeq
slice(int beginIndex, int endIndex)
Returns a Seq that is a slice of this.Iterator<CharSeq>
slideBy(java.util.function.Function<? super java.lang.Character,?> classifier)
Slides a non-overlapping window of a variable size over thisTraversable
.Iterator<CharSeq>
sliding(int size)
Slides a window of a specificsize
and step size 1 over thisTraversable
by callingTraversable.sliding(int, int)
.Iterator<CharSeq>
sliding(int size, int step)
Slides a window of a specificsize
andstep
size over thisTraversable
.<U> CharSeq
sortBy(java.util.Comparator<? super U> comparator, java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Sorts this elements by comparing the elements in a different domain, using the givenmapper
.<U extends java.lang.Comparable<? super U>>
CharSeqsortBy(java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Sorts this elements by comparing the elements in a different domain, using the givenmapper
.CharSeq
sorted()
Sorts this elements according to their natural order.CharSeq
sorted(java.util.Comparator<? super java.lang.Character> comparator)
Sorts this elements according to the providedComparator
.Tuple2<CharSeq,CharSeq>
span(java.util.function.Predicate<? super java.lang.Character> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the givenpredicate
and the second element is the remainder.Seq<CharSeq>
split(java.lang.String regex)
Splits this string around matches of the given regular expression.Seq<CharSeq>
split(java.lang.String regex, int limit)
Splits this string around matches of the given regular expression.Tuple2<CharSeq,CharSeq>
splitAt(int n)
Splits a Seq at the specified index.Tuple2<CharSeq,CharSeq>
splitAt(java.util.function.Predicate<? super java.lang.Character> predicate)
Splits a sequence at the first element which satisfies thePredicate
, e.g.Tuple2<CharSeq,CharSeq>
splitAtInclusive(java.util.function.Predicate<? super java.lang.Character> predicate)
Splits a sequence at the first element which satisfies thePredicate
, e.g.boolean
startsWith(CharSeq prefix)
Tests if this string starts with the specified prefix.boolean
startsWith(CharSeq prefix, int toffset)
Tests if the substring of this string beginning at the specified index starts with the specified prefix.boolean
startsWith(java.lang.Iterable<? extends java.lang.Character> that, int offset)
Tests whether this list contains the given sequence at a given index.java.lang.String
stringPrefix()
Returns the name of this Value type, which is used by toString().CharSeq
subSequence(int beginIndex)
Returns a Seq that is a subsequence of this.CharSeq
subSequence(int beginIndex, int endIndex)
Returns a Seq that is a subsequence of this.CharSeq
substring(int beginIndex)
Returns a string that is a substring of this string.CharSeq
substring(int beginIndex, int endIndex)
Returns a string that is a substring of this string.static CharSeq
tabulate(int n, java.util.function.Function<? super java.lang.Integer,? extends java.lang.Character> f)
Returns a CharSeq containingn
values of a given Functionf
over a range of integer values from 0 ton - 1
.CharSeq
tail()
Drops the first element of a non-empty Traversable.Option<CharSeq>
tailOption()
Drops the first element of a non-empty Traversable and returns anOption
.CharSeq
take(int n)
Takes the first n elements of this or all elements, if this length < n.CharSeq
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.CharSeq
takeRightUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Takes elements until the predicate holds for the current element, starting from the end.CharSeq
takeRightWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Takes elements while the predicate holds for the current element, starting from the end.CharSeq
takeUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Takes elements until the predicate holds for the current element.CharSeq
takeWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Takes elements while the predicate holds for the current element.java.lang.Boolean
toBoolean()
Converts thisCharSeq
to aBoolean
by callingBoolean.valueOf(String)
.java.lang.Byte
toByte()
Converts thisCharSeq
to aByte
by callingByte.valueOf(String)
.java.lang.Byte
toByte(int radix)
Converts thisCharSeq
to aByte
in the specified radix by callingByte.valueOf(String, int)
.char[]
toCharArray()
Converts this string to a new character array.java.lang.Double
toDouble()
Converts thisCharSeq
to aDouble
by callingDouble.valueOf(String)
.java.lang.Float
toFloat()
Converts thisCharSeq
to aFloat
by callingFloat.valueOf(String)
.java.lang.Integer
toInteger()
Converts thisCharSeq
to anInteger
by callingInteger.valueOf(String)
.java.lang.Integer
toInteger(int radix)
Converts thisCharSeq
to anInteger
in the specified radix by callingInteger.valueOf(String, int)
.java.lang.Character[]
toJavaArray()
Converts this to a Java array with component typeObject
java.lang.Long
toLong()
Converts thisCharSeq
to aLong
by callingLong.valueOf(String)
.java.lang.Long
toLong(int radix)
Converts thisCharSeq
to aLong
in the specified radix by callingLong.valueOf(String, int)
.CharSeq
toLowerCase()
Converts all of the characters in thisCharSeq
to lower case using the rules of the default locale.CharSeq
toLowerCase(java.util.Locale locale)
Converts all of the characters in thisCharSeq
to lower case using the rules of the givenLocale
.java.lang.Short
toShort()
Converts thisCharSeq
to aShort
by callingShort.valueOf(String)
.java.lang.Short
toShort(int radix)
Converts thisCharSeq
to aShort
in the specified radix by callingShort.valueOf(String, int)
.java.lang.String
toString()
Returns a string containing the characters in this sequence in the same order as this sequence.CharSeq
toUpperCase()
Converts all of the characters in thisCharSeq
to upper case using the rules of the default locale.CharSeq
toUpperCase(java.util.Locale locale)
Converts all of the characters in thisCharSeq
to upper case using the rules of the givenLocale
.<U> U
transform(java.util.function.Function<? super CharSeq,? extends U> f)
Transforms thisCharSeq
.CharSeq
trim()
Returns a string whose value is this string, with any leading and trailing whitespace removed.static CharSeq
unfold(java.lang.Character seed, java.util.function.Function<? super java.lang.Character,Option<Tuple2<? extends java.lang.Character,? extends java.lang.Character>>> f)
Creates a CharSeq from a seed value and a function.static <T> CharSeq
unfoldLeft(T seed, java.util.function.Function<? super T,Option<Tuple2<? extends T,? extends java.lang.Character>>> f)
Creates a CharSeq from a seed value and a function.static <T> CharSeq
unfoldRight(T seed, java.util.function.Function<? super T,Option<Tuple2<? extends java.lang.Character,? extends T>>> f)
Creates a CharSeq from a seed value and a function.<T1,T2>
Tuple2<IndexedSeq<T1>,IndexedSeq<T2>>unzip(java.util.function.Function<? super java.lang.Character,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct sets.<T1,T2,T3>
Tuple3<IndexedSeq<T1>,IndexedSeq<T2>,IndexedSeq<T3>>unzip3(java.util.function.Function<? super java.lang.Character,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct sets.CharSeq
update(int index, java.lang.Character element)
Updates the given element at the specified index.CharSeq
update(int index, java.util.function.Function<? super java.lang.Character,? extends java.lang.Character> updater)
Updates the given element at the specified index using the specified function.<U> IndexedSeq<Tuple2<java.lang.Character,U>>
zip(java.lang.Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining corresponding elements in pairs.<U> IndexedSeq<Tuple2<java.lang.Character,U>>
zipAll(java.lang.Iterable<? extends U> that, java.lang.Character thisElem, U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in pairs.<U,R>
IndexedSeq<R>zipWith(java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super java.lang.Character,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.IndexedSeq<Tuple2<java.lang.Character,java.lang.Integer>>
zipWithIndex()
Zips this traversable with its indices.<U> IndexedSeq<U>
zipWithIndex(java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, curried, isMemoized, memoized, partial, reversed, tupled
-
Methods inherited from interface io.vavr.collection.IndexedSeq
asPartialFunction, endsWith, indexOfSlice, indexWhere, isDefinedAt, last, lastIndexOfSlice, lastIndexWhere, reverseIterator, search, search, segmentLength
-
Methods inherited from interface io.vavr.collection.Seq
apply, containsSlice, crossProduct, crossProduct, foldRight, indexOf, indexOfOption, indexOfOption, indexOfSlice, indexOfSliceOption, indexOfSliceOption, indexWhere, indexWhereOption, indexWhereOption, isSequential, iterator, lastIndexOf, lastIndexOfOption, lastIndexOfOption, lastIndexOfSlice, lastIndexOfSliceOption, lastIndexOfSliceOption, lastIndexWhere, lastIndexWhereOption, lastIndexWhereOption, lift, prefixLength, startsWith, withDefault, withDefaultValue
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, fold, foldLeft, forEachWithIndex, get, headOption, isDistinct, isOrdered, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, nonEmpty, product, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
-
-
-
Method Detail
-
empty
public static CharSeq empty()
-
collector
public static java.util.stream.Collector<java.lang.Character,java.util.ArrayList<java.lang.Character>,CharSeq> collector()
Returns aCollector
which may be used in conjunction withStream.collect(java.util.stream.Collector)
to obtain aCharSeq
.- Returns:
- A
CharSeq
Collector.
-
of
public static CharSeq of(java.lang.CharSequence sequence)
Creates a String ofCharSequence
.- Parameters:
sequence
-CharSequence
instance.- Returns:
- A new
CharSeq
-
of
public static CharSeq of(char character)
Returns a singletonCharSeq
, i.e. aCharSeq
of one character.- Parameters:
character
- A character.- Returns:
- A new
CharSeq
instance containing the given element
-
of
public static CharSeq of(char... characters)
Creates a String of the given characters.- Parameters:
characters
- Zero or more characters.- Returns:
- A string containing the given characters in the same order.
- Throws:
java.lang.NullPointerException
- ifelements
is null
-
ofAll
public static CharSeq ofAll(java.lang.Iterable<? extends java.lang.Character> elements)
Creates a String of the given elements.The resulting string has the same iteration order as the given iterable of elements if the iteration order of the elements is stable.
- Parameters:
elements
- An Iterable of elements.- Returns:
- A string containing the given elements in the same order.
- Throws:
java.lang.NullPointerException
- ifelements
is null orelements
contains null
-
tabulate
public static CharSeq tabulate(int n, java.util.function.Function<? super java.lang.Integer,? extends java.lang.Character> f)
Returns a CharSeq containingn
values of a given Functionf
over a range of integer values from 0 ton - 1
.- Parameters:
n
- The number of elements in the CharSeqf
- The Function computing element values- Returns:
- A CharSeq consisting of elements
f(0),f(1), ..., f(n - 1)
- Throws:
java.lang.NullPointerException
- iff
is null
-
fill
public static CharSeq fill(int n, java.util.function.Supplier<? extends java.lang.Character> s)
Returns a CharSeq containingn
values supplied by a given Suppliers
.- Parameters:
n
- The number of elements in the CharSeqs
- The Supplier computing element values- Returns:
- A CharSeq of size
n
, where each element contains the result supplied bys
. - Throws:
java.lang.NullPointerException
- ifs
is null
-
range
public static CharSeq range(char from, char toExclusive)
Creates a CharSeq starting from characterfrom
, extending to charactertoExclusive - 1
.Examples:
CharSeq.range('a', 'c') // = "ab" CharSeq.range('c', 'a') // = ""
- Parameters:
from
- the first charactertoExclusive
- the successor of the last character- Returns:
- a range of characters as specified or the empty range if
from >= toExclusive
-
rangeBy
public static CharSeq rangeBy(char from, char toExclusive, int step)
-
rangeClosed
public static CharSeq rangeClosed(char from, char toInclusive)
Creates a CharSeq starting from characterfrom
, extending to charactertoInclusive
.Examples:
CharSeq.rangeClosed('a', 'c') // = "abc" CharSeq.rangeClosed('c', 'a') // = ""
- Parameters:
from
- the first charactertoInclusive
- the last character- Returns:
- a range of characters as specified or the empty range if
from > toInclusive
-
rangeClosedBy
public static CharSeq rangeClosedBy(char from, char toInclusive, int step)
Creates a CharSeq starting from characterfrom
, extending to charactertoInclusive
, withstep
.Examples:
CharSeq.rangeClosedBy('a', 'c', 1) // = ('a', 'b', 'c') CharSeq.rangeClosedBy('a', 'd', 2) // = ('a', 'c') CharSeq.rangeClosedBy('d', 'a', -2) // = ('d', 'b') CharSeq.rangeClosedBy('d', 'a', 2) // = ()
- Parameters:
from
- the first charactertoInclusive
- the last characterstep
- the step- Returns:
- a range of characters as specified or the empty range if
step * (from - toInclusive) > 0
. - Throws:
java.lang.IllegalArgumentException
- ifstep
is zero
-
unfoldRight
public static <T> CharSeq unfoldRight(T seed, java.util.function.Function<? super T,Option<Tuple2<? extends java.lang.Character,? extends T>>> f)
Creates a CharSeq from a seed value and a function. The function takes the seed at first. The function should returnNone
when it's done generating the CharSeq, otherwiseSome
Tuple
of the element for the next call and the value to add to the resulting CharSeq.Example:
CharSeq.unfoldRight('j', x -> x == 'a' ? Option.none() : Option.of(new Tuple2<>(new Character(x), (char)(x-1)))); // CharSeq.of("jihgfedcb"))
- Type Parameters:
T
- type of seeds- Parameters:
seed
- the start value for the iterationf
- the function to get the next step of the iteration- Returns:
- a CharSeq with the values built up by the iteration
- Throws:
java.lang.NullPointerException
- iff
is null
-
unfoldLeft
public static <T> CharSeq unfoldLeft(T seed, java.util.function.Function<? super T,Option<Tuple2<? extends T,? extends java.lang.Character>>> f)
Creates a CharSeq from a seed value and a function. The function takes the seed at first. The function should returnNone
when it's done generating the CharSeq, otherwiseSome
Tuple
of the value to add to the resulting CharSeq and the element for the next call.Example:
CharSeq.unfoldLeft('j', x -> x == 'a' ? Option.none() : Option.of(new Tuple2<>((char)(x-1), new Character(x)))); // CharSeq.of("bcdefghij"))
- Type Parameters:
T
- type of seeds- Parameters:
seed
- the start value for the iterationf
- the function to get the next step of the iteration- Returns:
- a CharSeq with the values built up by the iteration
- Throws:
java.lang.NullPointerException
- iff
is null
-
unfold
public static CharSeq unfold(java.lang.Character seed, java.util.function.Function<? super java.lang.Character,Option<Tuple2<? extends java.lang.Character,? extends java.lang.Character>>> f)
Creates a CharSeq from a seed value and a function. The function takes the seed at first. The function should returnNone
when it's done generating the CharSeq, otherwiseSome
Tuple
of the value to add to the resulting CharSeq and the element for the next call.Example:
CharSeq.unfold('j', x -> x == 'a' ? Option.none() : Option.of(new Tuple2<>((char)(x-1), new Character(x)))); // CharSeq.of("bcdefghij"))
- Parameters:
seed
- the start value for the iterationf
- the function to get the next step of the iteration- Returns:
- a CharSeq with the values built up by the iteration
- Throws:
java.lang.NullPointerException
- iff
is null
-
repeat
public static CharSeq repeat(char character, int times)
Repeats a charactertimes
times.- Parameters:
character
- A charactertimes
- Repetition count- Returns:
- A CharSeq representing
character * times
-
repeat
public CharSeq repeat(int times)
Repeats this CharSeqtimes
times.Example:
CharSeq.of("ja").repeat(13) = "jajajajajajajajajajajajaja"
- Parameters:
times
- Repetition count- Returns:
- A CharSeq representing
this * times
-
append
public CharSeq append(java.lang.Character element)
Description copied from interface:Seq
Appends an element to this.- Specified by:
append
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
append
in interfaceSeq<java.lang.Character>
- Parameters:
element
- An element- Returns:
- A new Seq containing the given element appended to this elements
-
appendAll
public CharSeq appendAll(java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:Seq
Appends all given elements to this.- Specified by:
appendAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
appendAll
in interfaceSeq<java.lang.Character>
- Parameters:
elements
- An Iterable of elements- Returns:
- A new Seq containing the given elements appended to this elements
-
asJava
@GwtIncompatible public java.util.List<java.lang.Character> asJava()
Description copied from interface:Seq
Creates an immutableList
view on top of thisSeq
, i.e. calling mutators will result inUnsupportedOperationException
at runtime.The difference to conversion methods
toJava*()
is that- A view is created in O(1) (constant time) whereas conversion takes O(n) (linear time), with n = collection size.
- The operations on a view have the same performance characteristics than the underlying persistent Vavr collection whereas the performance characteristics of a converted collection are those of the Java standard collections.
java.util.List
view throwsUnsupportedOperationException
before checking method arguments. Java does handle this case inconsistently.
-
asJava
@GwtIncompatible public CharSeq asJava(java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)
Description copied from interface:Seq
Creates an immutableList
view on top of thisSeq
that is passed to the givenaction
.- Specified by:
asJava
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
asJava
in interfaceSeq<java.lang.Character>
- Parameters:
action
- A side-effecting unit of work that operates on an immutablejava.util.List
view.- Returns:
- this instance
- See Also:
Seq.asJava()
-
asJavaMutable
@GwtIncompatible public java.util.List<java.lang.Character> asJavaMutable()
Description copied from interface:Seq
Creates a mutableList
view on top of thisSeq
, i.e. all mutator methods of theList
are implemented.- Specified by:
asJavaMutable
in interfaceSeq<java.lang.Character>
- Returns:
- A new mutable
Collection
view on thisTraversable
. - See Also:
Seq.asJava()
-
asJavaMutable
@GwtIncompatible public CharSeq asJavaMutable(java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)
Description copied from interface:Seq
Creates a mutableList
view on top of thisSeq
that is passed to the givenaction
.- Specified by:
asJavaMutable
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
asJavaMutable
in interfaceSeq<java.lang.Character>
- Parameters:
action
- A side-effecting unit of work that operates on a mutablejava.util.List
view.- Returns:
- this instance, if only read operations are performed on the
java.util.List
view or a new instance of this type, if write operations are performed on thejava.util.List
view. - See Also:
Seq.asJavaMutable()
-
collect
public <R> IndexedSeq<R> collect(PartialFunction<? super java.lang.Character,? extends R> partialFunction)
Description copied from interface:Traversable
Collects all elements that are in the domain of the givenpartialFunction
by mapping the elements to typeR
.More specifically, for each of this elements in iteration order first it is checked
If the elements makes it through that filter, the mapped instance is added to the result collectionpartialFunction.isDefinedAt(element)
Note:If thisR newElement = partialFunction.apply(element)
Traversable
is ordered (i.e. extendsOrdered
, the caller ofcollect
has to ensure that the elements are comparable (i.e. extendComparable
).- Specified by:
collect
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
collect
in interfaceSeq<java.lang.Character>
- Specified by:
collect
in interfaceTraversable<java.lang.Character>
- Type Parameters:
R
- The new element type- Parameters:
partialFunction
- A function that is not necessarily defined of all elements of this traversable.- Returns:
- A new
Traversable
instance containing elements of typeR
-
combinations
public IndexedSeq<CharSeq> combinations()
Description copied from interface:Seq
Returns the union of all combinations from k = 0 to length().Examples:
[].combinations() = [[]] [1,2,3].combinations() = [ [], // k = 0 [1], [2], [3], // k = 1 [1,2], [1,3], [2,3], // k = 2 [1,2,3] // k = 3 ]
- Specified by:
combinations
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
combinations
in interfaceSeq<java.lang.Character>
- Returns:
- the combinations of this
-
combinations
public IndexedSeq<CharSeq> combinations(int k)
Description copied from interface:Seq
Returns the k-combination of this traversable, i.e. all subset of this of k distinct elements.- Specified by:
combinations
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
combinations
in interfaceSeq<java.lang.Character>
- Parameters:
k
- Size of subsets- Returns:
- the k-combination of this elements
- See Also:
- Combination
-
crossProduct
public Iterator<CharSeq> crossProduct(int power)
Description copied from interface:Seq
Calculates the n-ary cartesian power (or cross product or simply product) of this.Example:
// = ((A,A), (A,B), (A,C), ..., (B,A), (B,B), ..., (Z,Y), (Z,Z)) CharSeq.rangeClosed('A', 'Z').crossProduct(2);
Cartesian power of negative value will return empty iterator.
Example:
// = () CharSeq.rangeClosed('A', 'Z').crossProduct(-1);
- Specified by:
crossProduct
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
crossProduct
in interfaceSeq<java.lang.Character>
- Parameters:
power
- the number of cartesian multiplications- Returns:
- A new Iterator representing the n-ary cartesian power of this
-
distinct
public CharSeq distinct()
Description copied from interface:Traversable
Returns a new version of this which contains no duplicates. Elements are compared usingequals
.- Specified by:
distinct
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
distinct
in interfaceSeq<java.lang.Character>
- Specified by:
distinct
in interfaceTraversable<java.lang.Character>
- Returns:
- a new
Traversable
containing this elements without duplicates
-
distinctBy
public CharSeq distinctBy(java.util.Comparator<? super java.lang.Character> comparator)
Description copied from interface:Traversable
Returns a new version of this which contains no duplicates. Elements are compared using the givencomparator
.- Specified by:
distinctBy
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
distinctBy
in interfaceSeq<java.lang.Character>
- Specified by:
distinctBy
in interfaceTraversable<java.lang.Character>
- Parameters:
comparator
- A comparator- Returns:
- a new
Traversable
containing this elements without duplicates
-
distinctBy
public <U> CharSeq distinctBy(java.util.function.Function<? super java.lang.Character,? extends U> keyExtractor)
Description copied from interface:Traversable
Returns a new version of this which contains no duplicates. Elements mapped to keys which are compared usingequals
.The elements of the result are determined in the order of their occurrence - first match wins.
- Specified by:
distinctBy
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
distinctBy
in interfaceSeq<java.lang.Character>
- Specified by:
distinctBy
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- key type- Parameters:
keyExtractor
- A key extractor- Returns:
- a new
Traversable
containing this elements without duplicates
-
drop
public CharSeq drop(int n)
Description copied from interface:Traversable
Drops the first n elements of this or all elements, if this length < n.- Specified by:
drop
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
drop
in interfaceSeq<java.lang.Character>
- Specified by:
drop
in interfaceTraversable<java.lang.Character>
- Parameters:
n
- The number of elements to drop.- Returns:
- a new instance consisting of all elements of this except the first n ones, or else the empty instance, if this has less than n elements.
-
dropUntil
public CharSeq dropUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Drops elements until the predicate holds for the current element.- Specified by:
dropUntil
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
dropUntil
in interfaceSeq<java.lang.Character>
- Specified by:
dropUntil
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements.- Returns:
- a new instance consisting of all elements starting from the first one which does satisfy the given predicate.
-
dropWhile
public CharSeq dropWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Drops elements while the predicate holds for the current element.Note: This is essentially the same as
dropUntil(predicate.negate())
. It is intended to be used with method references, which cannot be negated directly.- Specified by:
dropWhile
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
dropWhile
in interfaceSeq<java.lang.Character>
- Specified by:
dropWhile
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements.- Returns:
- a new instance consisting of all elements starting from the first one which does not satisfy the given predicate.
-
dropRight
public CharSeq dropRight(int n)
Description copied from interface:Traversable
Drops the last n elements of this or all elements, if this length < n.- Specified by:
dropRight
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
dropRight
in interfaceSeq<java.lang.Character>
- Specified by:
dropRight
in interfaceTraversable<java.lang.Character>
- Parameters:
n
- The number of elements to drop.- Returns:
- a new instance consisting of all elements of this except the last n ones, or else the empty instance, if this has less than n elements.
-
dropRightWhile
public CharSeq dropRightWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Seq
Drops elements while the predicate holds for the current element, starting from the end.Note: This is essentially the same as
dropRightUntil(predicate.negate())
. It is intended to be used with method references, which cannot be negated directly.- Specified by:
dropRightWhile
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
dropRightWhile
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements, starting from the end.- Returns:
- a new instance consisting of all elements until and including the last one which does not satisfy the given predicate.
-
dropRightUntil
public CharSeq dropRightUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Seq
Drops elements until the predicate holds for the current element, starting from the end.- Specified by:
dropRightUntil
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
dropRightUntil
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements, starting from the end.- Returns:
- a new instance consisting of all elements until and including the last one which does satisfy the given predicate.
-
filter
public CharSeq filter(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Returns a new traversable consisting of all elements which satisfy the given predicate.- Specified by:
filter
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
filter
in interfaceSeq<java.lang.Character>
- Specified by:
filter
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A predicate- Returns:
- a new traversable
-
filterNot
public CharSeq filterNot(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Returns a new traversable consisting of all elements which do not satisfy the given predicate.The default implementation is equivalent to
filter(predicate.negate()
- Specified by:
filterNot
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
filterNot
in interfaceSeq<java.lang.Character>
- Specified by:
filterNot
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A predicate- Returns:
- a new traversable
-
reject
@Deprecated public CharSeq reject(java.util.function.Predicate<? super java.lang.Character> predicate)
Deprecated.Description copied from interface:Traversable
Returns a new traversable consisting of all elements which do not satisfy the given predicate.The default implementation is equivalent to
filter(predicate.negate()
- Specified by:
reject
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
reject
in interfaceSeq<java.lang.Character>
- Specified by:
reject
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A predicate- Returns:
- a new traversable
-
flatMap
public <U> IndexedSeq<U> flatMap(java.util.function.Function<? super java.lang.Character,? extends java.lang.Iterable<? extends U>> mapper)
Description copied from interface:Traversable
FlatMaps this Traversable.- Specified by:
flatMap
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
flatMap
in interfaceSeq<java.lang.Character>
- Specified by:
flatMap
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- The resulting component type.- Parameters:
mapper
- A mapper- Returns:
- A new Traversable instance.
-
flatMapChars
public CharSeq flatMapChars(CharSeq.CharFunction<? extends java.lang.CharSequence> mapper)
-
groupBy
public <C> Map<C,CharSeq> groupBy(java.util.function.Function<? super java.lang.Character,? extends C> classifier)
Description copied from interface:Traversable
Groups this elements by classifying the elements.- Specified by:
groupBy
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
groupBy
in interfaceSeq<java.lang.Character>
- Specified by:
groupBy
in interfaceTraversable<java.lang.Character>
- Type Parameters:
C
- classified class type- Parameters:
classifier
- A function which classifies elements into classes- Returns:
- A Map containing the grouped elements
- See Also:
Traversable.arrangeBy(Function)
-
grouped
public Iterator<CharSeq> grouped(int size)
Description copied from interface:Traversable
Groups thisTraversable
into fixed size blocks.Let length be the length of this Iterable. Then grouped is defined as follows:
- If
this.isEmpty()
, the resultingIterator
is empty. - If
size <= length
, the resultingIterator
will containlength / size
blocks of sizesize
and maybe a non-empty block of sizelength % size
, if there are remaining elements. - If
size > length
, the resultingIterator
will contain one block of sizelength
.
[].grouped(1) = [] [].grouped(0) throws [].grouped(-1) throws [1,2,3,4].grouped(2) = [[1,2],[3,4]] [1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]] [1,2,3,4].grouped(5) = [[1,2,3,4]]
grouped(int)
is a special case of Traversable.sliding(int, int), i.e.grouped(size)
is the same assliding(size, size)
.- Specified by:
grouped
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
grouped
in interfaceSeq<java.lang.Character>
- Specified by:
grouped
in interfaceTraversable<java.lang.Character>
- Parameters:
size
- a positive block size- Returns:
- A new Iterator of grouped blocks of the given size
- If
-
hasDefiniteSize
public boolean hasDefiniteSize()
Description copied from interface:Traversable
Checks if this Traversable is known to have a finite size.This method should be implemented by classes only, i.e. not by interfaces.
- Specified by:
hasDefiniteSize
in interfaceTraversable<java.lang.Character>
- Returns:
- true, if this Traversable is known to have a finite size, false otherwise.
-
init
public CharSeq init()
Description copied from interface:Traversable
Dual of Traversable.tail(), returning all elements except the last.- Specified by:
init
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
init
in interfaceSeq<java.lang.Character>
- Specified by:
init
in interfaceTraversable<java.lang.Character>
- Returns:
- a new instance containing all elements except the last.
-
initOption
public Option<CharSeq> initOption()
Description copied from interface:Traversable
Dual of Traversable.tailOption(), returning all elements except the last asOption
.- Specified by:
initOption
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
initOption
in interfaceSeq<java.lang.Character>
- Specified by:
initOption
in interfaceTraversable<java.lang.Character>
- Returns:
Some(traversable)
orNone
if this is empty.
-
insert
public CharSeq insert(int index, java.lang.Character element)
Description copied from interface:Seq
Inserts the given element at the specified index.- Specified by:
insert
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
insert
in interfaceSeq<java.lang.Character>
- Parameters:
index
- an indexelement
- an element- Returns:
- a new Seq, where the given element is inserted into this at the given index
-
insertAll
public CharSeq insertAll(int index, java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:Seq
Inserts the given elements at the specified index.- Specified by:
insertAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
insertAll
in interfaceSeq<java.lang.Character>
- Parameters:
index
- an indexelements
- An Iterable of elements- Returns:
- a new Seq, where the given elements are inserted into this at the given index
-
iterator
public Iterator<java.lang.Character> iterator()
Description copied from interface:Traversable
An iterator by means of head() and tail(). Subclasses may want to override this method.- Specified by:
iterator
in interfaceIterable<java.lang.Character>
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Character>
- Specified by:
iterator
in interfaceTraversable<java.lang.Character>
- Specified by:
iterator
in interfaceValue<java.lang.Character>
- Returns:
- A new Iterator of this Traversable elements.
-
intersperse
public CharSeq intersperse(java.lang.Character element)
Description copied from interface:Seq
Inserts an element between all elements of this Traversable.- Specified by:
intersperse
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
intersperse
in interfaceSeq<java.lang.Character>
- Parameters:
element
- An element.- Returns:
- an interspersed version of this
-
map
public <U> IndexedSeq<U> map(java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Description copied from interface:Traversable
Maps the elements of thisTraversable
to elements of a new type preserving their order, if any.- Specified by:
map
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
map
in interfaceSeq<java.lang.Character>
- Specified by:
map
in interfaceTraversable<java.lang.Character>
- Specified by:
map
in interfaceValue<java.lang.Character>
- Type Parameters:
U
- Component type of the target Traversable- Parameters:
mapper
- A mapper.- Returns:
- a mapped Traversable
-
mkString
public java.lang.String mkString()
Description copied from interface:Traversable
Joins the elements of this by concatenating their string representations.This has the same effect as calling
mkString("", "", "")
.- Specified by:
mkString
in interfaceTraversable<java.lang.Character>
- Returns:
- a new String
-
padTo
public CharSeq padTo(int length, java.lang.Character element)
Description copied from interface:Seq
A copy of this sequence with an element appended until a given target length is reached.Note: lazily-evaluated Seq implementations need to process all elements in order to gather the overall length.
- Specified by:
padTo
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
padTo
in interfaceSeq<java.lang.Character>
- Parameters:
length
- the target lengthelement
- the padding element- Returns:
- a new sequence consisting of all elements of this sequence followed by the minimal number
of occurrences of
element
so that the resulting sequence has a length of at leastlength
.
-
leftPadTo
public CharSeq leftPadTo(int length, java.lang.Character element)
Description copied from interface:Seq
A copy of this sequence with an element prepended until a given target length is reached.Note: lazily-evaluated Seq implementations need to process all elements in order to gather the overall length.
- Specified by:
leftPadTo
in interfaceSeq<java.lang.Character>
- Parameters:
length
- the target lengthelement
- the padding element- Returns:
- a new sequence consisting of all elements of this sequence prepended by the minimal number
of occurrences of
element
so that the resulting sequence has a length of at leastlength
.
-
orElse
public CharSeq orElse(java.lang.Iterable<? extends java.lang.Character> other)
Description copied from interface:Traversable
Returns thisTraversable
if it is nonempty, otherwise return the alternative.- Specified by:
orElse
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
orElse
in interfaceSeq<java.lang.Character>
- Specified by:
orElse
in interfaceTraversable<java.lang.Character>
- Parameters:
other
- An alternativeTraversable
- Returns:
- this
Traversable
if it is nonempty, otherwise return the alternative.
-
orElse
public CharSeq orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends java.lang.Character>> supplier)
Description copied from interface:Traversable
Returns thisTraversable
if it is nonempty, otherwise return the result of evaluating supplier.- Specified by:
orElse
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
orElse
in interfaceSeq<java.lang.Character>
- Specified by:
orElse
in interfaceTraversable<java.lang.Character>
- Parameters:
supplier
- An alternativeTraversable
supplier- Returns:
- this
Traversable
if it is nonempty, otherwise return the result of evaluating supplier.
-
patch
public CharSeq patch(int from, java.lang.Iterable<? extends java.lang.Character> that, int replaced)
Description copied from interface:Seq
Produces a new list where a slice of elements in this list is replaced by another sequence.- Specified by:
patch
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
patch
in interfaceSeq<java.lang.Character>
- Parameters:
from
- the index of the first replaced elementthat
- sequence for replacementreplaced
- the number of elements to drop in the original list- Returns:
- a new sequence.
-
mapChars
public CharSeq mapChars(CharSeq.CharUnaryOperator mapper)
-
partition
public Tuple2<CharSeq,CharSeq> partition(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Creates a partition of thisTraversable
by splitting this elements in two in distinct traversables according to a predicate.- Specified by:
partition
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
partition
in interfaceSeq<java.lang.Character>
- Specified by:
partition
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A predicate which classifies an element if it is in the first or the second traversable.- Returns:
- A disjoint union of two traversables. The first
Traversable
contains all elements that satisfy the givenpredicate
, the secondTraversable
contains all elements that don't. The original order of elements is preserved.
-
peek
public CharSeq peek(java.util.function.Consumer<? super java.lang.Character> action)
Description copied from interface:Value
Performs the givenaction
on the first element if this is an eager implementation. Performs the givenaction
on all elements (the first immediately, successive deferred), if this is a lazy implementation.- Specified by:
peek
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
peek
in interfaceSeq<java.lang.Character>
- Specified by:
peek
in interfaceTraversable<java.lang.Character>
- Specified by:
peek
in interfaceValue<java.lang.Character>
- Parameters:
action
- The action that will be performed on the element(s).- Returns:
- this instance
-
permutations
public IndexedSeq<CharSeq> permutations()
Description copied from interface:Seq
Computes all unique permutations.Example:
[].permutations() = [] [1,2,3].permutations() = [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
- Specified by:
permutations
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
permutations
in interfaceSeq<java.lang.Character>
- Returns:
- this unique permutations
-
prepend
public CharSeq prepend(java.lang.Character element)
Description copied from interface:Seq
Prepends an element to this.- Specified by:
prepend
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
prepend
in interfaceSeq<java.lang.Character>
- Parameters:
element
- An element- Returns:
- A new Seq containing the given element prepended to this elements
-
prependAll
public CharSeq prependAll(java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:Seq
Prepends all given elements to this.- Specified by:
prependAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
prependAll
in interfaceSeq<java.lang.Character>
- Parameters:
elements
- An Iterable of elements- Returns:
- A new Seq containing the given elements prepended to this elements
-
remove
public CharSeq remove(java.lang.Character element)
Description copied from interface:Seq
Removes the first occurrence of the given element.- Specified by:
remove
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
remove
in interfaceSeq<java.lang.Character>
- Parameters:
element
- An element to be removed from this Seq.- Returns:
- a Seq containing all elements of this without the first occurrence of the given element.
-
removeFirst
public CharSeq removeFirst(java.util.function.Predicate<java.lang.Character> predicate)
Description copied from interface:Seq
Removes the first occurrence that satisfy predicate- Specified by:
removeFirst
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
removeFirst
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- an predicate- Returns:
- a new Seq
-
removeLast
public CharSeq removeLast(java.util.function.Predicate<java.lang.Character> predicate)
Description copied from interface:Seq
Removes the last occurrence that satisfy predicate- Specified by:
removeLast
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
removeLast
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- an predicate- Returns:
- a new Seq
-
removeAt
public CharSeq removeAt(int index)
Description copied from interface:Seq
Removes the element at the specified position in this sequence. Shifts any subsequent elements to the left (subtracts one from their indices).- Specified by:
removeAt
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
removeAt
in interfaceSeq<java.lang.Character>
- Parameters:
index
- position of element to remove- Returns:
- a sequence containing all elements of this without the element at the specified position.
-
removeAll
public CharSeq removeAll(java.lang.Character element)
Description copied from interface:Seq
Removes all occurrences of the given element.- Specified by:
removeAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
removeAll
in interfaceSeq<java.lang.Character>
- Parameters:
element
- An element to be removed from this Seq.- Returns:
- a Seq containing all elements of this but not the given element.
-
removeAll
public CharSeq removeAll(java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:Seq
Removes all occurrences of the given elements.- Specified by:
removeAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
removeAll
in interfaceSeq<java.lang.Character>
- Parameters:
elements
- Elements to be removed from this Seq.- Returns:
- a Seq containing all elements of this but none of the given elements.
-
removeAll
@Deprecated public CharSeq removeAll(java.util.function.Predicate<? super java.lang.Character> predicate)
Deprecated.Description copied from interface:Seq
Returns a new Seq consisting of all elements which do not satisfy the given predicate.- Specified by:
removeAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
removeAll
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- the predicate used to test elements- Returns:
- a new Seq
-
replace
public CharSeq replace(java.lang.Character currentElement, java.lang.Character newElement)
Description copied from interface:Traversable
Replaces the first occurrence (if exists) of the given currentElement with newElement.- Specified by:
replace
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
replace
in interfaceSeq<java.lang.Character>
- Specified by:
replace
in interfaceTraversable<java.lang.Character>
- Parameters:
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.- Returns:
- a Traversable containing all elements of this where the first occurrence of currentElement is replaced with newElement.
-
replaceAll
public CharSeq replaceAll(java.lang.Character currentElement, java.lang.Character newElement)
Description copied from interface:Traversable
Replaces all occurrences of the given currentElement with newElement.- Specified by:
replaceAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
replaceAll
in interfaceSeq<java.lang.Character>
- Specified by:
replaceAll
in interfaceTraversable<java.lang.Character>
- Parameters:
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.- Returns:
- a Traversable containing all elements of this where all occurrences of currentElement are replaced with newElement.
-
retainAll
public CharSeq retainAll(java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:Traversable
Keeps all occurrences of the given elements from this.- Specified by:
retainAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
retainAll
in interfaceSeq<java.lang.Character>
- Specified by:
retainAll
in interfaceTraversable<java.lang.Character>
- Parameters:
elements
- Elements to be kept.- Returns:
- a Traversable containing all occurrences of the given elements.
-
reverse
public CharSeq reverse()
Description copied from interface:Seq
Reverses the order of elements.- Specified by:
reverse
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
reverse
in interfaceSeq<java.lang.Character>
- Returns:
- the reversed elements.
-
rotateLeft
public CharSeq rotateLeft(int n)
Description copied from interface:Seq
Circular rotates the elements by the specified distance to the left direction.// = List(3, 4, 5, 1, 2) List.of(1, 2, 3, 4, 5).rotateLeft(2);
- Specified by:
rotateLeft
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
rotateLeft
in interfaceSeq<java.lang.Character>
- Parameters:
n
- distance of left rotation- Returns:
- the rotated elements.
-
rotateRight
public CharSeq rotateRight(int n)
Description copied from interface:Seq
Circular rotates the elements by the specified distance to the right direction.// = List(4, 5, 1, 2, 3) List.of(1, 2, 3, 4, 5).rotateRight(2);
- Specified by:
rotateRight
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
rotateRight
in interfaceSeq<java.lang.Character>
- Parameters:
n
- distance of right rotation- Returns:
- the rotated elements.
-
scan
public CharSeq scan(java.lang.Character zero, java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Character,? extends java.lang.Character> operation)
Description copied from interface:Traversable
Computes a prefix scan of the elements of the collection. Note: The neutral element z may be applied more than once.- Specified by:
scan
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
scan
in interfaceSeq<java.lang.Character>
- Specified by:
scan
in interfaceTraversable<java.lang.Character>
- Parameters:
zero
- neutral element for the operator opoperation
- the associative operator for the scan- Returns:
- a new traversable collection containing the prefix scan of the elements in this traversable collection
-
scanLeft
public <U> IndexedSeq<U> scanLeft(U zero, java.util.function.BiFunction<? super U,? super java.lang.Character,? extends U> operation)
Description copied from interface:Traversable
Produces a collection containing cumulative results of applying the operator going left to right. Note: will not terminate for infinite-sized collections. Note: might return different results for different runs, unless the underlying collection type is ordered.- Specified by:
scanLeft
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
scanLeft
in interfaceSeq<java.lang.Character>
- Specified by:
scanLeft
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- the type of the elements in the resulting collection- Parameters:
zero
- the initial valueoperation
- the binary operator applied to the intermediate result and the element- Returns:
- collection with intermediate results
-
scanRight
public <U> IndexedSeq<U> scanRight(U zero, java.util.function.BiFunction<? super java.lang.Character,? super U,? extends U> operation)
Description copied from interface:Traversable
Produces a collection containing cumulative results of applying the operator going right to left. The head of the collection is the last cumulative result. Note: will not terminate for infinite-sized collections. Note: might return different results for different runs, unless the underlying collection type is ordered.- Specified by:
scanRight
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
scanRight
in interfaceSeq<java.lang.Character>
- Specified by:
scanRight
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- the type of the elements in the resulting collection- Parameters:
zero
- the initial valueoperation
- the binary operator applied to the intermediate result and the element- Returns:
- collection with intermediate results
-
shuffle
public CharSeq shuffle()
Description copied from interface:Seq
Randomize the order of the elements in the current sequence.- Specified by:
shuffle
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
shuffle
in interfaceSeq<java.lang.Character>
- Returns:
- a sequence with the same elements as the current sequence in a random order.
-
shuffle
public CharSeq shuffle(java.util.Random random)
Description copied from interface:Seq
Randomize the order of the elements in the current sequence using the given source of randomness.- Specified by:
shuffle
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
shuffle
in interfaceSeq<java.lang.Character>
- Parameters:
random
- A random number generator- Returns:
- a sequence with the same elements as the current sequence in a random order.
-
slice
public CharSeq slice(int beginIndex, int endIndex)
Description copied from interface:Seq
Returns a Seq that is a slice of this. The slice begins with the element at the specifiedbeginIndex
and extends to the element at indexendIndex - 1
.Examples:
List.of(1, 2, 3, 4).slice(1, 3); // = (2, 3) List.of(1, 2, 3, 4).slice(0, 4); // = (1, 2, 3, 4) List.of(1, 2, 3, 4).slice(2, 2); // = () List.of(1, 2).slice(1, 0); // = () List.of(1, 2).slice(-10, 10); // = (1, 2)
Seq.subSequence(int, int)
which throws in some cases instead of returning a sequence.- Specified by:
slice
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
slice
in interfaceSeq<java.lang.Character>
- Parameters:
beginIndex
- the beginning index, inclusiveendIndex
- the end index, exclusive- Returns:
- the specified slice
-
slideBy
public Iterator<CharSeq> slideBy(java.util.function.Function<? super java.lang.Character,?> classifier)
Description copied from interface:Traversable
Slides a non-overlapping window of a variable size over thisTraversable
.Each window contains elements with the same class, as determined by
classifier
. Two consecutive values in thisTraversable
will be in the same window only ifclassifier
returns equal values for them. Otherwise, the values will constitute the last element of the previous window and the first element of the next window.Examples:
[].slideBy(Function.identity()) = [] [1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]] [1,2,3,10,12,5,7,20,29].slideBy(x -> x/10) = [[1,2,3],[10,12],[5,7],[20,29]]
- Specified by:
slideBy
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
slideBy
in interfaceSeq<java.lang.Character>
- Specified by:
slideBy
in interfaceTraversable<java.lang.Character>
- Parameters:
classifier
- A function which classifies elements into classes- Returns:
- A new Iterator of windows of the grouped elements
-
sliding
public Iterator<CharSeq> sliding(int size)
Description copied from interface:Traversable
Slides a window of a specificsize
and step size 1 over thisTraversable
by callingTraversable.sliding(int, int)
.- Specified by:
sliding
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
sliding
in interfaceSeq<java.lang.Character>
- Specified by:
sliding
in interfaceTraversable<java.lang.Character>
- Parameters:
size
- a positive window size- Returns:
- a new Iterator of windows of a specific size using step size 1
-
sliding
public Iterator<CharSeq> sliding(int size, int step)
Description copied from interface:Traversable
Slides a window of a specificsize
andstep
size over thisTraversable
.Examples:
[].sliding(1,1) = [] [1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]] [1,2,3,4,5].sliding(2,4) = [[1,2],[5]] [1,2,3,4,5].sliding(2,5) = [[1,2]] [1,2,3,4].sliding(5,3) = [[1,2,3,4],[4]]
- Specified by:
sliding
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
sliding
in interfaceSeq<java.lang.Character>
- Specified by:
sliding
in interfaceTraversable<java.lang.Character>
- Parameters:
size
- a positive window sizestep
- a positive step size- Returns:
- a new Iterator of windows of a specific size using a specific step size
-
sorted
public CharSeq sorted()
Description copied from interface:Seq
Sorts this elements according to their natural order. If this elements are notComparable
, ajava.lang.ClassCastException
may be thrown.- Specified by:
sorted
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
sorted
in interfaceSeq<java.lang.Character>
- Returns:
- A sorted version of this
-
sorted
public CharSeq sorted(java.util.Comparator<? super java.lang.Character> comparator)
Description copied from interface:Seq
Sorts this elements according to the providedComparator
. If this elements are notComparable
, ajava.lang.ClassCastException
may be thrown.- Specified by:
sorted
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
sorted
in interfaceSeq<java.lang.Character>
- Parameters:
comparator
- A comparator- Returns:
- a sorted version of this
-
sortBy
public <U extends java.lang.Comparable<? super U>> CharSeq sortBy(java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Description copied from interface:Seq
Sorts this elements by comparing the elements in a different domain, using the givenmapper
.- Specified by:
sortBy
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
sortBy
in interfaceSeq<java.lang.Character>
- Type Parameters:
U
- The domain where elements are compared- Parameters:
mapper
- A mapper- Returns:
- a sorted version of this
-
sortBy
public <U> CharSeq sortBy(java.util.Comparator<? super U> comparator, java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Description copied from interface:Seq
Sorts this elements by comparing the elements in a different domain, using the givenmapper
.- Specified by:
sortBy
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
sortBy
in interfaceSeq<java.lang.Character>
- Type Parameters:
U
- The domain where elements are compared- Parameters:
comparator
- A comparatormapper
- A mapper- Returns:
- a sorted version of this
-
span
public Tuple2<CharSeq,CharSeq> span(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Returns a tuple where the first element is the longest prefix of elements that satisfy the givenpredicate
and the second element is the remainder.- Specified by:
span
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
span
in interfaceSeq<java.lang.Character>
- Specified by:
span
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A predicate.- Returns:
- a
Tuple
containing the longest prefix of elements that satisfy p and the remainder.
-
subSequence
public CharSeq subSequence(int beginIndex)
Description copied from interface:Seq
Returns a Seq that is a subsequence of this. The subsequence begins with the element at the specifiedbeginIndex
and extends to the end of this Seq.Examples:
List.of(1, 2).subSequence(0); // = (1, 2) List.of(1, 2).subSequence(1); // = (2) List.of(1, 2).subSequence(2); // = () List.of(1, 2).subSequence(10); // throws IndexOutOfBoundsException List.of(1, 2).subSequence(-10); // throws IndexOutOfBoundsException
Seq.drop(int)
which is similar but does not throw.- Specified by:
subSequence
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
subSequence
in interfaceSeq<java.lang.Character>
- Parameters:
beginIndex
- the beginning index, inclusive- Returns:
- the specified subsequence
-
tail
public CharSeq tail()
Description copied from interface:Traversable
Drops the first element of a non-empty Traversable.- Specified by:
tail
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
tail
in interfaceSeq<java.lang.Character>
- Specified by:
tail
in interfaceTraversable<java.lang.Character>
- Returns:
- A new instance of Traversable containing all elements except the first.
-
tailOption
public Option<CharSeq> tailOption()
Description copied from interface:Traversable
Drops the first element of a non-empty Traversable and returns anOption
.- Specified by:
tailOption
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
tailOption
in interfaceSeq<java.lang.Character>
- Specified by:
tailOption
in interfaceTraversable<java.lang.Character>
- Returns:
Some(traversable)
orNone
if this is empty.
-
take
public CharSeq take(int n)
Description copied from interface:Traversable
Takes the first n elements of this or all elements, if this length < n.The result is equivalent to
sublist(0, max(0, min(length(), n)))
but does not throw ifn < 0
orn > length()
.In the case of
n < 0
the empty instance is returned, in the case ofn > length()
this is returned.- Specified by:
take
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
take
in interfaceSeq<java.lang.Character>
- Specified by:
take
in interfaceTraversable<java.lang.Character>
- Parameters:
n
- The number of elements to take.- Returns:
- A new instance consisting of the first n elements of this or all elements, if this has less than n elements.
-
takeUntil
public CharSeq takeUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Takes elements until the predicate holds for the current element.Note: This is essentially the same as
takeWhile(predicate.negate())
. It is intended to be used with method references, which cannot be negated directly.- Specified by:
takeUntil
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
takeUntil
in interfaceSeq<java.lang.Character>
- Specified by:
takeUntil
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements.- Returns:
- a new instance consisting of all elements before the first one which does satisfy the given predicate.
-
takeWhile
public CharSeq takeWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Traversable
Takes elements while the predicate holds for the current element.- Specified by:
takeWhile
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
takeWhile
in interfaceSeq<java.lang.Character>
- Specified by:
takeWhile
in interfaceTraversable<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for the contained elements.- Returns:
- a new instance consisting of all elements before the first one which does not satisfy the given predicate.
-
takeRight
public CharSeq takeRight(int n)
Description copied from interface:Traversable
Takes the last n elements of this or all elements, if this length < n.The result is equivalent to
sublist(max(0, min(length(), length() - n)), n)
, i.e. takeRight will not throw ifn < 0
orn > length()
.In the case of
n < 0
the empty instance is returned, in the case ofn > length()
this is returned.- Specified by:
takeRight
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
takeRight
in interfaceSeq<java.lang.Character>
- Specified by:
takeRight
in interfaceTraversable<java.lang.Character>
- Parameters:
n
- The number of elements to take.- Returns:
- A new instance consisting of the last n elements of this or all elements, if this has less than n elements.
-
takeRightUntil
public CharSeq takeRightUntil(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Seq
Takes elements until the predicate holds for the current element, starting from the end.- Specified by:
takeRightUntil
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
takeRightUntil
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements, starting from the end.- Returns:
- a new instance consisting of all elements after the last one which does satisfy the given predicate.
-
takeRightWhile
public CharSeq takeRightWhile(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Seq
Takes elements while the predicate holds for the current element, starting from the end.Note: This is essentially the same as
takeRightUntil(predicate.negate())
. It is intended to be used with method references, which cannot be negated directly.- Specified by:
takeRightWhile
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
takeRightWhile
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- A condition tested subsequently for this elements, starting from the end.- Returns:
- a new instance consisting of all elements after the last one which does not satisfy the given predicate.
-
transform
public <U> U transform(java.util.function.Function<? super CharSeq,? extends U> f)
Transforms thisCharSeq
.- Type Parameters:
U
- Type of transformation result- Parameters:
f
- A transformation- Returns:
- An instance of type
U
- Throws:
java.lang.NullPointerException
- iff
is null
-
unzip
public <T1,T2> Tuple2<IndexedSeq<T1>,IndexedSeq<T2>> unzip(java.util.function.Function<? super java.lang.Character,Tuple2<? extends T1,? extends T2>> unzipper)
Description copied from interface:Traversable
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct sets.- Specified by:
unzip
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
unzip
in interfaceSeq<java.lang.Character>
- Specified by:
unzip
in interfaceTraversable<java.lang.Character>
- Type Parameters:
T1
- 1st element type of a pair returned by unzipperT2
- 2nd element type of a pair returned by unzipper- Parameters:
unzipper
- a function which converts elements of this to pairs- Returns:
- A pair of set containing elements split by unzipper
-
unzip3
public <T1,T2,T3> Tuple3<IndexedSeq<T1>,IndexedSeq<T2>,IndexedSeq<T3>> unzip3(java.util.function.Function<? super java.lang.Character,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Description copied from interface:Traversable
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct sets.- Specified by:
unzip3
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
unzip3
in interfaceSeq<java.lang.Character>
- Specified by:
unzip3
in interfaceTraversable<java.lang.Character>
- Type Parameters:
T1
- 1st element type of a triplet returned by unzipperT2
- 2nd element type of a triplet returned by unzipperT3
- 3rd element type of a triplet returned by unzipper- Parameters:
unzipper
- a function which converts elements of this to pairs- Returns:
- A triplet of set containing elements split by unzipper
-
update
public CharSeq update(int index, java.lang.Character element)
Description copied from interface:Seq
Updates the given element at the specified index.- Specified by:
update
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
update
in interfaceSeq<java.lang.Character>
- Parameters:
index
- an indexelement
- an element- Returns:
- a new Seq consisting of all previous elements, with a single one (at the given index), changed to the new value.
-
update
public CharSeq update(int index, java.util.function.Function<? super java.lang.Character,? extends java.lang.Character> updater)
Description copied from interface:Seq
Updates the given element at the specified index using the specified function.- Specified by:
update
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
update
in interfaceSeq<java.lang.Character>
- Parameters:
index
- an indexupdater
- a function transforming the previous value- Returns:
- a new Seq consisting of all previous elements, with a single one (at the given index), changed to the new value.
-
zip
public <U> IndexedSeq<Tuple2<java.lang.Character,U>> zip(java.lang.Iterable<? extends U> that)
Description copied from interface:Traversable
Returns a traversable formed from this traversable and another Iterable collection by combining corresponding elements in pairs. If one of the two iterables is longer than the other, its remaining elements are ignored.The length of the returned traversable is the minimum of the lengths of this traversable and
that
iterable.- Specified by:
zip
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
zip
in interfaceSeq<java.lang.Character>
- Specified by:
zip
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- The type of the second half of the returned pairs.- Parameters:
that
- The Iterable providing the second half of each result pair.- Returns:
- a new traversable containing pairs consisting of corresponding elements of this traversable and
that
iterable.
-
zipWith
public <U,R> IndexedSeq<R> zipWith(java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super java.lang.Character,? super U,? extends R> mapper)
Description copied from interface:Traversable
Returns a traversable formed from this traversable and another Iterable collection by mapping elements. If one of the two iterables is longer than the other, its remaining elements are ignored.The length of the returned traversable is the minimum of the lengths of this traversable and
that
iterable.- Specified by:
zipWith
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
zipWith
in interfaceSeq<java.lang.Character>
- Specified by:
zipWith
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- The type of the second parameter of the mapper.R
- The type of the mapped elements.- Parameters:
that
- The Iterable providing the second parameter of the mapper.mapper
- a mapper.- Returns:
- a new traversable containing mapped elements of this traversable and
that
iterable.
-
zipAll
public <U> IndexedSeq<Tuple2<java.lang.Character,U>> zipAll(java.lang.Iterable<? extends U> that, java.lang.Character thisElem, U thatElem)
Description copied from interface:Traversable
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in pairs. If one of the two collections is shorter than the other, placeholder elements are used to extend the shorter collection to the length of the longer.The length of the returned traversable is the maximum of the lengths of this traversable and
that
iterable.Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
- Specified by:
zipAll
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
zipAll
in interfaceSeq<java.lang.Character>
- Specified by:
zipAll
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- The type of the second half of the returned pairs.- Parameters:
that
- The Iterable providing the second half of each result pair.thisElem
- The element to be used to fill up the result if this traversable is shorter than that.thatElem
- The element to be used to fill up the result if that is shorter than this traversable.- Returns:
- A new traversable containing pairs consisting of corresponding elements of this traversable and that.
-
zipWithIndex
public IndexedSeq<Tuple2<java.lang.Character,java.lang.Integer>> zipWithIndex()
Description copied from interface:Traversable
Zips this traversable with its indices.- Specified by:
zipWithIndex
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
zipWithIndex
in interfaceSeq<java.lang.Character>
- Specified by:
zipWithIndex
in interfaceTraversable<java.lang.Character>
- Returns:
- A new traversable containing all elements of this traversable paired with their index, starting with 0.
-
zipWithIndex
public <U> IndexedSeq<U> zipWithIndex(java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Integer,? extends U> mapper)
Description copied from interface:Traversable
Returns a traversable formed from this traversable and another Iterable collection by mapping elements. If one of the two iterables is longer than the other, its remaining elements are ignored.The length of the returned traversable is the minimum of the lengths of this traversable and
that
iterable.- Specified by:
zipWithIndex
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
zipWithIndex
in interfaceSeq<java.lang.Character>
- Specified by:
zipWithIndex
in interfaceTraversable<java.lang.Character>
- Type Parameters:
U
- The type of the mapped elements.- Parameters:
mapper
- a mapper.- Returns:
- a new traversable containing mapped elements of this traversable and
that
iterable.
-
get
public java.lang.Character get(int index)
Description copied from interface:Seq
Returns the element at the specified index.
-
indexOf
public int indexOf(java.lang.Character element, int from)
Description copied from interface:Seq
Returns the index of the first occurrence of the given element after or at some start index or -1 if this does not contain the given element.
-
lastIndexOf
public int lastIndexOf(java.lang.Character element, int end)
Description copied from interface:Seq
Returns the index of the last occurrence of the given element before or at a given end index or -1 if this does not contain the given element.- Specified by:
lastIndexOf
in interfaceSeq<java.lang.Character>
- Parameters:
element
- an elementend
- the end index- Returns:
- the index of the last occurrence of the given element
-
splitAt
public Tuple2<CharSeq,CharSeq> splitAt(int n)
Description copied from interface:Seq
Splits a Seq at the specified index. The result ofsplitAt(n)
is equivalent toTuple.of(take(n), drop(n))
.
-
splitAt
public Tuple2<CharSeq,CharSeq> splitAt(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Seq
Splits a sequence at the first element which satisfies thePredicate
, e.g. Tuple(init, element+tail).
-
splitAtInclusive
public Tuple2<CharSeq,CharSeq> splitAtInclusive(java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:Seq
Splits a sequence at the first element which satisfies thePredicate
, e.g. Tuple(init+element, tail).- Specified by:
splitAtInclusive
in interfaceSeq<java.lang.Character>
- Parameters:
predicate
- An predicate- Returns:
- A
Tuple
containing divided sequences
-
startsWith
public boolean startsWith(java.lang.Iterable<? extends java.lang.Character> that, int offset)
Description copied from interface:Seq
Tests whether this list contains the given sequence at a given index.Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate.
- Specified by:
startsWith
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
startsWith
in interfaceSeq<java.lang.Character>
- Parameters:
that
- the sequence to testoffset
- the index where the sequence is searched.- Returns:
- true if that is empty or that is prefix of this collection starting from the given offset, false otherwise.
-
head
public java.lang.Character head()
Description copied from interface:Traversable
Returns the first element of a non-empty Traversable.- Specified by:
head
in interfaceTraversable<java.lang.Character>
- Returns:
- The first element of this Traversable.
-
isAsync
public boolean isAsync()
ACharSeq
is computed synchronously.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Traversable
Checks if this Traversable is empty.- Specified by:
isEmpty
in interfaceTraversable<java.lang.Character>
- Specified by:
isEmpty
in interfaceValue<java.lang.Character>
- Returns:
- true, if this Traversable contains no elements, false otherwise.
-
isLazy
public boolean isLazy()
ACharSeq
is computed eagerly.
-
isTraversableAgain
public boolean isTraversableAgain()
Description copied from interface:Traversable
Checks if this Traversable can be repeatedly traversed.This method should be implemented by classes only, i.e. not by interfaces.
- Specified by:
isTraversableAgain
in interfaceTraversable<java.lang.Character>
- Returns:
- true, if this Traversable is known to be traversable repeatedly, false otherwise.
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:Traversable
In Vavr there are four basic classes of collections:- Seq (sequential elements)
- Set (distinct elements)
- Map (indexed elements)
- Multimap (indexed collections)
- belong to the same basic collection class (Seq, Set, Map or Multimap)
- contain the same elements
- have the same element order, if the collections are of type Seq
Notes:
- No collection instance equals null, e.g. Queue(1) not equals null.
- Nulls are allowed and handled as expected, e.g. List(null, 1) equals Stream(null, 1) and HashMap((null, 1)) equals LinkedHashMap((null, 1)).
- The element order is taken into account for Seq only. E.g. List(null, 1) not equals Stream(1, null) and HashMap((null, 1), ("a", null)) equals LinkedHashMap(("a", null), (null, 1)). The reason is, that we do not know which implementations we compare when having two instances of type Map, Multimap or Set (see Liskov Substitution Principle).
- Other collection classes are equal if their types are equal and their elements are equal (in iteration order).
- Iterator equality is defined to be object reference equality.
- Specified by:
equals
in interfaceTraversable<java.lang.Character>
- Specified by:
equals
in interfaceValue<java.lang.Character>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- an object, may be null- Returns:
- true, if this collection equals the given object according to the rules described above, false otherwise.
-
hashCode
public int hashCode()
Description copied from interface:Traversable
Returns the hash code of this collection.
We distinguish between two types of hashes, those for collections with predictable iteration order (like Seq) and those with arbitrary iteration order (like Set, Map and Multimap).
In all cases the hash of an empty collection is defined to be 1.
Collections with predictable iteration order are hashed as follows:
Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }
Generally, hash codes of collections aren't cached in Vavr (opposed to the size/length). Storing hash codes in order to reduce the time complexity would increase the memory footprint. Persistent collections are built upon tree structures, it allows us to implement efficient memory sharing. A drawback of tree structures is that they make it necessary to store collection attributes at each tree node (read: element).
The computation of the hash code is linear in time, i.e. O(n). If the hash code of a collection is re-calculated often, e.g. when using a List as HashMap key, we might want to cache the hash code. This can be achieved by simply using a wrapper class, which is not included in Vavr but could be implemented like this:public final class Hashed<K> { private final K key; private final Lazy<Integer> hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; } @Override public boolean equals(Object o) { if (o == key) { return true; } else if (key != null && o instanceof Hashed) { final Hashed that = (Hashed) o; return key.equals(that.key); } else { return false; } } @Override public int hashCode() { return hashCode.get(); } @Override public String toString() { return "Hashed(" + (key == null ? "null" : key.toString()) + ")"; } }
- Specified by:
hashCode
in interfaceTraversable<java.lang.Character>
- Specified by:
hashCode
in interfaceValue<java.lang.Character>
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hash code of this collection
-
charAt
public char charAt(int index)
Returns thechar
value at the specified index. An index ranges from0
tolength() - 1
. The firstchar
value of the sequence is at index0
, the next at index1
, and so on, as for array indexing.If the
char
value specified by the index is a surrogate, the surrogate value is returned.- Specified by:
charAt
in interfacejava.lang.CharSequence
- Parameters:
index
- the index of thechar
value.- Returns:
- the
char
value at the specified index of this string. The firstchar
value is at index0
. - Throws:
java.lang.IndexOutOfBoundsException
- if theindex
argument is negative or not less than the length of this string.
-
length
public int length()
Returns the length of this string. The length is equal to the number of Unicode code units in the string.- Specified by:
length
in interfacejava.lang.CharSequence
- Specified by:
length
in interfaceTraversable<java.lang.Character>
- Returns:
- the length of the sequence of characters represented by this object.
-
codePointAt
public int codePointAt(int index)
Returns the character (Unicode code point) at the specified index. The index refers tochar
values (Unicode code units) and ranges from0
tolength()
- 1
.If the
char
value specified at the given index is in the high-surrogate range, the following index is less than the length of thisCharSeq
, and thechar
value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, thechar
value at the given index is returned.- Parameters:
index
- the index to thechar
values- Returns:
- the code point value of the character at the
index
- Throws:
java.lang.IndexOutOfBoundsException
- if theindex
argument is negative or not less than the length of this string.
-
codePointBefore
public int codePointBefore(int index)
Returns the character (Unicode code point) before the specified index. The index refers tochar
values (Unicode code units) and ranges from1
tolength
.If the
char
value at(index - 1)
is in the low-surrogate range,(index - 2)
is not negative, and thechar
value at(index - 2)
is in the high-surrogate range, then the supplementary code point value of the surrogate pair is returned. If thechar
value atindex - 1
is an unpaired low-surrogate or a high-surrogate, the surrogate value is returned.- Parameters:
index
- the index following the code point that should be returned- Returns:
- the Unicode code point value before the given index.
- Throws:
java.lang.IndexOutOfBoundsException
- if theindex
argument is less than 1 or greater than the length of this string.
-
codePointCount
public int codePointCount(int beginIndex, int endIndex)
Returns the number of Unicode code points in the specified text range of thisCharSeq
. The text range begins at the specifiedbeginIndex
and extends to thechar
at indexendIndex - 1
. Thus the length (inchar
s) of the text range isendIndex-beginIndex
. Unpaired surrogates within the text range count as one code point each.- Parameters:
beginIndex
- the index to the firstchar
of the text range.endIndex
- the index after the lastchar
of the text range.- Returns:
- the number of Unicode code points in the specified text range
- Throws:
java.lang.IndexOutOfBoundsException
- if thebeginIndex
is negative, orendIndex
is larger than the length of thisCharSeq
, orbeginIndex
is larger thanendIndex
.
-
offsetByCodePoints
public int offsetByCodePoints(int index, int codePointOffset)
Returns the index within thisCharSeq
that is offset from the givenindex
bycodePointOffset
code points. Unpaired surrogates within the text range given byindex
andcodePointOffset
count as one code point each.- Parameters:
index
- the index to be offsetcodePointOffset
- the offset in code points- Returns:
- the index within this
CharSeq
- Throws:
java.lang.IndexOutOfBoundsException
- ifindex
is negative or larger then the length of thisCharSeq
, or ifcodePointOffset
is positive and the substring starting withindex
has fewer thancodePointOffset
code points, or ifcodePointOffset
is negative and the substring beforeindex
has fewer than the absolute value ofcodePointOffset
code points.
-
getChars
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Copies characters from this string into the destination character array.The first character to be copied is at index
srcBegin
; the last character to be copied is at indexsrcEnd-1
(thus the total number of characters to be copied issrcEnd-srcBegin
). The characters are copied into the subarray ofdst
starting at indexdstBegin
and ending at index:dstbegin + (srcEnd-srcBegin) - 1
- Parameters:
srcBegin
- index of the first character in the string to copy.srcEnd
- index after the last character in the string to copy.dst
- the destination array.dstBegin
- the start offset in the destination array.- Throws:
java.lang.IndexOutOfBoundsException
- If any of the following is true:srcBegin
is negative.srcBegin
is greater thansrcEnd
srcEnd
is greater than the length of this stringdstBegin
is negativedstBegin+(srcEnd-srcBegin)
is larger thandst.length
-
getBytes
public byte[] getBytes(java.lang.String charsetName) throws java.io.UnsupportedEncodingException
Encodes thisCharSeq
into a sequence of bytes using the named charset, storing the result into a new byte array.The behavior of this method when this string cannot be encoded in the given charset is unspecified. The
CharsetEncoder
class should be used when more control over the encoding process is required.- Parameters:
charsetName
- The name of a supported charset- Returns:
- The resultant byte array
- Throws:
java.io.UnsupportedEncodingException
- If the named charset is not supported
-
getBytes
public byte[] getBytes(java.nio.charset.Charset charset)
Encodes thisCharSeq
into a sequence of bytes using the given charset, storing the result into a new byte array.This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement byte array. The
CharsetEncoder
class should be used when more control over the encoding process is required.- Parameters:
charset
- The Charset to be used to encode theCharSeq
- Returns:
- The resultant byte array
-
getBytes
public byte[] getBytes()
Encodes thisCharSeq
into a sequence of bytes using the platform's default charset, storing the result into a new byte array.The behavior of this method when this string cannot be encoded in the default charset is unspecified. The
CharsetEncoder
class should be used when more control over the encoding process is required.- Returns:
- The resultant byte array
-
contentEquals
public boolean contentEquals(java.lang.StringBuffer sb)
Compares this string to the specifiedStringBuffer
. The result istrue
if and only if thisCharSeq
represents the same sequence of characters as the specifiedStringBuffer
. This method synchronizes on theStringBuffer
.- Parameters:
sb
- TheStringBuffer
to compare thisCharSeq
against- Returns:
true
if thisCharSeq
represents the same sequence of characters as the specifiedStringBuffer
,false
otherwise
-
contentEquals
public boolean contentEquals(java.lang.CharSequence cs)
Compares this string to the specifiedCharSequence
. The result istrue
if and only if thisCharSeq
represents the same sequence of char values as the specified sequence. Note that if theCharSequence
is aStringBuffer
then the method synchronizes on it.- Parameters:
cs
- The sequence to compare thisCharSeq
against- Returns:
true
if thisCharSeq
represents the same sequence of char values as the specified sequence,false
otherwise
-
equalsIgnoreCase
public boolean equalsIgnoreCase(CharSeq anotherString)
Compares thisCharSeq
to anotherCharSeq
, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.Two characters
c1
andc2
are considered the same ignoring case if at least one of the following is true:- The two characters are the same (as compared by the
==
operator) - Applying the method
Character.toUpperCase(char)
to each character produces the same result - Applying the method
Character.toLowerCase(char)
to each character produces the same result
- Parameters:
anotherString
- TheCharSeq
to compare thisCharSeq
against- Returns:
true
if the argument is notnull
and it represents an equivalentCharSeq
ignoring case;false
otherwise- See Also:
equals(Object)
- The two characters are the same (as compared by the
-
compareTo
public int compareTo(CharSeq anotherString)
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by thisCharSeq
object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if thisCharSeq
object lexicographically precedes the argument string. The result is a positive integer if thisCharSeq
object lexicographically follows the argument string. The result is zero if the strings are equal;compareTo
returns0
exactly when theequals(Object)
method would returntrue
.This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case,
compareTo
returns the difference of the two character values at positionk
in the two string -- that is, the value:
If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case,this.charAt(k)-anotherString.charAt(k)
compareTo
returns the difference of the lengths of the strings -- that is, the value:this.length()-anotherString.length()
- Specified by:
compareTo
in interfacejava.lang.Comparable<CharSeq>
- Parameters:
anotherString
- theCharSeq
to be compared.- Returns:
- the value
0
if the argument string is equal to this string; a value less than0
if this string is lexicographically less than the string argument; and a value greater than0
if this string is lexicographically greater than the string argument.
-
compareToIgnoreCase
public int compareToIgnoreCase(CharSeq str)
Compares two strings lexicographically, ignoring case differences. This method returns an integer whose sign is that of callingcompareTo
with normalized versions of the strings where case differences have been eliminated by callingCharacter.toLowerCase(Character.toUpperCase(character))
on each character.Note that this method does not take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides collators to allow locale-sensitive ordering.
- Parameters:
str
- theCharSeq
to be compared.- Returns:
- a negative integer, zero, or a positive integer as the specified String is greater than, equal to, or less than this String, ignoring case considerations.
-
regionMatches
public boolean regionMatches(int toffset, CharSeq other, int ooffset, int len)
Tests if two string regions are equal.A substring of this
CharSeq
object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of thisCharSeq
object to be compared begins at indextoffset
and has lengthlen
. The substring of other to be compared begins at indexooffset
and has lengthlen
. The result isfalse
if and only if at least one of the following is true:toffset
is negative.ooffset
is negative.toffset+len
is greater than the length of thisCharSeq
object.ooffset+len
is greater than the length of the other argument.- There is some nonnegative integer k less than
len
such that:this.charAt(toffset +
k) != other.charAt(ooffset +
k)
- Parameters:
toffset
- the starting offset of the subregion in this string.other
- the string argument.ooffset
- the starting offset of the subregion in the string argument.len
- the number of characters to compare.- Returns:
true
if the specified subregion of this string exactly matches the specified subregion of the string argument;false
otherwise.
-
regionMatches
public boolean regionMatches(boolean ignoreCase, int toffset, CharSeq other, int ooffset, int len)
Tests if two string regions are equal.A substring of this
CharSeq
object is compared to a substring of the argumentother
. The result istrue
if these substrings represent character sequences that are the same, ignoring case if and only ifignoreCase
is true. The substring of thisCharSeq
object to be compared begins at indextoffset
and has lengthlen
. The substring ofother
to be compared begins at indexooffset
and has lengthlen
. The result isfalse
if and only if at least one of the following is true:toffset
is negative.ooffset
is negative.toffset+len
is greater than the length of thisCharSeq
object.ooffset+len
is greater than the length of the other argument.ignoreCase
isfalse
and there is some nonnegative integer k less thanlen
such that:this.charAt(toffset+k) != other.charAt(ooffset+k)
ignoreCase
istrue
and there is some nonnegative integer k less thanlen
such that:
and:Character.toLowerCase(this.charAt(toffset+k)) != Character.toLowerCase(other.charAt(ooffset+k))
Character.toUpperCase(this.charAt(toffset+k)) != Character.toUpperCase(other.charAt(ooffset+k))
- Parameters:
ignoreCase
- iftrue
, ignore case when comparing characters.toffset
- the starting offset of the subregion in this string.other
- the string argument.ooffset
- the starting offset of the subregion in the string argument.len
- the number of characters to compare.- Returns:
true
if the specified subregion of this string matches the specified subregion of the string argument;false
otherwise. Whether the matching is exact or case insensitive depends on theignoreCase
argument.
-
subSequence
public CharSeq subSequence(int beginIndex, int endIndex)
Description copied from interface:Seq
Returns a Seq that is a subsequence of this. The subsequence begins with the element at the specifiedbeginIndex
and extends to the element at indexendIndex - 1
.Examples:
List.of(1, 2, 3, 4).subSequence(1, 3); // = (2, 3) List.of(1, 2, 3, 4).subSequence(0, 4); // = (1, 2, 3, 4) List.of(1, 2, 3, 4).subSequence(2, 2); // = () List.of(1, 2).subSequence(1, 0); // throws IndexOutOfBoundsException List.of(1, 2).subSequence(-10, 1); // throws IndexOutOfBoundsException List.of(1, 2).subSequence(0, 10); // throws IndexOutOfBoundsException
Seq.slice(int, int)
which returns an empty sequence instead of throwing.- Specified by:
subSequence
in interfacejava.lang.CharSequence
- Specified by:
subSequence
in interfaceIndexedSeq<java.lang.Character>
- Specified by:
subSequence
in interfaceSeq<java.lang.Character>
- Parameters:
beginIndex
- the beginning index, inclusiveendIndex
- the end index, exclusive- Returns:
- the specified subsequence
-
startsWith
public boolean startsWith(CharSeq prefix, int toffset)
Tests if the substring of this string beginning at the specified index starts with the specified prefix.- Parameters:
prefix
- the prefix.toffset
- where to begin looking in this string.- Returns:
true
if the character sequence represented by the argument is a prefix of the substring of this object starting at indextoffset
;false
otherwise. The result isfalse
iftoffset
is negative or greater than the length of thisCharSeq
object; otherwise the result is the same as the result of the expressionthis.substring(toffset).startsWith(prefix)
-
startsWith
public boolean startsWith(CharSeq prefix)
Tests if this string starts with the specified prefix.- Parameters:
prefix
- the prefix.- Returns:
true
if the character sequence represented by the argument is a prefix of the character sequence represented by this string;false
otherwise. Note also thattrue
will be returned if the argument is an empty string or is equal to thisCharSeq
object as determined by theequals(Object)
method.
-
endsWith
public boolean endsWith(CharSeq suffix)
Tests if this string ends with the specified suffix.- Parameters:
suffix
- the suffix.- Returns:
true
if the character sequence represented by the argument is a suffix of the character sequence represented by this object;false
otherwise. Note that the result will betrue
if the argument is the empty string or is equal to thisCharSeq
object as determined by theequals(Object)
method.
-
indexOf
public int indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character. If a character with valuech
occurs in the character sequence represented by thisCharSeq
object, then the index (in Unicode code units) of the first such occurrence is returned. For values ofch
in the range from 0 to 0xFFFF (inclusive), this is the smallest value k such that:
is true. For other values ofthis.charAt(k) == ch
ch
, it is the smallest value k such that:
is true. In either case, if no such character occurs in this string, thenthis.codePointAt(k) == ch
-1
is returned.- Parameters:
ch
- a character (Unicode code point).- Returns:
- the index of the first occurrence of the character in the
character sequence represented by this object, or
-1
if the character does not occur.
-
indexOf
public int indexOf(int ch, int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.If a character with value
ch
occurs in the character sequence represented by thisCharSeq
object at an index no smaller thanfromIndex
, then the index of the first such occurrence is returned. For values ofch
in the range from 0 to 0xFFFF (inclusive), this is the smallest value k such that:
is true. For other values of(this.charAt(k) == ch)
&&
(k >= fromIndex)ch
, it is the smallest value k such that:
is true. In either case, if no such character occurs in this string at or after position(this.codePointAt(k) == ch)
&&
(k >= fromIndex)fromIndex
, then-1
is returned.There is no restriction on the value of
fromIndex
. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string:-1
is returned.All indices are specified in
char
values (Unicode code units).- Parameters:
ch
- a character (Unicode code point).fromIndex
- the index to start the search from.- Returns:
- the index of the first occurrence of the character in the
character sequence represented by this object that is greater
than or equal to
fromIndex
, or-1
if the character does not occur.
-
lastIndexOf
public int lastIndexOf(int ch)
Returns the index within this string of the last occurrence of the specified character. For values ofch
in the range from 0 to 0xFFFF (inclusive), the index (in Unicode code units) returned is the largest value k such that:
is true. For other values ofthis.charAt(k) == ch
ch
, it is the largest value k such that:
is true. In either case, if no such character occurs in this string, thenthis.codePointAt(k) == ch
-1
is returned. TheCharSeq
is searched backwards starting at the last character.- Parameters:
ch
- a character (Unicode code point).- Returns:
- the index of the last occurrence of the character in the
character sequence represented by this object, or
-1
if the character does not occur.
-
lastIndexOf
public int lastIndexOf(int ch, int fromIndex)
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. For values ofch
in the range from 0 to 0xFFFF (inclusive), the index returned is the largest value k such that:
is true. For other values of(this.charAt(k) == ch)
&&
(k <= fromIndex)ch
, it is the largest value k such that:
is true. In either case, if no such character occurs in this string at or before position(this.codePointAt(k) == ch)
&&
(k <= fromIndex)fromIndex
, then-1
is returned.All indices are specified in
char
values (Unicode code units).- Parameters:
ch
- a character (Unicode code point).fromIndex
- the index to start the search from. There is no restriction on the value offromIndex
. If it is greater than or equal to the length of this string, it has the same effect as if it were equal to one less than the length of this string: this entire string may be searched. If it is negative, it has the same effect as if it were -1: -1 is returned.- Returns:
- the index of the last occurrence of the character in the
character sequence represented by this object that is less
than or equal to
fromIndex
, or-1
if the character does not occur before that point.
-
lastIndexOfOption
public Option<java.lang.Integer> lastIndexOfOption(int ch, int fromIndex)
Returns the index of the last occurrence of the given element as anOption
, starting the search at the specified index.- Parameters:
ch
- a character (Unicode code point).fromIndex
- the index to start the search from.- Returns:
Some(index)
orNone
if not found.
-
indexOf
public int indexOf(CharSeq str)
Returns the index within this string of the first occurrence of the specified substring.The returned index is the smallest value k for which:
If no such value of k exists, thenthis.startsWith(str, k)
-1
is returned.- Parameters:
str
- the substring to search for.- Returns:
- the index of the first occurrence of the specified substring,
or
-1
if there is no such occurrence.
-
indexOfOption
public Option<java.lang.Integer> indexOfOption(CharSeq str)
Returns the index of the first occurrence of the given element as anOption
.- Parameters:
str
- the substring to search for.- Returns:
Some(index)
orNone
if not found.
-
indexOf
public int indexOf(CharSeq str, int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.The returned index is the smallest value k for which:
If no such value of k exists, thenk >= fromIndex
&&
this.startsWith(str, k)-1
is returned.- Parameters:
str
- the substring to search for.fromIndex
- the index from which to start the search.- Returns:
- the index of the first occurrence of the specified substring,
starting at the specified index,
or
-1
if there is no such occurrence.
-
indexOfOption
public Option<java.lang.Integer> indexOfOption(CharSeq str, int fromIndex)
Returns the index of the first occurrence of the given element as anOption
, starting the search at the specified index.- Parameters:
str
- the substring to search for.fromIndex
- the index from which to start the search.- Returns:
Some(index)
orNone
if not found.
-
lastIndexOf
public int lastIndexOf(CharSeq str)
Returns the index within this string of the last occurrence of the specified substring. The last occurrence of the empty string "" is considered to occur at the index valuethis.length()
.The returned index is the largest value k for which:
If no such value of k exists, thenthis.startsWith(str, k)
-1
is returned.- Parameters:
str
- the substring to search for.- Returns:
- the index of the last occurrence of the specified substring,
or
-1
if there is no such occurrence.
-
lastIndexOfOption
public Option<java.lang.Integer> lastIndexOfOption(CharSeq str)
Returns the index of the last occurrence of the given element as anOption
.- Parameters:
str
- the substring to search for.- Returns:
Some(index)
orNone
if not found.
-
lastIndexOf
public int lastIndexOf(CharSeq str, int fromIndex)
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.The returned index is the largest value k for which:
If no such value of k exists, thenk
<=
fromIndex&&
this.startsWith(str, k)-1
is returned.- Parameters:
str
- the substring to search for.fromIndex
- the index to start the search from.- Returns:
- the index of the last occurrence of the specified substring,
searching backward from the specified index,
or
-1
if there is no such occurrence.
-
lastIndexOfOption
public Option<java.lang.Integer> lastIndexOfOption(CharSeq str, int fromIndex)
Returns the index of the last occurrence of the given element as anOption
, starting the search at the specified index.- Parameters:
str
- the substring to search for.fromIndex
- the index to start the search from.- Returns:
Some(index)
orNone
if not found.
-
substring
public CharSeq substring(int beginIndex)
Returns a string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.Examples:
"unhappy".substring(2) returns "happy" "Harbison".substring(3) returns "bison" "emptiness".substring(9) returns "" (an empty string)
- Parameters:
beginIndex
- the beginning index, inclusive.- Returns:
- the specified substring.
- Throws:
java.lang.IndexOutOfBoundsException
- ifbeginIndex
is negative or larger than the length of thisCharSeq
object.
-
substring
public CharSeq substring(int beginIndex, int endIndex)
Returns a string that is a substring of this string. The substring begins at the specifiedbeginIndex
and extends to the character at indexendIndex - 1
. Thus the length of the substring isendIndex-beginIndex
.Examples:
"hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile"
- Parameters:
beginIndex
- the beginning index, inclusive.endIndex
- the ending index, exclusive.- Returns:
- the specified substring.
- Throws:
java.lang.IndexOutOfBoundsException
- if thebeginIndex
is negative, orendIndex
is larger than the length of thisCharSeq
object, orbeginIndex
is larger thanendIndex
.
-
stringPrefix
public java.lang.String stringPrefix()
Description copied from interface:Value
Returns the name of this Value type, which is used by toString().- Specified by:
stringPrefix
in interfaceValue<java.lang.Character>
- Returns:
- This type name.
-
toString
public java.lang.String toString()
Returns a string containing the characters in this sequence in the same order as this sequence. The length of the string will be the length of this sequence.
-
concat
public CharSeq concat(CharSeq str)
Concatenates the specified string to the end of this string.If the length of the argument string is
0
, then thisCharSeq
object is returned. Otherwise, aCharSeq
object is returned that represents a character sequence that is the concatenation of the character sequence represented by thisCharSeq
object and the character sequence represented by the argument string.Examples:
"cares".concat("s") returns "caress" "to".concat("get").concat("her") returns "together"
- Parameters:
str
- theCharSeq
that is concatenated to the end of thisCharSeq
.- Returns:
- a string that represents the concatenation of this object's characters followed by the string argument's characters.
-
matches
public boolean matches(java.lang.String regex)
Tells whether or not this string matches the given regular expression.An invocation of this method of the form str
.matches(
regex)
yields exactly the same result as the expressionPattern
.matches(regex, str)
- Parameters:
regex
- the regular expression to which this string is to be matched- Returns:
true
if, and only if, this string matches the given regular expression- Throws:
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid- See Also:
Pattern
-
contains
public boolean contains(java.lang.CharSequence s)
Returns true if and only if this string contains the specified sequence of char values.- Parameters:
s
- the sequence to search for- Returns:
- true if this string contains
s
, false otherwise
-
replaceFirst
public CharSeq replaceFirst(java.lang.String regex, java.lang.String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.An invocation of this method of the form str
.replaceFirst(
regex,
repl)
yields exactly the same result as the expressionPattern
.compile
(regex).matcher
(str).replaceFirst
(repl)\
) and dollar signs ($
) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; seeMatcher.replaceFirst(java.lang.String)
. UseMatcher.quoteReplacement(java.lang.String)
to suppress the special meaning of these characters, if desired.- Parameters:
regex
- the regular expression to which this string is to be matchedreplacement
- the string to be substituted for the first match- Returns:
- The resulting
CharSeq
- Throws:
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid- See Also:
Pattern
-
replaceAll
public CharSeq replaceAll(java.lang.String regex, java.lang.String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.An invocation of this method of the form str
.replaceAll(
regex,
repl)
yields exactly the same result as the expressionPattern
.compile
(regex).matcher
(str).replaceAll
(repl)\
) and dollar signs ($
) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; seeMatcher.replaceAll
. UseMatcher.quoteReplacement(java.lang.String)
to suppress the special meaning of these characters, if desired.- Parameters:
regex
- the regular expression to which this string is to be matchedreplacement
- the string to be substituted for each match- Returns:
- The resulting
CharSeq
- Throws:
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid- See Also:
Pattern
-
replace
public CharSeq replace(java.lang.CharSequence target, java.lang.CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".- Parameters:
target
- The sequence of char values to be replacedreplacement
- The replacement sequence of char values- Returns:
- The resulting string
-
split
public Seq<CharSeq> split(java.lang.String regex)
Splits this string around matches of the given regular expression.This method works as if by invoking the two-argument
split(String, int)
method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resultingSeq
.The string
"boo:and:foo"
, for example, yields the following results with these expressions:Split examples showing regex and result Regex Result : { "boo", "and", "foo" }
o { "b", "", ":and:f" }
- Parameters:
regex
- the delimiting regular expression- Returns:
- the Seq of strings computed by splitting this string around matches of the given regular expression
- Throws:
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid- See Also:
Pattern
-
split
public Seq<CharSeq> split(java.lang.String regex, int limit)
Splits this string around matches of the given regular expression.The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.
When there is a positive-width match at the beginning of this string then an empty leading substring is included at the beginning of the resulting array. A zero-width match at the beginning however never produces such empty leading substring.
The
limit
parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.The string
"boo:and:foo"
, for example, yields the following results with these parameters:Split example showing regex, limit, and result Regex Limit Result : 2 { "boo", "and:foo" }
: 5 { "boo", "and", "foo" }
: -2 { "boo", "and", "foo" }
o 5 { "b", "", ":and:f", "", "" }
o -2 { "b", "", ":and:f", "", "" }
o 0 { "b", "", ":and:f" }
split(
regex,
n)
yields the same result as the expressionPattern
.compile
(regex).split
(str, n)- Parameters:
regex
- the delimiting regular expressionlimit
- the result threshold, as described above- Returns:
- the Seq of strings computed by splitting this string around matches of the given regular expression
- Throws:
java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid- See Also:
Pattern
-
toLowerCase
public CharSeq toLowerCase(java.util.Locale locale)
Converts all of the characters in thisCharSeq
to lower case using the rules of the givenLocale
. Case mapping is based on the Unicode Standard version specified by theCharacter
class. Since case mappings are not always 1:1 char mappings, the resultingCharSeq
may be a different length than the originalCharSeq
.Examples of lowercase mappings are in the following table:
Lowercase mapping examples showing language code of locale, upper case, lower case, and description Language Code of Locale Upper Case Lower Case Description tr (Turkish) \u0130 \u0069 capital letter I with dot above -> small letter i tr (Turkish) \u0049 \u0131 capital letter I -> small letter dotless i (all) French Fries french fries lowercased all chars in String (all) lowercased all chars in String - Parameters:
locale
- use the case transformation rules for this locale- Returns:
- the
CharSeq
, converted to lowercase. - See Also:
String.toLowerCase()
,String.toUpperCase()
,String.toUpperCase(Locale)
-
toLowerCase
public CharSeq toLowerCase()
Converts all of the characters in thisCharSeq
to lower case using the rules of the default locale. This is equivalent to callingtoLowerCase(Locale.getDefault())
.Note: This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags. For instance,
"TITLE".toLowerCase()
in a Turkish locale returns"t\u0131tle"
, where '\u0131' is the LATIN SMALL LETTER DOTLESS I character. To obtain correct results for locale insensitive strings, usetoLowerCase(Locale.ROOT)
.- Returns:
- the
CharSeq
, converted to lowercase. - See Also:
String.toLowerCase(Locale)
-
toUpperCase
public CharSeq toUpperCase(java.util.Locale locale)
Converts all of the characters in thisCharSeq
to upper case using the rules of the givenLocale
. Case mapping is based on the Unicode Standard version specified by theCharacter
class. Since case mappings are not always 1:1 char mappings, the resultingCharSeq
may be a different length than the originalCharSeq
.Examples of locale-sensitive and 1:M case mappings are in the following table.
Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description. Language Code of Locale Lower Case Upper Case Description tr (Turkish) \u0069 \u0130 small letter i -> capital letter I with dot above tr (Turkish) \u0131 \u0049 small letter dotless i -> capital letter I (all) \u00df \u0053 \u0053 small letter sharp s -> two letters: SS (all) Fahrvergnügen FAHRVERGNÜGEN - Parameters:
locale
- use the case transformation rules for this locale- Returns:
- the
CharSeq
, converted to uppercase. - See Also:
String.toUpperCase()
,String.toLowerCase()
,String.toLowerCase(Locale)
-
toUpperCase
public CharSeq toUpperCase()
Converts all of the characters in thisCharSeq
to upper case using the rules of the default locale. This method is equivalent totoUpperCase(Locale.getDefault())
.Note: This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags. For instance,
"title".toUpperCase()
in a Turkish locale returns"T\u0130TLE"
, where '\u0130' is the LATIN CAPITAL LETTER I WITH DOT ABOVE character. To obtain correct results for locale insensitive strings, usetoUpperCase(Locale.ROOT)
.- Returns:
- the
CharSeq
, converted to uppercase. - See Also:
String.toUpperCase(Locale)
-
capitalize
public CharSeq capitalize(java.util.Locale locale)
Converts the first character in thisCharSeq
to upper case using the rules of the givenLocale
. If theCharSeq
is empty, it won't have any effect. Case mapping is based on the Unicode Standard version specified by theCharacter
class. Since case mappings are not always 1:1 char mappings, the resultingCharSeq
may be a different length than the originalCharSeq
.Examples of locale-sensitive and 1:M case mappings are in the following table.
Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description. Language Code of Locale Lower Case Upper Case Description tr (Turkish) \u0069 \u0130 small letter i -> capital letter I with dot above tr (Turkish) \u0131 \u0049 small letter dotless i -> capital letter I (all) \u00df \u0053 \u0053 small letter sharp s -> two letters: SS (all) Fahrvergnügen FAHRVERGNÜGEN - Parameters:
locale
- use the case transformation rules for this locale- Returns:
- the
CharSeq
, capitalized.
-
capitalize
public CharSeq capitalize()
Converts the first character in thisCharSeq
to upper case using the rules of the default locale. If theCharSeq
is empty, it won't have any effect. This method is equivalent tocapitalize(Locale.getDefault())
.Note: This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags. For instance,
"title".toUpperCase()
in a Turkish locale returns"T\u0130TLE"
, where '\u0130' is the LATIN CAPITAL LETTER I WITH DOT ABOVE character. To obtain correct results for locale insensitive strings, usetoUpperCase(Locale.ROOT)
.- Returns:
- the
CharSeq
, capitalized.
-
trim
public CharSeq trim()
Returns a string whose value is this string, with any leading and trailing whitespace removed.If this
CharSeq
object represents an empty character sequence, or the first and last characters of character sequence represented by thisCharSeq
object both have codes greater than'\u0020'
(the space character), then a reference to thisCharSeq
object is returned.Otherwise, if there is no character with a code greater than
'\u0020'
in the string, then aCharSeq
object representing an empty string is returned.Otherwise, let k be the index of the first character in the string whose code is greater than
'\u0020'
, and let m be the index of the last character in the string whose code is greater than'\u0020'
. ACharSeq
object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result ofthis.substring(k, m + 1)
.This method may be used to trim whitespace (as defined above) from the beginning and end of a string.
- Returns:
- A string whose value is this string, with any leading and trailing white space removed, or this string if it has no leading or trailing white space.
-
toCharArray
public char[] toCharArray()
Converts this string to a new character array.- Returns:
- a newly allocated character array whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.
-
decodeByte
public java.lang.Byte decodeByte()
Decodes thisCharSeq
into aByte
by callingByte.decode(String)
.We write
instead ofByte value = charSeq.decodeByte();
Byte value = Byte.decode(charSeq.mkString());
- Returns:
- a
Byte
object holding the byte value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- if thisCharSeq
does not contain a parsable byte.
-
decodeInteger
public java.lang.Integer decodeInteger()
Decodes thisCharSeq
into anInteger
by callingInteger.decode(String)
.We write
instead ofInteger value = charSeq.decodeInteger();
Integer value = Integer.decode(charSeq.mkString());
- Returns:
- an
Integer
object holding the int value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- if thisCharSeq
does not contain a parsable int.
-
decodeLong
public java.lang.Long decodeLong()
Decodes thisCharSeq
into aLong
by callingLong.decode(String)
.We write
instead ofLong value = charSeq.decodeLong();
Long value = Long.decode(charSeq.mkString());
- Returns:
- a
Long
object holding the long value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- if thisCharSeq
does not contain a parsable long.
-
decodeShort
public java.lang.Short decodeShort()
Decodes thisCharSeq
into aShort
by callingShort.decode(String)
.We write
instead ofShort value = charSeq.decodeShort();
Short value = Short.decode(charSeq.mkString());
- Returns:
- a
Short
object holding the short value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- if thisCharSeq
does not contain a parsable short.
-
parseBoolean
public boolean parseBoolean()
Parses thisCharSeq
as a boolean by callingBoolean.parseBoolean(String)
.We write
instead ofboolean value = charSeq.parseBoolean();
boolean value = Boolean.parseBoolean(charSeq.mkString());
- Returns:
- the boolean represented by this
CharSeq
-
parseByte
public byte parseByte()
Parses thisCharSeq
as a signed decimal byte by callingByte.parseByte(String)
.We write
instead ofbyte value = charSeq.parseByte();
byte value = Byte.parseByte(charSeq.mkString());
- Returns:
- the byte value represented by this
CharSeq
in decimal - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable byte.
-
parseByte
public byte parseByte(int radix)
Parses thisCharSeq
as a signed byte in the specified radix by callingByte.parseByte(String, int)
.We write
instead ofbyte value = charSeq.parseByte(radix);
byte value = Byte.parseByte(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting thisCharSeq
- Returns:
- the byte value represented by this
CharSeq
in the specified radix - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable byte.
-
parseDouble
public double parseDouble()
Parses thisCharSeq
as a double by callingDouble.parseDouble(String)
.We write
instead ofdouble value = charSeq.parseDouble();
double value = Double.parseDouble(charSeq.mkString());
- Returns:
- the double value represented by this
CharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable double.
-
parseFloat
public float parseFloat()
Parses thisCharSeq
as a float by callingFloat.parseFloat(String)
.We write
instead offloat value = charSeq.parseFloat();
float value = Double.parseFloat(charSeq.mkString());
- Returns:
- the float value represented by this
CharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable float.
-
parseInt
public int parseInt()
Parses thisCharSeq
as a signed decimal int by callingInteger.parseInt(String)
.We write
instead ofint value = charSeq.parseInt();
int value = Integer.parseInt(charSeq.mkString());
- Returns:
- the int value represented by this
CharSeq
in decimal - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable int.
-
parseInt
public int parseInt(int radix)
Parses thisCharSeq
as a signed int in the specified radix by callingInteger.parseInt(String, int)
.We write
instead ofint value = charSeq.parseInt(radix);
int value = Integer.parseInt(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting thisCharSeq
- Returns:
- the int value represented by this
CharSeq
in the specified radix - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable int.
-
parseUnsignedInt
@GwtIncompatible public int parseUnsignedInt()
Parses thisCharSeq
as a unsigned decimal int by callingInteger.parseUnsignedInt(String)
.We write
instead ofint value = charSeq.parseUnsignedInt();
int value = Integer.parseUnsignedInt(charSeq.mkString());
- Returns:
- the unsigned int value represented by this
CharSeq
in decimal - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable unsigned int.
-
parseUnsignedInt
@GwtIncompatible public int parseUnsignedInt(int radix)
Parses thisCharSeq
as a unsigned int in the specified radix by callingInteger.parseUnsignedInt(String, int)
.We write
instead ofint value = charSeq.parseUnsignedInt(radix);
int value = Integer.parseUnsignedInt(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting thisCharSeq
- Returns:
- the unsigned int value represented by this
CharSeq
in the specified radix - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable unsigned int.
-
parseLong
public long parseLong()
Parses thisCharSeq
as a signed decimal long by callingLong.parseLong(String)
.We write
instead oflong value = charSeq.parseLong();
long value = Long.parseLong(charSeq.mkString());
- Returns:
- the long value represented by this
CharSeq
in decimal - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable long.
-
parseLong
public long parseLong(int radix)
Parses thisCharSeq
as a signed long in the specified radix by callingLong.parseLong(String, int)
.We write
instead oflong value = charSeq.parseLong(radix);
long value = Long.parseLong(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting thisCharSeq
- Returns:
- the long value represented by this
CharSeq
in the specified radix - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable long.
-
parseUnsignedLong
@GwtIncompatible public long parseUnsignedLong()
Parses thisCharSeq
as a unsigned decimal long by callingLong.parseUnsignedLong(String)
.We write
instead oflong value = charSeq.parseUnsignedLong();
long value = Long.parseUnsignedLong(charSeq.mkString());
- Returns:
- the unsigned long value represented by this
CharSeq
in decimal - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable unsigned long.
-
parseUnsignedLong
@GwtIncompatible public long parseUnsignedLong(int radix)
Parses thisCharSeq
as a unsigned long in the specified radix by callingLong.parseUnsignedLong(String, int)
.We write
instead oflong value = charSeq.parseUnsignedLong(radix);
long value = Long.parseUnsignedLong(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting thisCharSeq
- Returns:
- the unsigned long value represented by this
CharSeq
in the specified radix - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable unsigned long.
-
parseShort
public short parseShort()
Parses thisCharSeq
as a signed decimal short by callingShort.parseShort(String)
.We write
instead ofshort value = charSeq.parseShort();
short value = Short.parseShort(charSeq.mkString());
- Returns:
- the short value represented by this
CharSeq
in decimal - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable short.
-
parseShort
public short parseShort(int radix)
Parses thisCharSeq
as a signed short in the specified radix by callingShort.parseShort(String, int)
.We write
instead ofshort value = charSeq.parseShort(radix);
short value = Short.parseShort(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting thisCharSeq
- Returns:
- the short value represented by this
CharSeq
in the specified radix - Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable short.
-
toBoolean
public java.lang.Boolean toBoolean()
Converts thisCharSeq
to aBoolean
by callingBoolean.valueOf(String)
.We write
instead ofBoolean value = charSeq.toBoolean();
Boolean value = Boolean.valueOf(charSeq.mkString());
- Returns:
- the
Boolean
value represented by thisCharSeq
-
toByte
public java.lang.Byte toByte()
Converts thisCharSeq
to aByte
by callingByte.valueOf(String)
.We write
instead ofByte value = charSeq.toByte();
Byte value = Byte.valueOf(charSeq.mkString());
- Returns:
- a
Byte
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable byte.
-
toByte
public java.lang.Byte toByte(int radix)
Converts thisCharSeq
to aByte
in the specified radix by callingByte.valueOf(String, int)
.We write
instead ofByte value = charSeq.toByte(radix);
Byte value = Byte.valueOf(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting this char sequence- Returns:
- a
Byte
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable byte.
-
toDouble
public java.lang.Double toDouble()
Converts thisCharSeq
to aDouble
by callingDouble.valueOf(String)
.We write
instead ofDouble value = charSeq.toDouble();
Double value = Double.valueOf(charSeq.mkString());
- Returns:
- a
Double
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable double.
-
toFloat
public java.lang.Float toFloat()
Converts thisCharSeq
to aFloat
by callingFloat.valueOf(String)
.We write
instead ofFloat value = charSeq.toFloat();
Float value = Float.valueOf(charSeq.mkString());
- Returns:
- a
Float
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable float.
-
toInteger
public java.lang.Integer toInteger()
Converts thisCharSeq
to anInteger
by callingInteger.valueOf(String)
.We write
instead ofInteger value = charSeq.toInteger();
Integer value = Integer.valueOf(charSeq.mkString());
- Returns:
- an
Integer
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable int.
-
toInteger
public java.lang.Integer toInteger(int radix)
Converts thisCharSeq
to anInteger
in the specified radix by callingInteger.valueOf(String, int)
.We write
instead ofInteger value = charSeq.toInteger(radix);
Integer value = Integer.valueOf(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting this char sequence- Returns:
- an
Integer
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable int.
-
toLong
public java.lang.Long toLong()
Converts thisCharSeq
to aLong
by callingLong.valueOf(String)
.We write
instead ofLong value = charSeq.toLong();
Long value = Long.valueOf(charSeq.mkString());
- Returns:
- a
Long
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable long.
-
toLong
public java.lang.Long toLong(int radix)
Converts thisCharSeq
to aLong
in the specified radix by callingLong.valueOf(String, int)
.We write
instead ofLong value = charSeq.toLong(radix);
Long value = Long.valueOf(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting this char sequence- Returns:
- a
Long
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable long.
-
toShort
public java.lang.Short toShort()
Converts thisCharSeq
to aShort
by callingShort.valueOf(String)
.We write
instead ofShort value = charSeq.toShort();
Short value = Short.valueOf(charSeq.mkString());
- Returns:
- a
Short
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable short.
-
toShort
public java.lang.Short toShort(int radix)
Converts thisCharSeq
to aShort
in the specified radix by callingShort.valueOf(String, int)
.We write
instead ofShort value = charSeq.toShort(radix);
Short value = Short.valueOf(charSeq.mkString(), radix);
- Parameters:
radix
- the radix to be used in interpreting this char sequence- Returns:
- a
Short
object holding the value represented by thisCharSeq
- Throws:
java.lang.NumberFormatException
- If thisCharSeq
does not contain a parsable short.
-
toJavaArray
public java.lang.Character[] toJavaArray()
Description copied from interface:Value
Converts this to a Java array with component typeObject
// = [] of type Object[] Future.<String> of(() -> { throw new Error(); }) .toJavaArray() // = [ok] of type Object[] Try.of(() -> "ok") .toJavaArray() // = [1, 2, 3] of type Object[] List.of(1, 2, 3) .toJavaArray()
- Specified by:
toJavaArray
in interfaceValue<java.lang.Character>
- Returns:
- A new Java array.
-
-