Class CharSeq
java.lang.Object
io.jenetics.util.CharSeq
- All Implemented Interfaces:
BaseSeq<Character>, Copyable<MSeq<Character>>, ISeq<Character>, Seq<Character>, Serializable, CharSequence, Comparable<CharSeq>, Iterable<Character>, IntFunction<Character>, RandomAccess
public final class CharSeq
extends Object
implements CharSequence, ISeq<Character>, Comparable<CharSeq>, Serializable
This class is used for holding the valid characters of an
CharacterGene. It is not a character sequence in the
classical sense. The characters of this sequence are sorted and doesn't
contain duplicate values, like a set.
final CharSeq cs1 = new CharSeq("abcdeaafg");
final CharSeq cs2 = new CharSeq("gfedcbabb");
assert(cs1.equals(cs2));
- Since:
- 1.0
- Version:
- 2.0
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCharSeq(char[] characters) Create a new (distinct) CharSeq from the givencharacters.CharSeq(CharSequence characters) Create a new (distinct) CharSeq from the givencharacters. -
Method Summary
Modifier and TypeMethodDescriptionReturn a newSeqwith the givenvaluesappended.charcharAt(int index) intbooleancontains(char c) Test whether this character set contains the given characterc.booleanTest whether this character set contains the given characterc.booleanReturnstrueif this sequence contains the specified element.copy()Return a shallow copy of this sequence.booleanCompares the specified object with this sequence for equality.static Stringexpand(char a, char b) Expands the characters betweenaandb.static Stringexpand(CharSequence pattern) Expands the character range for the givenpattern.booleanTests whether a predicate holds for all elements of this sequence.voidfinal Characterget(int index) Return the value at the givenindex.inthashCode()Returns the hash code value for this sequence.intindexWhere(Predicate<? super Character> predicate, int start, int end) Returns the index of the first element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.booleanisEmpty()Test whether this character set is empty.intlastIndexWhere(Predicate<? super Character> predicate, int start, int end) Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.intlength()Return the length of this sequence.<B> ISeq<B> Builds a new sequence by applying a function to all elements of this sequence.static CharSeqof(char a, char b) Expands the characters betweenaandb.static CharSeqof(CharSequence pattern) Expands the character range for the givenpattern.Return a newSeqwith the givenvaluesprepended.subSeq(int start) Returns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive.subSeq(int start, int end) Returns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive.subSequence(int start, int end) toISeq(CharSequence chars) Helper method for creating a sequence of characters from the givenCharSequence.toString()Methods inherited from interface BaseSeq
forEach, get, iterator, listIterator, nonEmpty, spliterator, streamMethods inherited from interface CharSequence
chars, codePoints, getCharsMethods inherited from interface Seq
apply, asISeq, asList, asMSeq, forAll, indexOf, indexOf, indexOf, indexWhere, indexWhere, indexWhere, isSorted, isSorted, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, lastIndexWhere, parallelStream, size, toArray, toArray, toArray, toString, toString
-
Constructor Details
-
CharSeq
Create a new (distinct) CharSeq from the givencharacters. The givenCharSequenceis sorted and duplicate values are removed- Parameters:
characters- the characters.- Throws:
NullPointerException- if thecharactersarenull.- See Also:
-
CharSeq
Create a new (distinct) CharSeq from the givencharacters. The givenCharSequenceis sorted and duplicate values are removed.- Parameters:
characters- the characters.- Throws:
NullPointerException- if thecharactersarenull.
-
-
Method Details
-
contains
Description copied from interface:SeqReturnstrueif this sequence contains the specified element. -
contains
Test whether this character set contains the given characterc.- Parameters:
c- the character to test.- Returns:
trueif this character set contains the given character,falseotherwise.- Throws:
NullPointerException- if the given charactercisnull.
-
contains
Test whether this character set contains the given characterc.- Parameters:
c- the character to test.- Returns:
trueif this character set contains the given character,falseotherwise.
-
charAt
- Specified by:
charAtin interfaceCharSequence
-
length
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
isEmpty
-
hashCode
Description copied from interface:SeqReturns the hash code value for this sequence. The hash code is defined as followed:int hashCode = 1; final Iterator<E> it = seq.iterator(); while (it.hasNext()) { final E obj = it.next(); hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode()); } -
equals
Description copied from interface:SeqCompares the specified object with this sequence for equality. Returns true if and only if the specified object is also a sequence, both sequences have the same size, and all corresponding pairs of elements in the two sequences are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) This definition ensures that the equals method works properly across different implementations of the Seq interface. -
compareTo
- Specified by:
compareToin interfaceComparable<CharSeq>
-
toString
- Specified by:
toStringin interfaceCharSequence
-
expand
Expands the character range for the givenpattern. E.g.a-zA-Z0-1will return a string containing all upper and lower case characters (from a to z), and all digits form 0 to 9.- Parameters:
pattern- thepatternto expand.- Returns:
- the expanded pattern.
- Throws:
PatternSyntaxException- if the pattern could not be expanded.NullPointerException- if the pattern isnull.
-
expand
-
of
Expands the character range for the givenpattern. E.g.a-zA-Z0-1will return a string containing all upper and lower case characters (from a to z), and all digits form 0 to 9.- Parameters:
pattern- thepatternto expand.- Returns:
- the expanded pattern.
- Throws:
PatternSyntaxException- if the pattern could not be expanded.NullPointerException- if the pattern isnull.- See Also:
-
of
-
toISeq
Helper method for creating a sequence of characters from the givenCharSequence. The returned sequence will contain all characters in the original order.- Parameters:
chars- the char sequence to convert.- Returns:
- a sequence which will contain all given chars in the original order.
-
toCharSeq
-
map
Description copied from interface:SeqBuilds a new sequence by applying a function to all elements of this sequence.- Specified by:
mapin interfaceISeq<T>- Specified by:
mapin interfaceSeq<T>- Type Parameters:
B- the element type of the returned collection.- Parameters:
mapper- the function to apply to each element.- Returns:
- a new sequence of type That resulting from applying the given function f to each element of this sequence and collecting the results.
-
append
Description copied from interface:SeqReturn a newSeqwith the givenvaluesappended. -
prepend
Description copied from interface:SeqReturn a newSeqwith the givenvaluesprepended. -
subSeq
Description copied from interface:SeqReturns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive. (Ifstartandendare equal, the returned sequence has length zero.) The returned sequence is backed by this sequence, so non-structural changes in the returned sequence are reflected in this sequence, and vice versa.This method eliminates the need for explicit range operations (of the populationSort that commonly exist for arrays). Any operation that expects a sequence can be used as a range operation by passing a subsequence view instead of a whole sequence.
-
subSeq
Description copied from interface:SeqReturns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive. (Ifstartandendare equal, the returned sequence has length zero.) The returned sequence is backed by this sequence, so non-structural changes in the returned sequence are reflected in this array, and vice versa.This method eliminates the need for explicit range operations (of the populationSort that commonly exist for arrays). Any operation that expects an array can be used as a range operation by passing a subsequence view instead of a whole sequence.
-
copy
-
get
-
forEach
-
forAll
Description copied from interface:SeqTests whether a predicate holds for all elements of this sequence. -
indexWhere
Description copied from interface:SeqReturns the index of the first element on which the given predicate returns
true, or -1 if the predicate returns false for every sequence element.// Finding index of the first null value. final int index = seq.indexOf(o -> o == null); // Assert of no null values. assert (sequence.indexOf(o -> o == null) == -1);- Specified by:
indexWherein interfaceSeq<T>- Parameters:
predicate- the search predicate.start- the search start indexend- the search end index- Returns:
- the index of the first element on which the given predicate
returns
true, or -1 if the predicate returnsfalsefor every sequence element.
-
lastIndexWhere
Description copied from interface:SeqReturns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.- Specified by:
lastIndexWherein interfaceSeq<T>- Parameters:
predicate- the search predicate.start- the search start indexend- the search end index- Returns:
- the index of the last element on which the given predicate
returns
true, or -1 if the predicate returns false for every sequence element.
-