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>,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
nullelements.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCharSeq.CharFunction<R>Represents a function that accepts achar-valued argument and produces a result.static interfaceCharSeq.CharUnaryOperatorRepresents an operation on a singlechar-valued operand that produces achar-valued result.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringbackprivate static CharSeqEMPTYprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description privateCharSeq(java.lang.String javaString)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CharSeqappend(java.lang.Character element)Returns a new sequence with the given element appended at the end.CharSeqappendAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)Returns a new sequence with all elements from the givenIterableappended at the end of this sequence.java.util.List<java.lang.Character>asJava()Returns an immutableListview of thisSeq.CharSeqasJava(@NonNull java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)Creates an immutableListview of thisSeqand passes it to the givenaction.java.util.List<java.lang.Character>asJavaMutable()Returns a mutableListview of thisSeq.CharSeqasJavaMutable(@NonNull java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)Creates a mutableListview of thisSeqand passes it to the givenaction.CharSeqcapitalize()Converts the first character in thisCharSeqto upper case using the rules of the default locale.CharSeqcapitalize(java.util.Locale locale)Converts the first character in thisCharSeqto upper case using the rules of the givenLocale.charcharAt(int index)Returns thecharvalue at the specified index.intcodePointAt(int index)Returns the character (Unicode code point) at the specified index.intcodePointBefore(int index)Returns the character (Unicode code point) before the specified index.intcodePointCount(int beginIndex, int endIndex)Returns the number of Unicode code points in the specified text range of thisCharSeq.<R> IndexedSeq<R>collect(@NonNull PartialFunction<? super java.lang.Character,? extends R> partialFunction)Applies aPartialFunctionto all elements that are defined for it and collects the results.static java.util.stream.Collector<java.lang.Character,java.util.ArrayList<java.lang.Character>,CharSeq>collector()Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aCharSeq.IndexedSeq<CharSeq>combinations()Returns a sequence containing all combinations of elements from this sequence, for all sizes from0tolength().IndexedSeq<CharSeq>combinations(int k)Returns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.intcompareTo(CharSeq anotherString)Compares two strings lexicographically.intcompareToIgnoreCase(CharSeq str)Compares two strings lexicographically, ignoring case differences.CharSeqconcat(CharSeq str)Concatenates the specified string to the end of this string.booleancontains(java.lang.CharSequence s)Returns true if and only if this string contains the specified sequence of char values.booleancontentEquals(java.lang.CharSequence cs)Compares this string to the specifiedCharSequence.booleancontentEquals(java.lang.StringBuffer sb)Compares this string to the specifiedStringBuffer.Iterator<CharSeq>crossProduct(int power)Returns the n-ary Cartesian power (cross product) of this sequence.java.lang.BytedecodeByte()Decodes thisCharSeqinto aByteby callingByte.decode(String).java.lang.IntegerdecodeInteger()Decodes thisCharSeqinto anIntegerby callingInteger.decode(String).java.lang.LongdecodeLong()Decodes thisCharSeqinto aLongby callingLong.decode(String).java.lang.ShortdecodeShort()Decodes thisCharSeqinto aShortby callingShort.decode(String).CharSeqdistinct()Returns a newTraversablecontaining the elements of this instance with all duplicates removed.CharSeqdistinctBy(@NonNull java.util.Comparator<? super java.lang.Character> comparator)Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.<U> CharSeqdistinctBy(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> keyExtractor)Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.CharSeqdistinctByKeepLast(@NonNull java.util.Comparator<? super java.lang.Character> comparator)Returns a sequence with duplicate elements removed, as determined by the provided comparator.<U> CharSeqdistinctByKeepLast(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> keyExtractor)Returns a sequence with duplicates removed based on a key extracted from each element.CharSeqdrop(int n)Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.CharSeqdropRight(int n)Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.CharSeqdropRightUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Drops elements from the end of the sequence until an element satisfies the given predicate.CharSeqdropRightWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Drops elements from the end of the sequence while the given predicate holds.CharSeqdropUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.CharSeqdropWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.static CharSeqempty()Returns the empty CharSeq.booleanendsWith(CharSeq suffix)Tests if this string ends with the specified suffix.booleanequals(java.lang.Object o)Determines whether this collection is equal to the given object.booleanequalsIgnoreCase(CharSeq anotherString)Compares thisCharSeqto anotherCharSeq, ignoring case considerations.static CharSeqfill(int n, java.util.function.Supplier<? extends java.lang.Character> s)Returns a CharSeq containingnvalues supplied by a given Suppliers.CharSeqfilter(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Returns a new traversable containing only the elements that satisfy the given predicate.<U> IndexedSeq<U>flatMap(@NonNull java.util.function.Function<? super java.lang.Character,? extends java.lang.Iterable<? extends U>> mapper)Transforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.CharSeqflatMapChars(@NonNull CharSeq.CharFunction<? extends java.lang.CharSequence> mapper)FlatMaps thisCharSeqto a newCharSeqby applying aCharFunctionto each character, which returns aCharSequence, and concatenating the results.java.lang.Characterget(int index)Returns the element at the specified index.byte[]getBytes()Encodes thisCharSeqinto 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 thisCharSeqinto a sequence of bytes using the named charset, storing the result into a new byte array.byte[]getBytes(java.nio.charset.Charset charset)Encodes thisCharSeqinto a sequence of bytes using the given charset, storing the result into a new byte array.voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)Copies characters from this string into the destination character array.<C> Map<C,CharSeq>groupBy(@NonNull java.util.function.Function<? super java.lang.Character,? extends C> classifier)Groups elements of thisTraversablebased on a classifier function.Iterator<CharSeq>grouped(int size)Splits thisTraversableinto consecutive blocks of the given size.booleanhasDefiniteSize()Indicates whether thisTraversablehas a known finite size.inthashCode()Returns the hash code of this collection.java.lang.Characterhead()Returns the first element of this non-emptyTraversable.intindexOf(int ch)Returns the index within this string of the first occurrence of the specified character.intindexOf(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.intindexOf(CharSeq str)Returns the index within this string of the first occurrence of the specified substring.intindexOf(CharSeq str, int fromIndex)Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.intindexOf(java.lang.Character element, int from)Returns the index of the first occurrence of the given element, starting at the specified index, or-1if this sequence does not contain the element.(package private) Option<java.lang.Integer>indexOfOption(int ch)Returns the index of the first occurrence of the given element as anOption.(package private) Option<java.lang.Integer>indexOfOption(int ch, int fromIndex)Returns the index of the first occurrence of the given element as anOption, starting the search at the specified index.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.CharSeqinit()Returns all elements of this Traversable except the last one.Option<CharSeq>initOption()Returns all elements of this Traversable except the last one, wrapped in anOption.CharSeqinsert(int index, java.lang.Character element)Returns a new sequence with the given element inserted at the specified index.CharSeqinsertAll(int index, @NonNull java.lang.Iterable<? extends java.lang.Character> elements)Returns a new sequence with the given elements inserted at the specified index.CharSeqintersperse(java.lang.Character element)Returns a new sequence where the given element is inserted between all elements of this sequence.booleanisAsync()ACharSeqis computed synchronously.booleanisEmpty()Checks if this Traversable contains no elements.booleanisLazy()ACharSeqis computed eagerly.booleanisTraversableAgain()Checks if this Traversable can be traversed multiple times without side effects.@NonNull Iterator<java.lang.Character>iterator()Returns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail().intlastIndexOf(int ch)Returns the index within this string of the last occurrence of the specified character.intlastIndexOf(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.intlastIndexOf(CharSeq str)Returns the index within this string of the last occurrence of the specified substring.intlastIndexOf(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.intlastIndexOf(java.lang.Character element, int end)Returns the index of the last occurrence of the given element at or before the specified end index, or-1if this sequence does not contain the element.(package private) Option<java.lang.Integer>lastIndexOfOption(int ch)Returns the index of the last occurrence of the given element as anOption.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.CharSeqleftPadTo(int length, java.lang.Character element)Returns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.intlength()Returns the length of this string.<U> IndexedSeq<U>map(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> mapper)Transforms the elements of this Traversable to a new type, preserving order if defined.CharSeqmapChars(CharSeq.CharUnaryOperator mapper)Maps thisCharSeqto a newCharSeqby applying aCharUnaryOperatorto each character.<U> IndexedSeq<U>mapTo(U value)Maps the underlying value to another fixed value.IndexedSeq<java.lang.Void>mapToVoid()Maps the underlying value to Voidbooleanmatches(java.lang.String regex)Tells whether or not this string matches the given regular expression.java.lang.StringmkString()Concatenates the string representations of all elements in this Traversable.static CharSeqof(char character)Returns a singletonCharSeq, i.e.static CharSeqof(char @NonNull ... characters)Creates a String of the given characters.static CharSeqof(@NonNull java.lang.CharSequence sequence)Creates a String ofCharSequence.static CharSeqofAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)Creates a String of the given elements.intoffsetByCodePoints(int index, int codePointOffset)Returns the index within thisCharSeqthat is offset from the givenindexbycodePointOffsetcode points.CharSeqorElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends java.lang.Character>> supplier)Returns thisTraversableif it is non-empty; otherwise, returns the result of evaluating the given supplier.CharSeqorElse(java.lang.Iterable<? extends java.lang.Character> other)Returns thisTraversableif it is non-empty; otherwise, returns the given alternative.private static java.lang.StringBuilderpadding(char element, int limit)CharSeqpadTo(int length, java.lang.Character element)Returns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.booleanparseBoolean()Parses thisCharSeqas a boolean by callingBoolean.parseBoolean(String).byteparseByte()Parses thisCharSeqas a signed decimal byte by callingByte.parseByte(String).byteparseByte(int radix)Parses thisCharSeqas a signed byte in the specified radix by callingByte.parseByte(String, int).doubleparseDouble()Parses thisCharSeqas a double by callingDouble.parseDouble(String).floatparseFloat()Parses thisCharSeqas a float by callingFloat.parseFloat(String).intparseInt()Parses thisCharSeqas a signed decimal int by callingInteger.parseInt(String).intparseInt(int radix)Parses thisCharSeqas a signed int in the specified radix by callingInteger.parseInt(String, int).longparseLong()Parses thisCharSeqas a signed decimal long by callingLong.parseLong(String).longparseLong(int radix)Parses thisCharSeqas a signed long in the specified radix by callingLong.parseLong(String, int).shortparseShort()Parses thisCharSeqas a signed decimal short by callingShort.parseShort(String).shortparseShort(int radix)Parses thisCharSeqas a signed short in the specified radix by callingShort.parseShort(String, int).intparseUnsignedInt()Parses thisCharSeqas a unsigned decimal int by callingInteger.parseUnsignedInt(String).intparseUnsignedInt(int radix)Parses thisCharSeqas a unsigned int in the specified radix by callingInteger.parseUnsignedInt(String, int).longparseUnsignedLong()Parses thisCharSeqas a unsigned decimal long by callingLong.parseUnsignedLong(String).longparseUnsignedLong(int radix)Parses thisCharSeqas a unsigned long in the specified radix by callingLong.parseUnsignedLong(String, int).Tuple2<CharSeq,CharSeq>partition(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Splits thisTraversableinto two partitions according to a predicate.CharSeqpatch(int from, @NonNull java.lang.Iterable<? extends java.lang.Character> that, int replaced)Returns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.CharSeqpeek(@NonNull java.util.function.Consumer<? super java.lang.Character> action)Performs the givenactionon the first element if this is an eager implementation.IndexedSeq<CharSeq>permutations()Returns all unique permutations of this sequence.CharSeqprepend(java.lang.Character element)Returns a new sequence with the given element prepended to this sequence.CharSeqprependAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)Returns a new sequence with all given elements prepended to this sequence.static CharSeqrange(char from, char toExclusive)Creates a CharSeq starting from characterfrom, extending to charactertoExclusive - 1.static CharSeqrangeBy(char from, char toExclusive, int step)Creates a CharSeq starting from characterfrom, extending to charactertoExclusive - 1, withstep.static CharSeqrangeClosed(char from, char toInclusive)Creates a CharSeq starting from characterfrom, extending to charactertoInclusive.static CharSeqrangeClosedBy(char from, char toInclusive, int step)Creates a CharSeq starting from characterfrom, extending to charactertoInclusive, withstep.private java.lang.ObjectreadResolve()booleanregionMatches(boolean ignoreCase, int toffset, CharSeq other, int ooffset, int len)Tests if two string regions are equal.booleanregionMatches(int toffset, CharSeq other, int ooffset, int len)Tests if two string regions are equal.CharSeqreject(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Returns a new traversable containing only the elements that do not satisfy the given predicate.CharSeqremove(java.lang.Character element)Returns a new sequence with the first occurrence of the given element removed.CharSeqremoveAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)Returns a new sequence with all occurrences of the given elements removed.CharSeqremoveAll(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Deprecated.CharSeqremoveAll(java.lang.Character element)Returns a new sequence with all occurrences of the given element removed.CharSeqremoveAt(int index)Returns a new sequence with the element at the specified position removed.CharSeqremoveFirst(@NonNull java.util.function.Predicate<java.lang.Character> predicate)Returns a new sequence with the first element that satisfies the given predicate removed.CharSeqremoveLast(@NonNull java.util.function.Predicate<java.lang.Character> predicate)Returns a new sequence with the last element that satisfies the given predicate removed.static CharSeqrepeat(char character, int times)Repeats a charactertimestimes.CharSeqrepeat(int times)Repeats this CharSeqtimestimes.CharSeqreplace(java.lang.Character currentElement, java.lang.Character newElement)Replaces the first occurrence ofcurrentElementwithnewElement, if it exists.CharSeqreplace(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.CharSeqreplaceAll(java.lang.Character currentElement, java.lang.Character newElement)Replaces all occurrences ofcurrentElementwithnewElement.CharSeqreplaceAll(java.lang.String regex, java.lang.String replacement)Replaces each substring of this string that matches the given regular expression with the given replacement.CharSeqreplaceFirst(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.CharSeqretainAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)Retains only the elements from this Traversable that are contained in the givenelements.CharSeqreverse()Returns a new sequence with the order of elements reversed.CharSeqrotateLeft(int n)Returns a new sequence with the elements circularly rotated to the left by the specified distance.CharSeqrotateRight(int n)Returns a new sequence with the elements circularly rotated to the right by the specified distance.CharSeqscan(java.lang.Character zero, @NonNull 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 this Traversable.<U> IndexedSeq<U>scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super java.lang.Character,? extends U> operation)Produces a collection containing cumulative results of applying the operator from left to right.<U> IndexedSeq<U>scanRight(U zero, @NonNull java.util.function.BiFunction<? super java.lang.Character,? super U,? extends U> operation)Produces a collection containing cumulative results of applying the operator from right to left.CharSeqshuffle()Returns a new sequence with the elements randomly shuffled.CharSeqslice(int beginIndex, int endIndex)Returns a subsequence (slice) of this sequence, starting atbeginIndex(inclusive) and ending atendIndex(exclusive).Iterator<CharSeq>slideBy(@NonNull java.util.function.Function<? super java.lang.Character,?> classifier)Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Iterator<CharSeq>sliding(int size)Slides a window of a givensizeover thisTraversablewith a step size of 1.Iterator<CharSeq>sliding(int size, int step)Slides a window of a specificsizewith a givenstepover thisTraversable.<U> CharSeqsortBy(@NonNull java.util.Comparator<? super U> comparator, java.util.function.Function<? super java.lang.Character,? extends U> mapper)Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper, using the providedcomparator.<U extends java.lang.Comparable<? super U>>
CharSeqsortBy(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> mapper)Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper.CharSeqsorted()Returns a new sequence with elements sorted according to their natural order.CharSeqsorted(@NonNull java.util.Comparator<? super java.lang.Character> comparator)Returns a new sequence with elements sorted according to the givenComparator.Tuple2<CharSeq,CharSeq>span(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Splits thisTraversableinto a prefix and remainder according to the givenpredicate.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 this sequence at the specified index.Tuple2<CharSeq,CharSeq>splitAt(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Splits this sequence at the first element satisfying the given predicate.Tuple2<CharSeq,CharSeq>splitAtInclusive(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Splits this sequence at the first element satisfying the given predicate, including the element in the first part.private Tuple2<CharSeq,CharSeq>splitByBuilder(java.lang.StringBuilder sb)booleanstartsWith(@NonNull java.lang.Iterable<? extends java.lang.Character> that, int offset)Tests whether this sequence contains the given sequence starting at the specified index.booleanstartsWith(CharSeq prefix)Tests if this string starts with the specified prefix.booleanstartsWith(CharSeq prefix, int toffset)Tests if the substring of this string beginning at the specified index starts with the specified prefix.java.lang.StringstringPrefix()Returns the name of this Value type, which is used by toString().CharSeqsubSequence(int beginIndex)Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndexand extending to the end of this sequence.CharSeqsubSequence(int beginIndex, int endIndex)Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndex(inclusive) and ending atendIndex(exclusive).CharSeqsubstring(int beginIndex)Returns a string that is a substring of this string.CharSeqsubstring(int beginIndex, int endIndex)Returns a string that is a substring of this string.static CharSeqtabulate(int n, @NonNull java.util.function.Function<? super java.lang.Integer,? extends java.lang.Character> f)Returns a CharSeq containingnvalues of a given Functionfover a range of integer values from 0 ton - 1.CharSeqtail()Returns a newTraversablewithout its first element.Option<CharSeq>tailOption()Returns a newTraversablewithout its first element as anOption.CharSeqtake(int n)Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.CharSeqtakeRight(int n)Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.CharSeqtakeRightUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Takes elements from the end of the sequence until an element satisfies the given predicate.CharSeqtakeRightWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Takes elements from the end of the sequence while the given predicate holds.CharSeqtakeUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Takes elements from thisTraversableuntil the given predicate holds for an element.CharSeqtakeWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)Takes elements from thisTraversablewhile the given predicate holds.java.lang.BooleantoBoolean()Converts thisCharSeqto aBooleanby callingBoolean.valueOf(String).java.lang.BytetoByte()Converts thisCharSeqto aByteby callingByte.valueOf(String).java.lang.BytetoByte(int radix)Converts thisCharSeqto aBytein the specified radix by callingByte.valueOf(String, int).char[]toCharArray()Converts this string to a new character array.java.lang.DoubletoDouble()Converts thisCharSeqto aDoubleby callingDouble.valueOf(String).java.lang.FloattoFloat()Converts thisCharSeqto aFloatby callingFloat.valueOf(String).java.lang.IntegertoInteger()Converts thisCharSeqto anIntegerby callingInteger.valueOf(String).java.lang.IntegertoInteger(int radix)Converts thisCharSeqto anIntegerin the specified radix by callingInteger.valueOf(String, int).java.lang.Character[]toJavaArray()Converts this to a Java array with component typeObjectjava.lang.LongtoLong()Converts thisCharSeqto aLongby callingLong.valueOf(String).java.lang.LongtoLong(int radix)Converts thisCharSeqto aLongin the specified radix by callingLong.valueOf(String, int).CharSeqtoLowerCase()Converts all of the characters in thisCharSeqto lower case using the rules of the default locale.CharSeqtoLowerCase(java.util.Locale locale)Converts all of the characters in thisCharSeqto lower case using the rules of the givenLocale.java.lang.ShorttoShort()Converts thisCharSeqto aShortby callingShort.valueOf(String).java.lang.ShorttoShort(int radix)Converts thisCharSeqto aShortin the specified radix by callingShort.valueOf(String, int).java.lang.StringtoString()Returns a string containing the characters in this sequence in the same order as this sequence.CharSeqtoUpperCase()Converts all of the characters in thisCharSeqto upper case using the rules of the default locale.CharSeqtoUpperCase(java.util.Locale locale)Converts all of the characters in thisCharSeqto upper case using the rules of the givenLocale.<U> Utransform(java.util.function.Function<? super CharSeq,? extends U> f)Transforms thisCharSeq.CharSeqtrim()Returns a string whose value is this string, with any leading and trailing whitespace removed.static CharSequnfold(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> CharSequnfoldLeft(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> CharSequnfoldRight(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(@NonNull java.util.function.Function<? super java.lang.Character,Tuple2<? extends T1,? extends T2>> unzipper)Unzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.<T1,T2,T3>
Tuple3<IndexedSeq<T1>,IndexedSeq<T2>,IndexedSeq<T3>>unzip3(@NonNull java.util.function.Function<? super java.lang.Character,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)Unzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.CharSequpdate(int index, @NonNull java.util.function.Function<? super java.lang.Character,? extends java.lang.Character> updater)Returns a newSeqwith the element at the specified index updated using the given function.CharSequpdate(int index, java.lang.Character element)Returns a newSeqwith the element at the specified index replaced by the given value.<U> IndexedSeq<Tuple2<java.lang.Character,U>>zip(@NonNull java.lang.Iterable<? extends U> that)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable.<U> IndexedSeq<Tuple2<java.lang.Character,U>>zipAll(@NonNull java.lang.Iterable<? extends U> that, java.lang.Character thisElem, U thatElem)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.<U,R>
IndexedSeq<R>zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super java.lang.Character,? super U,? extends R> mapper)Returns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function.IndexedSeq<Tuple2<java.lang.Character,java.lang.Integer>>zipWithIndex()Zips thisTraversablewith its indices, starting at 0.<U> IndexedSeq<U>zipWithIndex(@NonNull java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Integer,? extends U> mapper)Zips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOption
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, 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, foldLeft, forEachWithIndex, get, headOption, isDistinct, isOrdered, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, nonEmpty, product, reduceLeft, reduceLeftOption, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
EMPTY
private static final CharSeq EMPTY
-
back
private final java.lang.String back
-
-
Method Detail
-
empty
public static CharSeq empty()
Returns the empty CharSeq.- Returns:
- An empty CharSeq
-
collector
public static java.util.stream.Collector<java.lang.Character,java.util.ArrayList<java.lang.Character>,CharSeq> collector()
Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aCharSeq.- Returns:
- A
CharSeqCollector.
-
of
public static CharSeq of(@NonNull java.lang.CharSequence sequence)
Creates a String ofCharSequence.- Parameters:
sequence-CharSequenceinstance.- Returns:
- A new
CharSeq
-
of
public static CharSeq of(char character)
Returns a singletonCharSeq, i.e. aCharSeqof one character.- Parameters:
character- A character.- Returns:
- A new
CharSeqinstance containing the given element
-
of
public static CharSeq of(char @NonNull ... 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- ifelementsis null
-
ofAll
public static CharSeq ofAll(@NonNull 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- ifelementsis null orelementscontains null
-
tabulate
public static CharSeq tabulate(int n, @NonNull java.util.function.Function<? super java.lang.Integer,? extends java.lang.Character> f)
Returns a CharSeq containingnvalues of a given Functionfover 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- iffis null
-
fill
public static CharSeq fill(int n, java.util.function.Supplier<? extends java.lang.Character> s)
Returns a CharSeq containingnvalues 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- ifsis 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)
Creates a CharSeq starting from characterfrom, extending to charactertoExclusive - 1, withstep.Examples:
CharSeq.rangeBy('a', 'e', 2) // = "ac" CharSeq.rangeBy('e', 'a', -2) // = "ec"- Parameters:
from- the first charactertoExclusive- the successor of the last characterstep- the step- Returns:
- a range of characters from
from(inclusive) totoExclusive(exclusive) bystep, or an empty CharSeq if the parameters would result in an empty range
-
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- ifstepis 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 returnNonewhen it's done generating the CharSeq, otherwiseSomeTupleof 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- iffis 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 returnNonewhen it's done generating the CharSeq, otherwiseSomeTupleof 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- iffis 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 returnNonewhen it's done generating the CharSeq, otherwiseSomeTupleof 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- iffis null
-
repeat
public static CharSeq repeat(char character, int times)
Repeats a charactertimestimes.- Parameters:
character- A charactertimes- Repetition count- Returns:
- A CharSeq representing
character * times
-
repeat
public CharSeq repeat(int times)
Repeats this CharSeqtimestimes.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:SeqReturns a new sequence with the given element appended at the end.- Specified by:
appendin interfaceIndexedSeq<java.lang.Character>- Specified by:
appendin interfaceSeq<java.lang.Character>- Parameters:
element- the element to append- Returns:
- a new
Seqcontaining all elements of this sequence followed by the given element
-
appendAll
public CharSeq appendAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:SeqReturns a new sequence with all elements from the givenIterableappended at the end of this sequence.- Specified by:
appendAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
appendAllin interfaceSeq<java.lang.Character>- Parameters:
elements- the elements to append; must not benull- Returns:
- a new
Seqcontaining all elements of this sequence followed by the given elements
-
asJava
@GwtIncompatible public java.util.List<java.lang.Character> asJava()
Description copied from interface:SeqReturns an immutableListview of thisSeq. Any attempt to modify the view (e.g., via mutator methods) will throwUnsupportedOperationExceptionat runtime.This is a view, not a copy. Compared to conversion methods like
toJava*():- Creating the view is O(1) (constant time), whereas conversions take O(n), with n = collection size.
- Operations on the view have the same performance characteristics as the underlying persistent Vavr collection, while converted collections behave like standard Java collections.
Note: the immutable Java list view throws
UnsupportedOperationExceptionbefore checking method arguments, which may differ from standard Java behavior.
-
asJava
@GwtIncompatible public CharSeq asJava(@NonNull java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)
Description copied from interface:SeqCreates an immutableListview of thisSeqand passes it to the givenaction.The view is immutable: any attempt to modify it will throw
UnsupportedOperationExceptionat runtime.- Specified by:
asJavain interfaceIndexedSeq<java.lang.Character>- Specified by:
asJavain interfaceSeq<java.lang.Character>- Parameters:
action- a side-effecting operation that receives an immutablejava.util.Listview- Returns:
- this sequence
- See Also:
Seq.asJava()
-
asJavaMutable
@GwtIncompatible public java.util.List<java.lang.Character> asJavaMutable()
Description copied from interface:SeqReturns a mutableListview of thisSeq. All standard mutator methods of theListinterface are supported and modify the underlying view.Unlike
Seq.asJava(), this view allows modifications, but the performance characteristics correspond to the underlying persistent Vavr collection.- Specified by:
asJavaMutablein interfaceSeq<java.lang.Character>- Returns:
- a mutable
Listview of this sequence - See Also:
Seq.asJava()
-
asJavaMutable
@GwtIncompatible public CharSeq asJavaMutable(@NonNull java.util.function.Consumer<? super java.util.List<java.lang.Character>> action)
Description copied from interface:SeqCreates a mutableListview of thisSeqand passes it to the givenaction.The view supports all standard mutator methods. The result of the action determines what is returned:
- If only read operations are performed, this instance is returned.
- If any write operations are performed, a new
Seqreflecting those changes is returned.
- Specified by:
asJavaMutablein interfaceIndexedSeq<java.lang.Character>- Specified by:
asJavaMutablein interfaceSeq<java.lang.Character>- Parameters:
action- a side-effecting operation that receives a mutablejava.util.Listview- Returns:
- this sequence or a new sequence reflecting modifications made through the view
- See Also:
Seq.asJavaMutable()
-
collect
public <R> IndexedSeq<R> collect(@NonNull PartialFunction<? super java.lang.Character,? extends R> partialFunction)
Description copied from interface:TraversableApplies aPartialFunctionto all elements that are defined for it and collects the results.For each element in iteration order, the function is first tested:
IfpartialFunction.isDefinedAt(element)true, the element is mapped to typeR:R newElement = partialFunction.apply(element)Note: If this
Traversableis ordered (i.e., extendsOrdered), the caller must ensure that the resulting elements are comparable (i.e., implementComparable).- Specified by:
collectin interfaceIndexedSeq<java.lang.Character>- Specified by:
collectin interfaceSeq<java.lang.Character>- Specified by:
collectin interfaceTraversable<java.lang.Character>- Type Parameters:
R- the type of elements in the resultingTraversable- Parameters:
partialFunction- a function that may not be defined for all elements of this traversable- Returns:
- a new
Traversablecontaining the results of applying the partial function
-
combinations
public IndexedSeq<CharSeq> combinations()
Description copied from interface:SeqReturns a sequence containing all combinations of elements from this sequence, for all sizes from0tolength().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:
combinationsin interfaceIndexedSeq<java.lang.Character>- Specified by:
combinationsin interfaceSeq<java.lang.Character>- Returns:
- a sequence of sequences representing all combinations of this sequence's elements
-
combinations
public IndexedSeq<CharSeq> combinations(int k)
Description copied from interface:SeqReturns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.- Specified by:
combinationsin interfaceIndexedSeq<java.lang.Character>- Specified by:
combinationsin interfaceSeq<java.lang.Character>- Parameters:
k- the size of each subset- Returns:
- a sequence of sequences representing all k-element combinations
- See Also:
- Combination
-
crossProduct
public Iterator<CharSeq> crossProduct(int power)
Description copied from interface:SeqReturns the n-ary Cartesian power (cross product) of this sequence. Each element of the resulting iterator is a sequence of lengthpower, containing all possible combinations of elements from this sequence.Example for power = 2:
// Result: [(A,A), (A,B), (A,C), ..., (B,A), (B,B), ..., (Z,Y), (Z,Z)] CharSeq.rangeClosed('A', 'Z').crossProduct(2);If
poweris negative, the result is an empty iterator:// Result: () CharSeq.rangeClosed('A', 'Z').crossProduct(-1);- Specified by:
crossProductin interfaceIndexedSeq<java.lang.Character>- Specified by:
crossProductin interfaceSeq<java.lang.Character>- Parameters:
power- the number of Cartesian multiplications- Returns:
- an
Iteratorover sequences representing the Cartesian power of this sequence
-
distinct
public CharSeq distinct()
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance with all duplicates removed. Element equality is determined usingequals.- Specified by:
distinctin interfaceIndexedSeq<java.lang.Character>- Specified by:
distinctin interfaceSeq<java.lang.Character>- Specified by:
distinctin interfaceTraversable<java.lang.Character>- Returns:
- a new
Traversablewithout duplicate elements
-
distinctBy
public CharSeq distinctBy(@NonNull java.util.Comparator<? super java.lang.Character> comparator)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceIndexedSeq<java.lang.Character>- Specified by:
distinctByin interfaceSeq<java.lang.Character>- Specified by:
distinctByin interfaceTraversable<java.lang.Character>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
public <U> CharSeq distinctBy(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> keyExtractor)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.The first occurrence of each key is retained in the resulting sequence.
- Specified by:
distinctByin interfaceIndexedSeq<java.lang.Character>- Specified by:
distinctByin interfaceSeq<java.lang.Character>- Specified by:
distinctByin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of key- Parameters:
keyExtractor- a function to extract keys for determining uniqueness- Returns:
- a new
Traversablewith duplicates removed based on keys
-
distinctByKeepLast
public CharSeq distinctByKeepLast(@NonNull java.util.Comparator<? super java.lang.Character> comparator)
Description copied from interface:SeqReturns a sequence with duplicate elements removed, as determined by the provided comparator. When duplicates are found, the **last occurrence** of each element is retained.- Specified by:
distinctByKeepLastin interfaceIndexedSeq<java.lang.Character>- Specified by:
distinctByKeepLastin interfaceSeq<java.lang.Character>- Parameters:
comparator- a comparator defining equality between elements- Returns:
- a new sequence with duplicates removed, keeping the last occurrence of each element
-
distinctByKeepLast
public <U> CharSeq distinctByKeepLast(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> keyExtractor)
Description copied from interface:SeqReturns a sequence with duplicates removed based on a key extracted from each element. The key is obtained via the providedkeyExtractorfunction. When duplicates are found, the **last occurrence** of each element for a given key is retained.- Specified by:
distinctByKeepLastin interfaceIndexedSeq<java.lang.Character>- Specified by:
distinctByKeepLastin interfaceSeq<java.lang.Character>- Type Parameters:
U- the type of the key used for determining uniqueness- Parameters:
keyExtractor- a function extracting a key from each element for uniqueness comparison- Returns:
- a new sequence of elements distinct by the extracted key, keeping the last occurrence
-
drop
public CharSeq drop(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropin interfaceIndexedSeq<java.lang.Character>- Specified by:
dropin interfaceSeq<java.lang.Character>- Specified by:
dropin interfaceTraversable<java.lang.Character>- Parameters:
n- the number of elements to drop- Returns:
- a new instance excluding the first
nelements
-
dropUntil
public CharSeq dropUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.- Specified by:
dropUntilin interfaceIndexedSeq<java.lang.Character>- Specified by:
dropUntilin interfaceSeq<java.lang.Character>- Specified by:
dropUntilin interfaceTraversable<java.lang.Character>- Parameters:
predicate- a condition tested on each element- Returns:
- a new instance starting from the first element matching the predicate
-
dropWhile
public CharSeq dropWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.This is equivalent to
dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.- Specified by:
dropWhilein interfaceIndexedSeq<java.lang.Character>- Specified by:
dropWhilein interfaceSeq<java.lang.Character>- Specified by:
dropWhilein interfaceTraversable<java.lang.Character>- Parameters:
predicate- a condition tested on each element- Returns:
- a new instance starting from the first element not matching the predicate
-
dropRight
public CharSeq dropRight(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropRightin interfaceIndexedSeq<java.lang.Character>- Specified by:
dropRightin interfaceSeq<java.lang.Character>- Specified by:
dropRightin interfaceTraversable<java.lang.Character>- Parameters:
n- the number of elements to drop from the end- Returns:
- a new instance excluding the last
nelements
-
dropRightWhile
public CharSeq dropRightWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:SeqDrops elements from the end of the sequence while the given predicate holds.This is equivalent to
dropRightUntil(predicate.negate()). Useful when using method references that cannot be negated directly.- Specified by:
dropRightWhilein interfaceIndexedSeq<java.lang.Character>- Specified by:
dropRightWhilein interfaceSeq<java.lang.Character>- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements up to and including the last element that does not satisfy the predicate
-
dropRightUntil
public CharSeq dropRightUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:SeqDrops elements from the end of the sequence until an element satisfies the given predicate. The returned sequence includes the last element that satisfies the predicate.- Specified by:
dropRightUntilin interfaceIndexedSeq<java.lang.Character>- Specified by:
dropRightUntilin interfaceSeq<java.lang.Character>- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements up to and including the last element that satisfies the predicate
-
filter
public CharSeq filter(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.- Specified by:
filterin interfaceIndexedSeq<java.lang.Character>- Specified by:
filterin interfaceSeq<java.lang.Character>- Specified by:
filterin interfaceTraversable<java.lang.Character>- Parameters:
predicate- the condition to test elements- Returns:
- a traversable with elements matching the predicate
-
reject
public CharSeq reject(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that do not satisfy the given predicate.This is equivalent to
filter(predicate.negate()).- Specified by:
rejectin interfaceIndexedSeq<java.lang.Character>- Specified by:
rejectin interfaceSeq<java.lang.Character>- Specified by:
rejectin interfaceTraversable<java.lang.Character>- Parameters:
predicate- the condition to test elements- Returns:
- a traversable with elements not matching the predicate
-
flatMap
public <U> IndexedSeq<U> flatMap(@NonNull java.util.function.Function<? super java.lang.Character,? extends java.lang.Iterable<? extends U>> mapper)
Description copied from interface:TraversableTransforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.- Specified by:
flatMapin interfaceIndexedSeq<java.lang.Character>- Specified by:
flatMapin interfaceSeq<java.lang.Character>- Specified by:
flatMapin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of elements in the resulting Traversable- Parameters:
mapper- a function mapping elements to iterables- Returns:
- a new Traversable containing all elements produced by applying
mapperand flattening
-
flatMapChars
public CharSeq flatMapChars(@NonNull CharSeq.CharFunction<? extends java.lang.CharSequence> mapper)
FlatMaps thisCharSeqto a newCharSeqby applying aCharFunctionto each character, which returns aCharSequence, and concatenating the results.This is a specialized version of
flatMap(Function)for primitive characters that returns aCharSeqinstead of anIndexedSeq<Character>.- Parameters:
mapper- A mapper that takes a char and returns a CharSequence- Returns:
- A new CharSeq containing the concatenated results
- Throws:
java.lang.NullPointerException- ifmapperis null
-
groupBy
public <C> Map<C,CharSeq> groupBy(@NonNull java.util.function.Function<? super java.lang.Character,? extends C> classifier)
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceIndexedSeq<java.lang.Character>- Specified by:
groupByin interfaceSeq<java.lang.Character>- Specified by:
groupByin interfaceTraversable<java.lang.Character>- Type Parameters:
C- The type of the group keys- Parameters:
classifier- A function that assigns each element to a group- Returns:
- A map where each key corresponds to a group of elements
- See Also:
Traversable.arrangeBy(Function)
-
grouped
public Iterator<CharSeq> grouped(int size)
Description copied from interface:TraversableSplits thisTraversableinto consecutive blocks of the given size.Let
lengthbe the number of elements in thisTraversable:- If empty, the resulting
Iteratoris empty. - If
size <= length, the resultingIteratorcontainslength / sizeblocks of sizesizeand possibly a final smaller block of sizelength % size. - If
size > length, the resultingIteratorcontains a single block of sizelength.
Examples:
[].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]]Note:
grouped(size)is equivalent tosliding(size, size).- Specified by:
groupedin interfaceIndexedSeq<java.lang.Character>- Specified by:
groupedin interfaceSeq<java.lang.Character>- Specified by:
groupedin interfaceTraversable<java.lang.Character>- Parameters:
size- the block size; must be positive- Returns:
- an
Iteratorover blocks of elements
- If empty, the resulting
-
hasDefiniteSize
public boolean hasDefiniteSize()
Description copied from interface:TraversableIndicates whether thisTraversablehas a known finite size.This should typically be implemented by concrete classes, not interfaces.
- Specified by:
hasDefiniteSizein interfaceTraversable<java.lang.Character>- Returns:
trueif the number of elements is finite and known,falseotherwise.
-
init
public CharSeq init()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail().- Specified by:
initin interfaceIndexedSeq<java.lang.Character>- Specified by:
initin interfaceSeq<java.lang.Character>- Specified by:
initin interfaceTraversable<java.lang.Character>- Returns:
- a new instance containing all elements except the last
-
initOption
public Option<CharSeq> initOption()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one, wrapped in anOption.This is the dual of
Traversable.tailOption().- Specified by:
initOptionin interfaceIndexedSeq<java.lang.Character>- Specified by:
initOptionin interfaceSeq<java.lang.Character>- Specified by:
initOptionin interfaceTraversable<java.lang.Character>- Returns:
Some(traversable)if non-empty, orNoneif this Traversable is empty
-
insert
public CharSeq insert(int index, java.lang.Character element)
Description copied from interface:SeqReturns a new sequence with the given element inserted at the specified index.- Specified by:
insertin interfaceIndexedSeq<java.lang.Character>- Specified by:
insertin interfaceSeq<java.lang.Character>- Parameters:
index- the position at which to insert the elementelement- the element to insert- Returns:
- a new
Seqwith the element inserted
-
insertAll
public CharSeq insertAll(int index, @NonNull java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:SeqReturns a new sequence with the given elements inserted at the specified index.- Specified by:
insertAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
insertAllin interfaceSeq<java.lang.Character>- Parameters:
index- the position at which to insert the elementselements- the elements to insert; must not benull- Returns:
- a new
Seqwith the elements inserted
-
iterator
public @NonNull Iterator<java.lang.Character> iterator()
Description copied from interface:TraversableReturns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail(). Subclasses may override for a more efficient implementation.- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Character>- Specified by:
iteratorin interfaceTraversable<java.lang.Character>- Specified by:
iteratorin interfaceValue<java.lang.Character>- Returns:
- a new
Iteratorover the elements of this Traversable
-
intersperse
public CharSeq intersperse(java.lang.Character element)
Description copied from interface:SeqReturns a new sequence where the given element is inserted between all elements of this sequence.- Specified by:
interspersein interfaceIndexedSeq<java.lang.Character>- Specified by:
interspersein interfaceSeq<java.lang.Character>- Parameters:
element- the element to intersperse- Returns:
- a new
Seqwith the element interspersed
-
map
public <U> IndexedSeq<U> map(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Description copied from interface:TraversableTransforms the elements of this Traversable to a new type, preserving order if defined.- Specified by:
mapin interfaceIndexedSeq<java.lang.Character>- Specified by:
mapin interfaceSeq<java.lang.Character>- Specified by:
mapin interfaceTraversable<java.lang.Character>- Specified by:
mapin interfaceValue<java.lang.Character>- Type Parameters:
U- the target element type- Parameters:
mapper- a mapping function- Returns:
- a new Traversable containing the mapped elements
-
mapTo
public <U> IndexedSeq<U> mapTo(U value)
Description copied from interface:ValueMaps the underlying value to another fixed value.- Specified by:
mapToin interfaceIndexedSeq<java.lang.Character>- Specified by:
mapToin interfaceSeq<java.lang.Character>- Specified by:
mapToin interfaceTraversable<java.lang.Character>- Specified by:
mapToin interfaceValue<java.lang.Character>- Type Parameters:
U- The new component type- Parameters:
value- value to replace the contents with- Returns:
- A new value
-
mapToVoid
public IndexedSeq<java.lang.Void> mapToVoid()
Description copied from interface:ValueMaps the underlying value to Void- Specified by:
mapToVoidin interfaceIndexedSeq<java.lang.Character>- Specified by:
mapToVoidin interfaceSeq<java.lang.Character>- Specified by:
mapToVoidin interfaceTraversable<java.lang.Character>- Specified by:
mapToVoidin interfaceValue<java.lang.Character>- Returns:
- A new value of type Void
-
mkString
public java.lang.String mkString()
Description copied from interface:TraversableConcatenates the string representations of all elements in this Traversable.Equivalent to
mkString("", "", "").- Specified by:
mkStringin interfaceTraversable<java.lang.Character>- Returns:
- a new
Stringcontaining all elements concatenated
-
padTo
public CharSeq padTo(int length, java.lang.Character element)
Description copied from interface:SeqReturns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.Note: Lazily-evaluated sequences may need to process all elements to determine the overall length.
- Specified by:
padToin interfaceIndexedSeq<java.lang.Character>- Specified by:
padToin interfaceSeq<java.lang.Character>- Parameters:
length- the target length of the resulting sequenceelement- the element to append as padding- Returns:
- a new
Seqconsisting of this sequence followed by the minimal number of occurrences ofelementto reach at leastlength
-
leftPadTo
public CharSeq leftPadTo(int length, java.lang.Character element)
Description copied from interface:SeqReturns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.Note: Lazily-evaluated sequences may need to process all elements to determine the overall length.
- Specified by:
leftPadToin interfaceSeq<java.lang.Character>- Parameters:
length- the target length of the resulting sequenceelement- the element to prepend as padding- Returns:
- a new
Seqconsisting of this sequence prepended by the minimal number of occurrences ofelementto reach at leastlength
-
orElse
public CharSeq orElse(java.lang.Iterable<? extends java.lang.Character> other)
Description copied from interface:TraversableReturns thisTraversableif it is non-empty; otherwise, returns the given alternative.- Specified by:
orElsein interfaceIndexedSeq<java.lang.Character>- Specified by:
orElsein interfaceSeq<java.lang.Character>- Specified by:
orElsein interfaceTraversable<java.lang.Character>- Parameters:
other- an alternativeTraversableto return if this is empty- Returns:
- this
Traversableif non-empty, otherwiseother
-
orElse
public CharSeq orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends java.lang.Character>> supplier)
Description copied from interface:TraversableReturns thisTraversableif it is non-empty; otherwise, returns the result of evaluating the given supplier.- Specified by:
orElsein interfaceIndexedSeq<java.lang.Character>- Specified by:
orElsein interfaceSeq<java.lang.Character>- Specified by:
orElsein interfaceTraversable<java.lang.Character>- Parameters:
supplier- a supplier of an alternativeTraversableif this is empty- Returns:
- this
Traversableif non-empty, otherwise the result ofsupplier.get()
-
padding
private static java.lang.StringBuilder padding(char element, int limit)
-
patch
public CharSeq patch(int from, @NonNull java.lang.Iterable<? extends java.lang.Character> that, int replaced)
Description copied from interface:SeqReturns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.- Specified by:
patchin interfaceIndexedSeq<java.lang.Character>- Specified by:
patchin interfaceSeq<java.lang.Character>- Parameters:
from- the starting index of the slice to be replacedthat- the sequence of elements to insert; must not benullreplaced- the number of elements to remove from this sequence starting atfrom- Returns:
- a new
Seqwith the specified slice replaced
-
mapChars
public CharSeq mapChars(CharSeq.CharUnaryOperator mapper)
Maps thisCharSeqto a newCharSeqby applying aCharUnaryOperatorto each character.This is a specialized version of
map(Function)for primitive characters that returns aCharSeqinstead of anIndexedSeq<Character>.- Parameters:
mapper- A mapper that takes a char and returns a char- Returns:
- A new CharSeq containing the mapped characters
- Throws:
java.lang.NullPointerException- ifmapperis null
-
partition
public Tuple2<CharSeq,CharSeq> partition(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableSplits thisTraversableinto two partitions according to a predicate.The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.
- Specified by:
partitionin interfaceIndexedSeq<java.lang.Character>- Specified by:
partitionin interfaceSeq<java.lang.Character>- Specified by:
partitionin interfaceTraversable<java.lang.Character>- Parameters:
predicate- a predicate used to classify elements- Returns:
- a
Tuple2containing the two resultingTraversableinstances
-
peek
public CharSeq peek(@NonNull java.util.function.Consumer<? super java.lang.Character> action)
Description copied from interface:ValuePerforms the givenactionon the first element if this is an eager implementation. Performs the givenactionon all elements (the first immediately, successive deferred), if this is a lazy implementation.- Specified by:
peekin interfaceIndexedSeq<java.lang.Character>- Specified by:
peekin interfaceSeq<java.lang.Character>- Specified by:
peekin interfaceTraversable<java.lang.Character>- Specified by:
peekin 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:SeqReturns all unique permutations of this sequence.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:
permutationsin interfaceIndexedSeq<java.lang.Character>- Specified by:
permutationsin interfaceSeq<java.lang.Character>- Returns:
- a sequence of all unique permutations of this sequence
-
prepend
public CharSeq prepend(java.lang.Character element)
Description copied from interface:SeqReturns a new sequence with the given element prepended to this sequence.- Specified by:
prependin interfaceIndexedSeq<java.lang.Character>- Specified by:
prependin interfaceSeq<java.lang.Character>- Parameters:
element- the element to prepend- Returns:
- a new
Seqwith the element added at the front
-
prependAll
public CharSeq prependAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:SeqReturns a new sequence with all given elements prepended to this sequence.- Specified by:
prependAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
prependAllin interfaceSeq<java.lang.Character>- Parameters:
elements- the elements to prepend; must not benull- Returns:
- a new
Seqwith the elements added at the front
-
remove
public CharSeq remove(java.lang.Character element)
Description copied from interface:SeqReturns a new sequence with the first occurrence of the given element removed.- Specified by:
removein interfaceIndexedSeq<java.lang.Character>- Specified by:
removein interfaceSeq<java.lang.Character>- Parameters:
element- the element to remove- Returns:
- a new
Seqwithout the first occurrence of the element
-
removeFirst
public CharSeq removeFirst(@NonNull java.util.function.Predicate<java.lang.Character> predicate)
Description copied from interface:SeqReturns a new sequence with the first element that satisfies the given predicate removed.- Specified by:
removeFirstin interfaceIndexedSeq<java.lang.Character>- Specified by:
removeFirstin interfaceSeq<java.lang.Character>- Parameters:
predicate- the predicate used to identify the element to remove; must not benull- Returns:
- a new
Seqwithout the first matching element
-
removeLast
public CharSeq removeLast(@NonNull java.util.function.Predicate<java.lang.Character> predicate)
Description copied from interface:SeqReturns a new sequence with the last element that satisfies the given predicate removed.- Specified by:
removeLastin interfaceIndexedSeq<java.lang.Character>- Specified by:
removeLastin interfaceSeq<java.lang.Character>- Parameters:
predicate- the predicate used to identify the element to remove; must not benull- Returns:
- a new
Seqwithout the last matching element
-
removeAt
public CharSeq removeAt(int index)
Description copied from interface:SeqReturns a new sequence with the element at the specified position removed. Subsequent elements are shifted to the left (indices decreased by one).- Specified by:
removeAtin interfaceIndexedSeq<java.lang.Character>- Specified by:
removeAtin interfaceSeq<java.lang.Character>- Parameters:
index- the position of the element to remove- Returns:
- a new
Seqwithout the element at the specified index
-
removeAll
public CharSeq removeAll(java.lang.Character element)
Description copied from interface:SeqReturns a new sequence with all occurrences of the given element removed.- Specified by:
removeAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
removeAllin interfaceSeq<java.lang.Character>- Parameters:
element- the element to remove- Returns:
- a new
Seqwithout any occurrences of the element
-
removeAll
public CharSeq removeAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:SeqReturns a new sequence with all occurrences of the given elements removed.- Specified by:
removeAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
removeAllin interfaceSeq<java.lang.Character>- Parameters:
elements- the elements to remove; must not benull- Returns:
- a new
Seqwithout any of the given elements
-
removeAll
@Deprecated public CharSeq removeAll(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Deprecated.Description copied from interface:SeqReturns a new Seq consisting of all elements which do not satisfy the given predicate.- Specified by:
removeAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
removeAllin 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:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.- Specified by:
replacein interfaceIndexedSeq<java.lang.Character>- Specified by:
replacein interfaceSeq<java.lang.Character>- Specified by:
replacein interfaceTraversable<java.lang.Character>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with the first occurrence of
currentElementreplaced bynewElement
-
replaceAll
public CharSeq replaceAll(java.lang.Character currentElement, java.lang.Character newElement)
Description copied from interface:TraversableReplaces all occurrences ofcurrentElementwithnewElement.- Specified by:
replaceAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
replaceAllin interfaceSeq<java.lang.Character>- Specified by:
replaceAllin interfaceTraversable<java.lang.Character>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with all occurrences of
currentElementreplaced bynewElement
-
retainAll
public CharSeq retainAll(@NonNull java.lang.Iterable<? extends java.lang.Character> elements)
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.- Specified by:
retainAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
retainAllin interfaceSeq<java.lang.Character>- Specified by:
retainAllin interfaceTraversable<java.lang.Character>- Parameters:
elements- the elements to keep- Returns:
- a new Traversable containing only the elements present in
elements, in their original order
-
reverse
public CharSeq reverse()
Description copied from interface:SeqReturns a new sequence with the order of elements reversed.- Specified by:
reversein interfaceIndexedSeq<java.lang.Character>- Specified by:
reversein interfaceSeq<java.lang.Character>- Returns:
- a new
Seqwith elements in reversed order
-
rotateLeft
public CharSeq rotateLeft(int n)
Description copied from interface:SeqReturns a new sequence with the elements circularly rotated to the left by the specified distance.Example:
// Result: List(3, 4, 5, 1, 2) List.of(1, 2, 3, 4, 5).rotateLeft(2);- Specified by:
rotateLeftin interfaceIndexedSeq<java.lang.Character>- Specified by:
rotateLeftin interfaceSeq<java.lang.Character>- Parameters:
n- the number of positions to rotate left- Returns:
- a new
Seqwith elements rotated left
-
rotateRight
public CharSeq rotateRight(int n)
Description copied from interface:SeqReturns a new sequence with the elements circularly rotated to the right by the specified distance.Example:
// Result: List(4, 5, 1, 2, 3) List.of(1, 2, 3, 4, 5).rotateRight(2);- Specified by:
rotateRightin interfaceIndexedSeq<java.lang.Character>- Specified by:
rotateRightin interfaceSeq<java.lang.Character>- Parameters:
n- the number of positions to rotate right- Returns:
- a new
Seqwith elements rotated right
-
scan
public CharSeq scan(java.lang.Character zero, @NonNull java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Character,? extends java.lang.Character> operation)
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.- Specified by:
scanin interfaceIndexedSeq<java.lang.Character>- Specified by:
scanin interfaceSeq<java.lang.Character>- Specified by:
scanin interfaceTraversable<java.lang.Character>- Parameters:
zero- the neutral element for the operatoroperation- an associative binary operator- Returns:
- a new Traversable containing the prefix scan of the elements
-
scanLeft
public <U> IndexedSeq<U> scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super java.lang.Character,? extends U> operation)
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from left to right.Will not terminate for infinite collections. The results may vary across runs unless the collection is ordered.
- Specified by:
scanLeftin interfaceIndexedSeq<java.lang.Character>- Specified by:
scanLeftin interfaceSeq<java.lang.Character>- Specified by:
scanLeftin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to the intermediate result and each element- Returns:
- a new Traversable containing the cumulative results
-
scanRight
public <U> IndexedSeq<U> scanRight(U zero, @NonNull java.util.function.BiFunction<? super java.lang.Character,? super U,? extends U> operation)
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from right to left.The head of the resulting collection is the last cumulative result. Will not terminate for infinite collections. Results may vary across runs unless the collection is ordered.
- Specified by:
scanRightin interfaceIndexedSeq<java.lang.Character>- Specified by:
scanRightin interfaceSeq<java.lang.Character>- Specified by:
scanRightin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to each element and the intermediate result- Returns:
- a new Traversable containing the cumulative results
-
shuffle
public CharSeq shuffle()
Description copied from interface:SeqReturns a new sequence with the elements randomly shuffled.- Specified by:
shufflein interfaceIndexedSeq<java.lang.Character>- Specified by:
shufflein interfaceSeq<java.lang.Character>- Returns:
- a new
Seqcontaining the same elements in a random order
-
slice
public CharSeq slice(int beginIndex, int endIndex)
Description copied from interface:SeqReturns a subsequence (slice) of this sequence, starting atbeginIndex(inclusive) and ending atendIndex(exclusive).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)See also
Seq.subSequence(int, int), which may throw an exception instead of returning a sequence in some cases.- Specified by:
slicein interfaceIndexedSeq<java.lang.Character>- Specified by:
slicein interfaceSeq<java.lang.Character>- Parameters:
beginIndex- the starting index (inclusive)endIndex- the ending index (exclusive)- Returns:
- a new
Seqrepresenting the specified slice
-
slideBy
public Iterator<CharSeq> slideBy(@NonNull java.util.function.Function<? super java.lang.Character,?> classifier)
Description copied from interface:TraversablePartitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Each window contains elements with the same class, as determined by
classifier. Two consecutive elements belong to the same window only ifclassifierreturns equal values for both. Otherwise, the current window ends and a new window begins with the next element.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:
slideByin interfaceIndexedSeq<java.lang.Character>- Specified by:
slideByin interfaceSeq<java.lang.Character>- Specified by:
slideByin interfaceTraversable<java.lang.Character>- Parameters:
classifier- A function classifying elements into groups- Returns:
- An
Iteratorof windows (grouped elements)
-
sliding
public Iterator<CharSeq> sliding(int size)
Description copied from interface:TraversableSlides a window of a givensizeover thisTraversablewith a step size of 1.This is equivalent to calling
Traversable.sliding(int, int)with a step size of 1.- Specified by:
slidingin interfaceIndexedSeq<java.lang.Character>- Specified by:
slidingin interfaceSeq<java.lang.Character>- Specified by:
slidingin interfaceTraversable<java.lang.Character>- Parameters:
size- a positive window size- Returns:
- An
Iteratorof windows, each containing up tosizeelements
-
sliding
public Iterator<CharSeq> sliding(int size, int step)
Description copied from interface:TraversableSlides a window of a specificsizewith a givenstepover 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:
slidingin interfaceIndexedSeq<java.lang.Character>- Specified by:
slidingin interfaceSeq<java.lang.Character>- Specified by:
slidingin interfaceTraversable<java.lang.Character>- Parameters:
size- a positive window sizestep- a positive step size- Returns:
- an
Iteratorof windows with the given size and step
-
sorted
public CharSeq sorted()
Description copied from interface:SeqReturns a new sequence with elements sorted according to their natural order.- Specified by:
sortedin interfaceIndexedSeq<java.lang.Character>- Specified by:
sortedin interfaceSeq<java.lang.Character>- Returns:
- a new
Seqwith elements in natural order
-
sorted
public CharSeq sorted(@NonNull java.util.Comparator<? super java.lang.Character> comparator)
Description copied from interface:SeqReturns a new sequence with elements sorted according to the givenComparator.- Specified by:
sortedin interfaceIndexedSeq<java.lang.Character>- Specified by:
sortedin interfaceSeq<java.lang.Character>- Parameters:
comparator- the comparator used to order elements; must not benull- Returns:
- a new
Seqwith elements sorted according to the comparator
-
sortBy
public <U extends java.lang.Comparable<? super U>> CharSeq sortBy(@NonNull java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Description copied from interface:SeqReturns a new sequence sorted by comparing elements in a different domain defined by the givenmapper.- Specified by:
sortByin interfaceIndexedSeq<java.lang.Character>- Specified by:
sortByin interfaceSeq<java.lang.Character>- Type Parameters:
U- the type used for comparison- Parameters:
mapper- a function mapping elements to aComparabledomain; must not benull- Returns:
- a new
Seqsorted according to the mapped values
-
sortBy
public <U> CharSeq sortBy(@NonNull java.util.Comparator<? super U> comparator, java.util.function.Function<? super java.lang.Character,? extends U> mapper)
Description copied from interface:SeqReturns a new sequence sorted by comparing elements in a different domain defined by the givenmapper, using the providedcomparator.- Specified by:
sortByin interfaceIndexedSeq<java.lang.Character>- Specified by:
sortByin interfaceSeq<java.lang.Character>- Type Parameters:
U- the type used for comparison- Parameters:
comparator- the comparator used to compare mapped values; must not benullmapper- a function mapping elements to the domain for comparison; must not benull- Returns:
- a new
Seqsorted according to the mapped values and comparator
-
span
public Tuple2<CharSeq,CharSeq> span(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableSplits thisTraversableinto a prefix and remainder according to the givenpredicate.The first element of the returned
Tupleis the longest prefix of elements satisfyingpredicate, and the second element is the remaining elements.- Specified by:
spanin interfaceIndexedSeq<java.lang.Character>- Specified by:
spanin interfaceSeq<java.lang.Character>- Specified by:
spanin interfaceTraversable<java.lang.Character>- Parameters:
predicate- a predicate used to determine the prefix- Returns:
- a
Tuplecontaining the prefix and remainder
-
subSequence
public CharSeq subSequence(int beginIndex)
Description copied from interface:SeqReturns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndexand extending to the end of this sequence.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 IndexOutOfBoundsExceptionSee also
Seq.drop(int), which provides similar functionality but does not throw an exception for out-of-bounds indices.- Specified by:
subSequencein interfaceIndexedSeq<java.lang.Character>- Specified by:
subSequencein interfaceSeq<java.lang.Character>- Parameters:
beginIndex- the starting index (inclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndexto the end
-
tail
public CharSeq tail()
Description copied from interface:TraversableReturns a newTraversablewithout its first element.- Specified by:
tailin interfaceIndexedSeq<java.lang.Character>- Specified by:
tailin interfaceSeq<java.lang.Character>- Specified by:
tailin interfaceTraversable<java.lang.Character>- Returns:
- a new
Traversablecontaining all elements except the first
-
tailOption
public Option<CharSeq> tailOption()
Description copied from interface:TraversableReturns a newTraversablewithout its first element as anOption.- Specified by:
tailOptionin interfaceIndexedSeq<java.lang.Character>- Specified by:
tailOptionin interfaceSeq<java.lang.Character>- Specified by:
tailOptionin interfaceTraversable<java.lang.Character>- Returns:
Some(traversable)if non-empty, otherwiseNone
-
take
public CharSeq take(int n)
Description copied from interface:TraversableReturns the firstnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(0, max(0, min(length(), n))), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takein interfaceIndexedSeq<java.lang.Character>- Specified by:
takein interfaceSeq<java.lang.Character>- Specified by:
takein interfaceTraversable<java.lang.Character>- Parameters:
n- the number of elements to take- Returns:
- a new
Traversablecontaining the firstnelements
-
takeUntil
public CharSeq takeUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableTakes elements from thisTraversableuntil the given predicate holds for an element.Equivalent to
takeWhile(predicate.negate()), but useful when using method references that cannot be negated directly.- Specified by:
takeUntilin interfaceIndexedSeq<java.lang.Character>- Specified by:
takeUntilin interfaceSeq<java.lang.Character>- Specified by:
takeUntilin interfaceTraversable<java.lang.Character>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements before the first one that satisfies the predicate
-
takeWhile
public CharSeq takeWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:TraversableTakes elements from thisTraversablewhile the given predicate holds.- Specified by:
takeWhilein interfaceIndexedSeq<java.lang.Character>- Specified by:
takeWhilein interfaceSeq<java.lang.Character>- Specified by:
takeWhilein interfaceTraversable<java.lang.Character>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements up to (but not including) the first one that does not satisfy the predicate
-
takeRight
public CharSeq takeRight(int n)
Description copied from interface:TraversableReturns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(max(0, length() - n), length()), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takeRightin interfaceIndexedSeq<java.lang.Character>- Specified by:
takeRightin interfaceSeq<java.lang.Character>- Specified by:
takeRightin interfaceTraversable<java.lang.Character>- Parameters:
n- the number of elements to take from the end- Returns:
- a new
Traversablecontaining the lastnelements
-
takeRightUntil
public CharSeq takeRightUntil(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:SeqTakes elements from the end of the sequence until an element satisfies the given predicate. The returned sequence starts after the last element that satisfies the predicate.- Specified by:
takeRightUntilin interfaceIndexedSeq<java.lang.Character>- Specified by:
takeRightUntilin interfaceSeq<java.lang.Character>- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements after the last element that satisfies the predicate
-
takeRightWhile
public CharSeq takeRightWhile(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:SeqTakes elements from the end of the sequence while the given predicate holds.This is an equivalent to
takeRightUntil(predicate.negate()). Useful when using method references that cannot be negated directly.- Specified by:
takeRightWhilein interfaceIndexedSeq<java.lang.Character>- Specified by:
takeRightWhilein interfaceSeq<java.lang.Character>- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements after the last element that does not satisfy the 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- iffis null
-
unzip
public <T1,T2> Tuple2<IndexedSeq<T1>,IndexedSeq<T2>> unzip(@NonNull java.util.function.Function<? super java.lang.Character,Tuple2<? extends T1,? extends T2>> unzipper)
Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.- Specified by:
unzipin interfaceIndexedSeq<java.lang.Character>- Specified by:
unzipin interfaceSeq<java.lang.Character>- Specified by:
unzipin interfaceTraversable<java.lang.Character>- Type Parameters:
T1- type of the first element in the resulting pairsT2- type of the second element in the resulting pairs- Parameters:
unzipper- a function that maps elements of thisTraversableto pairs- Returns:
- a
Tuple2containing twoTraversablecollections with the split elements
-
unzip3
public <T1,T2,T3> Tuple3<IndexedSeq<T1>,IndexedSeq<T2>,IndexedSeq<T3>> unzip3(@NonNull java.util.function.Function<? super java.lang.Character,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.- Specified by:
unzip3in interfaceIndexedSeq<java.lang.Character>- Specified by:
unzip3in interfaceSeq<java.lang.Character>- Specified by:
unzip3in interfaceTraversable<java.lang.Character>- Type Parameters:
T1- type of the first element in the resulting triplesT2- type of the second element in the resulting triplesT3- type of the third element in the resulting triples- Parameters:
unzipper- a function that maps elements of thisTraversableto triples- Returns:
- a
Tuple3containing threeTraversablecollections with the split elements
-
update
public CharSeq update(int index, java.lang.Character element)
Description copied from interface:SeqReturns a newSeqwith the element at the specified index replaced by the given value.- Specified by:
updatein interfaceIndexedSeq<java.lang.Character>- Specified by:
updatein interfaceSeq<java.lang.Character>- Parameters:
index- the index of the element to updateelement- the new element to set at the specified index- Returns:
- a new
Seqwith the updated element
-
update
public CharSeq update(int index, @NonNull java.util.function.Function<? super java.lang.Character,? extends java.lang.Character> updater)
Description copied from interface:SeqReturns a newSeqwith the element at the specified index updated using the given function.- Specified by:
updatein interfaceIndexedSeq<java.lang.Character>- Specified by:
updatein interfaceSeq<java.lang.Character>- Parameters:
index- the index of the element to updateupdater- a function that computes the new element from the existing element- Returns:
- a new
Seqwith the element atindextransformed byupdater
-
zip
public <U> IndexedSeq<Tuple2<java.lang.Character,U>> zip(@NonNull java.lang.Iterable<? extends U> that)
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable. Pairing stops when either collection runs out of elements; any remaining elements in the longer collection are ignored.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipin interfaceIndexedSeq<java.lang.Character>- Specified by:
zipin interfaceSeq<java.lang.Character>- Specified by:
zipin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pair- Returns:
- a new
Traversablecontaining pairs of corresponding elements
-
zipWith
public <U,R> IndexedSeq<R> zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super java.lang.Character,? super U,? extends R> mapper)
Description copied from interface:TraversableReturns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function. Pairing stops when either collection runs out of elements.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipWithin interfaceIndexedSeq<java.lang.Character>- Specified by:
zipWithin interfaceSeq<java.lang.Character>- Specified by:
zipWithin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of elements in the second parameter of the mapperR- the type of elements in the resultingTraversable- Parameters:
that- anIterableproviding the second parameter of the mappermapper- a function that combines elements from this andthatinto a new element- Returns:
- a new
Traversablecontaining mapped elements
-
zipAll
public <U> IndexedSeq<Tuple2<java.lang.Character,U>> zipAll(@NonNull java.lang.Iterable<? extends U> that, java.lang.Character thisElem, U thatElem)
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.The length of the resulting
Traversableis the maximum of the lengths of thisTraversableandthat.If this
Traversableis shorter thanthat,thisElemis used as a filler. Conversely, ifthatis shorter,thatElemis used.- Specified by:
zipAllin interfaceIndexedSeq<java.lang.Character>- Specified by:
zipAllin interfaceSeq<java.lang.Character>- Specified by:
zipAllin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pairthisElem- the element used to fill missing values if thisTraversableis shorter thanthatthatElem- the element used to fill missing values ifthatis shorter than thisTraversable- Returns:
- a new
Traversablecontaining pairs of elements, including fillers as needed
-
zipWithIndex
public IndexedSeq<Tuple2<java.lang.Character,java.lang.Integer>> zipWithIndex()
Description copied from interface:TraversableZips thisTraversablewith its indices, starting at 0.- Specified by:
zipWithIndexin interfaceIndexedSeq<java.lang.Character>- Specified by:
zipWithIndexin interfaceSeq<java.lang.Character>- Specified by:
zipWithIndexin interfaceTraversable<java.lang.Character>- Returns:
- a new
Traversablecontaining each element paired with its index
-
zipWithIndex
public <U> IndexedSeq<U> zipWithIndex(@NonNull java.util.function.BiFunction<? super java.lang.Character,? super java.lang.Integer,? extends U> mapper)
Description copied from interface:TraversableZips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.- Specified by:
zipWithIndexin interfaceIndexedSeq<java.lang.Character>- Specified by:
zipWithIndexin interfaceSeq<java.lang.Character>- Specified by:
zipWithIndexin interfaceTraversable<java.lang.Character>- Type Parameters:
U- the type of elements in the resultingTraversable- Parameters:
mapper- a function mapping an element and its index to a new element- Returns:
- a new
Traversablecontaining the mapped elements
-
get
public java.lang.Character get(int index)
Description copied from interface:SeqReturns the element at the specified index.
-
indexOf
public int indexOf(java.lang.Character element, int from)Description copied from interface:SeqReturns the index of the first occurrence of the given element, starting at the specified index, or-1if this sequence does not contain the element.
-
lastIndexOf
public int lastIndexOf(java.lang.Character element, int end)Description copied from interface:SeqReturns the index of the last occurrence of the given element at or before the specified end index, or-1if this sequence does not contain the element.- Specified by:
lastIndexOfin interfaceSeq<java.lang.Character>- Parameters:
element- the element to search forend- the maximum index to consider- Returns:
- the index of the last occurrence at or before
end, or-1if not found
-
splitAt
public Tuple2<CharSeq,CharSeq> splitAt(int n)
Description copied from interface:SeqSplits this sequence at the specified index.The result of
splitAt(n)is equivalent toTuple.of(take(n), drop(n)).
-
splitAt
public Tuple2<CharSeq,CharSeq> splitAt(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:SeqSplits this sequence at the first element satisfying the given predicate.
-
splitAtInclusive
public Tuple2<CharSeq,CharSeq> splitAtInclusive(@NonNull java.util.function.Predicate<? super java.lang.Character> predicate)
Description copied from interface:SeqSplits this sequence at the first element satisfying the given predicate, including the element in the first part.- Specified by:
splitAtInclusivein interfaceSeq<java.lang.Character>- Parameters:
predicate- the predicate used to determine the split point; must not benull- Returns:
- a
Tuple2containing the sequence up to and including the first matching element and the remaining sequence
-
startsWith
public boolean startsWith(@NonNull java.lang.Iterable<? extends java.lang.Character> that, int offset)Description copied from interface:SeqTests whether this sequence contains the given sequence starting at the specified index.Note: If both this sequence and the argument sequence are infinite, this method may not terminate.
- Specified by:
startsWithin interfaceIndexedSeq<java.lang.Character>- Specified by:
startsWithin interfaceSeq<java.lang.Character>- Parameters:
that- the sequence to test; must not benulloffset- the index at which to start checking for the prefix- Returns:
trueifthatis empty or matches a subsequence of this sequence starting atoffset,falseotherwise
-
head
public java.lang.Character head()
Description copied from interface:TraversableReturns the first element of this non-emptyTraversable.- Specified by:
headin interfaceTraversable<java.lang.Character>- Returns:
- the first element
-
isAsync
public boolean isAsync()
ACharSeqis computed synchronously.
-
isEmpty
public boolean isEmpty()
Description copied from interface:TraversableChecks if this Traversable contains no elements.- Specified by:
isEmptyin interfaceTraversable<java.lang.Character>- Specified by:
isEmptyin interfaceValue<java.lang.Character>- Returns:
trueif empty,falseotherwise
-
isLazy
public boolean isLazy()
ACharSeqis computed eagerly.
-
isTraversableAgain
public boolean isTraversableAgain()
Description copied from interface:TraversableChecks if this Traversable can be traversed multiple times without side effects.Implementations should provide the correct behavior; this is not meant for interfaces alone.
- Specified by:
isTraversableAgainin interfaceTraversable<java.lang.Character>- Returns:
trueif this Traversable is guaranteed to be repeatably traversable,falseotherwise
-
readResolve
private java.lang.Object readResolve()
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- They are of the same collection type (Seq, Set, Map, Multimap)
- They contain the same elements
- For
Seq, the element order is the same
For
MapandMultimap, two entries(key1, value1)and(key2, value2)are equal if both their keys and values are equal.Additional notes:
- No collection equals
null(e.g.,Queue(1) != null) - Null elements are allowed and treated as expected
(e.g.,
List(null, 1) == Stream(null, 1),HashMap((null,1)) == LinkedHashMap((null,1))) - Element order matters only for
Seq - Other collection classes are equal if their types and elements (in iteration order) are equal
- Iterators are compared by reference only
- Specified by:
equalsin interfaceTraversable<java.lang.Character>- Specified by:
equalsin interfaceValue<java.lang.Character>- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to compare with, may benull- Returns:
trueif the collections are equal according to the rules above,falseotherwise
-
hashCode
public int hashCode()
Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.For collections with predictable iteration order, the hash is computed as:
int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }For collections with arbitrary iteration order, the hash is computed to be independent of element order:
int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as
HashMapkeys), caching can be done externally using a wrapper, for example:{@code public final class Hashed{ private final K key; private final Lazy hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; } - Specified by:
hashCodein interfaceTraversable<java.lang.Character>- Specified by:
hashCodein interfaceValue<java.lang.Character>- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code of this collection
-
charAt
public char charAt(int index)
Returns thecharvalue at the specified index. An index ranges from0tolength() - 1. The firstcharvalue of the sequence is at index0, the next at index1, and so on, as for array indexing.If the
charvalue specified by the index is a surrogate, the surrogate value is returned.- Specified by:
charAtin interfacejava.lang.CharSequence- Parameters:
index- the index of thecharvalue.- Returns:
- the
charvalue at the specified index of this string. The firstcharvalue is at index0. - Throws:
java.lang.IndexOutOfBoundsException- if theindexargument 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:
lengthin interfacejava.lang.CharSequence- Specified by:
lengthin 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 tocharvalues (Unicode code units) and ranges from0tolength()- 1.If the
charvalue specified at the given index is in the high-surrogate range, the following index is less than the length of thisCharSeq, and thecharvalue at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, thecharvalue at the given index is returned.- Parameters:
index- the index to thecharvalues- Returns:
- the code point value of the character at the
index - Throws:
java.lang.IndexOutOfBoundsException- if theindexargument 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 tocharvalues (Unicode code units) and ranges from1tolength.If the
charvalue at(index - 1)is in the low-surrogate range,(index - 2)is not negative, and thecharvalue at(index - 2)is in the high-surrogate range, then the supplementary code point value of the surrogate pair is returned. If thecharvalue atindex - 1is 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 theindexargument 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 specifiedbeginIndexand extends to thecharat indexendIndex - 1. Thus the length (inchars) of the text range isendIndex-beginIndex. Unpaired surrogates within the text range count as one code point each.- Parameters:
beginIndex- the index to the firstcharof the text range.endIndex- the index after the lastcharof the text range.- Returns:
- the number of Unicode code points in the specified text range
- Throws:
java.lang.IndexOutOfBoundsException- if thebeginIndexis negative, orendIndexis larger than the length of thisCharSeq, orbeginIndexis larger thanendIndex.
-
offsetByCodePoints
public int offsetByCodePoints(int index, int codePointOffset)Returns the index within thisCharSeqthat is offset from the givenindexbycodePointOffsetcode points. Unpaired surrogates within the text range given byindexandcodePointOffsetcount 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- ifindexis negative or larger then the length of thisCharSeq, or ifcodePointOffsetis positive and the substring starting withindexhas fewer thancodePointOffsetcode points, or ifcodePointOffsetis negative and the substring beforeindexhas fewer than the absolute value ofcodePointOffsetcode 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 ofdststarting at indexdstBeginand 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:srcBeginis negative.srcBeginis greater thansrcEndsrcEndis greater than the length of this stringdstBeginis negativedstBegin+(srcEnd-srcBegin)is larger thandst.length
-
getBytes
public byte[] getBytes(java.lang.String charsetName) throws java.io.UnsupportedEncodingExceptionEncodes thisCharSeqinto 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
CharsetEncoderclass 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 thisCharSeqinto 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
CharsetEncoderclass 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 thisCharSeqinto 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
CharsetEncoderclass 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 istrueif and only if thisCharSeqrepresents the same sequence of characters as the specifiedStringBuffer. This method synchronizes on theStringBuffer.- Parameters:
sb- TheStringBufferto compare thisCharSeqagainst- Returns:
trueif thisCharSeqrepresents the same sequence of characters as the specifiedStringBuffer,falseotherwise
-
contentEquals
public boolean contentEquals(java.lang.CharSequence cs)
Compares this string to the specifiedCharSequence. The result istrueif and only if thisCharSeqrepresents the same sequence of char values as the specified sequence. Note that if theCharSequenceis aStringBufferthen the method synchronizes on it.- Parameters:
cs- The sequence to compare thisCharSeqagainst- Returns:
trueif thisCharSeqrepresents the same sequence of char values as the specified sequence,falseotherwise
-
equalsIgnoreCase
public boolean equalsIgnoreCase(CharSeq anotherString)
Compares thisCharSeqto 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
c1andc2are 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- TheCharSeqto compare thisCharSeqagainst- Returns:
trueif the argument is notnulland it represents an equivalentCharSeqignoring case;falseotherwise- 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 thisCharSeqobject is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if thisCharSeqobject lexicographically precedes the argument string. The result is a positive integer if thisCharSeqobject lexicographically follows the argument string. The result is zero if the strings are equal;compareToreturns0exactly 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,compareToreturns the difference of the two character values at positionkin 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)
compareToreturns the difference of the lengths of the strings -- that is, the value:this.length()-anotherString.length()
- Specified by:
compareToin interfacejava.lang.Comparable<CharSeq>- Parameters:
anotherString- theCharSeqto be compared.- Returns:
- the value
0if the argument string is equal to this string; a value less than0if this string is lexicographically less than the string argument; and a value greater than0if 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 callingcompareTowith 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- theCharSeqto 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
CharSeqobject is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of thisCharSeqobject to be compared begins at indextoffsetand has lengthlen. The substring of other to be compared begins at indexooffsetand has lengthlen. The result isfalseif and only if at least one of the following is true:toffsetis negative.ooffsetis negative.toffset+lenis greater than the length of thisCharSeqobject.ooffset+lenis greater than the length of the other argument.- There is some nonnegative integer k less than
lensuch 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:
trueif the specified subregion of this string exactly matches the specified subregion of the string argument;falseotherwise.
-
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
CharSeqobject is compared to a substring of the argumentother. The result istrueif these substrings represent character sequences that are the same, ignoring case if and only ifignoreCaseis true. The substring of thisCharSeqobject to be compared begins at indextoffsetand has lengthlen. The substring ofotherto be compared begins at indexooffsetand has lengthlen. The result isfalseif and only if at least one of the following is true:toffsetis negative.ooffsetis negative.toffset+lenis greater than the length of thisCharSeqobject.ooffset+lenis greater than the length of the other argument.ignoreCaseisfalseand there is some nonnegative integer k less thanlensuch that:this.charAt(toffset+k) != other.charAt(ooffset+k)
ignoreCaseistrueand there is some nonnegative integer k less thanlensuch 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:
trueif the specified subregion of this string matches the specified subregion of the string argument;falseotherwise. Whether the matching is exact or case insensitive depends on theignoreCaseargument.
-
subSequence
public CharSeq subSequence(int beginIndex, int endIndex)
Description copied from interface:SeqReturns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndex(inclusive) and ending atendIndex(exclusive).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 IndexOutOfBoundsExceptionSee also
Seq.slice(int, int), which returns an empty sequence instead of throwing exceptions when indices are out of range.- Specified by:
subSequencein interfacejava.lang.CharSequence- Specified by:
subSequencein interfaceIndexedSeq<java.lang.Character>- Specified by:
subSequencein interfaceSeq<java.lang.Character>- Parameters:
beginIndex- the starting index (inclusive) of the subsequenceendIndex- the ending index (exclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndextoendIndex - 1
-
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:
trueif the character sequence represented by the argument is a prefix of the substring of this object starting at indextoffset;falseotherwise. The result isfalseiftoffsetis negative or greater than the length of thisCharSeqobject; 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:
trueif the character sequence represented by the argument is a prefix of the character sequence represented by this string;falseotherwise. Note also thattruewill be returned if the argument is an empty string or is equal to thisCharSeqobject 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:
trueif the character sequence represented by the argument is a suffix of the character sequence represented by this object;falseotherwise. Note that the result will betrueif the argument is the empty string or is equal to thisCharSeqobject 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 valuechoccurs in the character sequence represented by thisCharSeqobject, then the index (in Unicode code units) of the first such occurrence is returned. For values ofchin 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
-1is 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
-1if the character does not occur.
-
indexOfOption
Option<java.lang.Integer> indexOfOption(int ch)
Returns the index of the first occurrence of the given element as anOption.- Parameters:
ch- a character (Unicode code point).- Returns:
Some(index)orNoneif not found.
-
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
choccurs in the character sequence represented by thisCharSeqobject at an index no smaller thanfromIndex, then the index of the first such occurrence is returned. For values ofchin 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-1is 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:-1is returned.All indices are specified in
charvalues (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-1if the character does not occur.
-
indexOfOption
Option<java.lang.Integer> indexOfOption(int ch, int fromIndex)
Returns the index of the first 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)orNoneif not found.
-
lastIndexOf
public int lastIndexOf(int ch)
Returns the index within this string of the last occurrence of the specified character. For values ofchin 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
-1is returned. TheCharSeqis 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
-1if the character does not occur.
-
lastIndexOfOption
Option<java.lang.Integer> lastIndexOfOption(int ch)
Returns the index of the last occurrence of the given element as anOption.- Parameters:
ch- a character (Unicode code point).- Returns:
Some(index)orNoneif not found.
-
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 ofchin 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-1is returned.All indices are specified in
charvalues (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-1if 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)orNoneif 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)
-1is returned.- Parameters:
str- the substring to search for.- Returns:
- the index of the first occurrence of the specified substring,
or
-1if 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)orNoneif 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)-1is 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
-1if 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)orNoneif 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)
-1is returned.- Parameters:
str- the substring to search for.- Returns:
- the index of the last occurrence of the specified substring,
or
-1if 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)orNoneif 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)-1is 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
-1if 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)orNoneif 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- ifbeginIndexis negative or larger than the length of thisCharSeqobject.
-
substring
public CharSeq substring(int beginIndex, int endIndex)
Returns a string that is a substring of this string. The substring begins at the specifiedbeginIndexand 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 thebeginIndexis negative, orendIndexis larger than the length of thisCharSeqobject, orbeginIndexis larger thanendIndex.
-
stringPrefix
public java.lang.String stringPrefix()
Description copied from interface:ValueReturns the name of this Value type, which is used by toString().- Specified by:
stringPrefixin 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 thisCharSeqobject is returned. Otherwise, aCharSeqobject is returned that represents a character sequence that is the concatenation of the character sequence represented by thisCharSeqobject and the character sequence represented by the argument string.Examples:
"cares".concat("s") returns "caress" "to".concat("get").concat("her") returns "together"- Parameters:
str- theCharSeqthat 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:
trueif, 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 expression
Note that backslashes ({@link Pattern}.{@link Pattern#compile(String) compile}(<i>regex</i>).{@link Pattern#matcher(CharSequence) matcher}(<i>str</i>).{@link java.util.regex.Matcher#replaceFirst replaceFirst}(<i>repl</i>)\) 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 expression
Note that backslashes ({@link Pattern}.{@link Pattern#compile(String) compile}(<i>regex</i>).{@link Pattern#matcher(CharSequence) matcher}(<i>str</i>).{@link java.util.regex.Matcher#replaceAll replaceAll}(<i>repl</i>)\) 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
limitparameter 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:
An invocation of this method of the form str.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 expression{@link Pattern}.{@link Pattern#compile(String) compile}(<i>regex</i>).{@link Pattern#split(CharSequence, int) split}(<i>str</i>, <i>n</i>)- 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 thisCharSeqto lower case using the rules of the givenLocale. Case mapping is based on the Unicode Standard version specified by theCharacterclass. Since case mappings are not always 1:1 char mappings, the resultingCharSeqmay 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 thisCharSeqto 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 thisCharSeqto upper case using the rules of the givenLocale. Case mapping is based on the Unicode Standard version specified by theCharacterclass. Since case mappings are not always 1:1 char mappings, the resultingCharSeqmay 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 thisCharSeqto 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 thisCharSeqto upper case using the rules of the givenLocale. If theCharSeqis empty, it won't have any effect. Case mapping is based on the Unicode Standard version specified by theCharacterclass. Since case mappings are not always 1:1 char mappings, the resultingCharSeqmay 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 thisCharSeqto upper case using the rules of the default locale. If theCharSeqis 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
CharSeqobject represents an empty character sequence, or the first and last characters of character sequence represented by thisCharSeqobject both have codes greater than'\u0020'(the space character), then a reference to thisCharSeqobject is returned.Otherwise, if there is no character with a code greater than
'\u0020'in the string, then aCharSeqobject 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'. ACharSeqobject 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 thisCharSeqinto aByteby callingByte.decode(String).We write
instead ofByte value = charSeq.decodeByte();Byte value = Byte.decode(charSeq.mkString());- Returns:
- a
Byteobject holding the byte value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- if thisCharSeqdoes not contain a parsable byte.
-
decodeInteger
public java.lang.Integer decodeInteger()
Decodes thisCharSeqinto anIntegerby callingInteger.decode(String).We write
instead ofInteger value = charSeq.decodeInteger();Integer value = Integer.decode(charSeq.mkString());- Returns:
- an
Integerobject holding the int value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- if thisCharSeqdoes not contain a parsable int.
-
decodeLong
public java.lang.Long decodeLong()
Decodes thisCharSeqinto aLongby callingLong.decode(String).We write
instead ofLong value = charSeq.decodeLong();Long value = Long.decode(charSeq.mkString());- Returns:
- a
Longobject holding the long value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- if thisCharSeqdoes not contain a parsable long.
-
decodeShort
public java.lang.Short decodeShort()
Decodes thisCharSeqinto aShortby callingShort.decode(String).We write
instead ofShort value = charSeq.decodeShort();Short value = Short.decode(charSeq.mkString());- Returns:
- a
Shortobject holding the short value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- if thisCharSeqdoes not contain a parsable short.
-
parseBoolean
public boolean parseBoolean()
Parses thisCharSeqas 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 thisCharSeqas 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
CharSeqin decimal - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable byte.
-
parseByte
public byte parseByte(int radix)
Parses thisCharSeqas 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
CharSeqin the specified radix - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable byte.
-
parseDouble
public double parseDouble()
Parses thisCharSeqas 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 thisCharSeqdoes not contain a parsable double.
-
parseFloat
public float parseFloat()
Parses thisCharSeqas 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 thisCharSeqdoes not contain a parsable float.
-
parseInt
public int parseInt()
Parses thisCharSeqas 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
CharSeqin decimal - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable int.
-
parseInt
public int parseInt(int radix)
Parses thisCharSeqas 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
CharSeqin the specified radix - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable int.
-
parseUnsignedInt
@GwtIncompatible public int parseUnsignedInt()
Parses thisCharSeqas 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
CharSeqin decimal - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable unsigned int.
-
parseUnsignedInt
@GwtIncompatible public int parseUnsignedInt(int radix)
Parses thisCharSeqas 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
CharSeqin the specified radix - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable unsigned int.
-
parseLong
public long parseLong()
Parses thisCharSeqas 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
CharSeqin decimal - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable long.
-
parseLong
public long parseLong(int radix)
Parses thisCharSeqas 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
CharSeqin the specified radix - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable long.
-
parseUnsignedLong
@GwtIncompatible public long parseUnsignedLong()
Parses thisCharSeqas 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
CharSeqin decimal - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable unsigned long.
-
parseUnsignedLong
@GwtIncompatible public long parseUnsignedLong(int radix)
Parses thisCharSeqas 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
CharSeqin the specified radix - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable unsigned long.
-
parseShort
public short parseShort()
Parses thisCharSeqas 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
CharSeqin decimal - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable short.
-
parseShort
public short parseShort(int radix)
Parses thisCharSeqas 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
CharSeqin the specified radix - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable short.
-
toBoolean
public java.lang.Boolean toBoolean()
Converts thisCharSeqto aBooleanby callingBoolean.valueOf(String).We write
instead ofBoolean value = charSeq.toBoolean();Boolean value = Boolean.valueOf(charSeq.mkString());- Returns:
- the
Booleanvalue represented by thisCharSeq
-
toByte
public java.lang.Byte toByte()
Converts thisCharSeqto aByteby callingByte.valueOf(String).We write
instead ofByte value = charSeq.toByte();Byte value = Byte.valueOf(charSeq.mkString());- Returns:
- a
Byteobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable byte.
-
toByte
public java.lang.Byte toByte(int radix)
Converts thisCharSeqto aBytein 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
Byteobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable byte.
-
toDouble
public java.lang.Double toDouble()
Converts thisCharSeqto aDoubleby callingDouble.valueOf(String).We write
instead ofDouble value = charSeq.toDouble();Double value = Double.valueOf(charSeq.mkString());- Returns:
- a
Doubleobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable double.
-
toFloat
public java.lang.Float toFloat()
Converts thisCharSeqto aFloatby callingFloat.valueOf(String).We write
instead ofFloat value = charSeq.toFloat();Float value = Float.valueOf(charSeq.mkString());- Returns:
- a
Floatobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable float.
-
toInteger
public java.lang.Integer toInteger()
Converts thisCharSeqto anIntegerby callingInteger.valueOf(String).We write
instead ofInteger value = charSeq.toInteger();Integer value = Integer.valueOf(charSeq.mkString());- Returns:
- an
Integerobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable int.
-
toInteger
public java.lang.Integer toInteger(int radix)
Converts thisCharSeqto anIntegerin 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
Integerobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable int.
-
toLong
public java.lang.Long toLong()
Converts thisCharSeqto aLongby callingLong.valueOf(String).We write
instead ofLong value = charSeq.toLong();Long value = Long.valueOf(charSeq.mkString());- Returns:
- a
Longobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable long.
-
toLong
public java.lang.Long toLong(int radix)
Converts thisCharSeqto aLongin 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
Longobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable long.
-
toShort
public java.lang.Short toShort()
Converts thisCharSeqto aShortby callingShort.valueOf(String).We write
instead ofShort value = charSeq.toShort();Short value = Short.valueOf(charSeq.mkString());- Returns:
- a
Shortobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable short.
-
toShort
public java.lang.Short toShort(int radix)
Converts thisCharSeqto aShortin 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
Shortobject holding the value represented by thisCharSeq - Throws:
java.lang.NumberFormatException- If thisCharSeqdoes not contain a parsable short.
-
toJavaArray
public java.lang.Character[] toJavaArray()
Description copied from interface:ValueConverts 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:
toJavaArrayin interfaceValue<java.lang.Character>- Returns:
- A new Java array.
-
-