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:
  • Constructor Details

    • CharSeq

      public CharSeq(char[] characters)
      Create a new (distinct) CharSeq from the given characters. The given CharSequence is sorted and duplicate values are removed
      Parameters:
      characters - the characters.
      Throws:
      NullPointerException - if the characters are null.
      See Also:
    • CharSeq

      public CharSeq(CharSequence characters)
      Create a new (distinct) CharSeq from the given characters. The given CharSequence is sorted and duplicate values are removed.
      Parameters:
      characters - the characters.
      Throws:
      NullPointerException - if the characters are null.
  • Method Details

    • contains

      public boolean contains(Object object)
      Description copied from interface: Seq
      Returns true if this sequence contains the specified element.
      Specified by:
      contains in interface Seq<Character>
      Parameters:
      object - element whose presence in this sequence is to be tested. The tested element can be null.
      Returns:
      true if this sequence contains the specified element
    • contains

      public boolean contains(Character c)
      Test whether this character set contains the given character c.
      Parameters:
      c - the character to test.
      Returns:
      true if this character set contains the given character, false otherwise.
      Throws:
      NullPointerException - if the given character c is null.
    • contains

      public boolean contains(char c)
      Test whether this character set contains the given character c.
      Parameters:
      c - the character to test.
      Returns:
      true if this character set contains the given character, false otherwise.
    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • length

      public int length()
      Description copied from interface: BaseSeq
      Return the length of this sequence. Once the sequence is created, the length can't be changed.
      Specified by:
      length in interface BaseSeq<Character>
      Specified by:
      length in interface CharSequence
      Returns:
      the length of this sequence.
    • subSequence

      public CharSeq subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • isEmpty

      public boolean isEmpty()
      Test whether this character set is empty.
      Specified by:
      isEmpty in interface BaseSeq<Character>
      Specified by:
      isEmpty in interface CharSequence
      Returns:
      true if this character set is empty, false otherwise.
    • hashCode

      public int hashCode()
      Description copied from interface: Seq
      Returns 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());
      }
      
      Specified by:
      hashCode in interface Seq<Character>
      Returns:
      the hash code value for this list
      See Also:
    • equals

      public boolean equals(Object obj)
      Description copied from interface: Seq
      Compares 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.
      Specified by:
      equals in interface Seq<Character>
      Parameters:
      obj - the object to be compared for equality with this sequence.
      Returns:
      true if the specified object is equal to this sequence, false otherwise.
      See Also:
    • compareTo

      public int compareTo(CharSeq set)
      Specified by:
      compareTo in interface Comparable<CharSeq>
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
    • expand

      public static String expand(CharSequence pattern)
      Expands the character range for the given pattern. E.g. a-zA-Z0-1 will return a string containing all upper and lower case characters (from a to z), and all digits form 0 to 9.
      Parameters:
      pattern - the pattern to expand.
      Returns:
      the expanded pattern.
      Throws:
      PatternSyntaxException - if the pattern could not be expanded.
      NullPointerException - if the pattern is null.
    • expand

      public static String expand(char a, char b)
      Expands the characters between a and b.
      Parameters:
      a - the start character.
      b - the stop character.
      Returns:
      the expanded characters.
    • of

      public static CharSeq of(CharSequence pattern)
      Expands the character range for the given pattern. E.g. a-zA-Z0-1 will return a string containing all upper and lower case characters (from a to z), and all digits form 0 to 9.
      Parameters:
      pattern - the pattern to expand.
      Returns:
      the expanded pattern.
      Throws:
      PatternSyntaxException - if the pattern could not be expanded.
      NullPointerException - if the pattern is null.
      See Also:
    • of

      public static CharSeq of(char a, char b)
      Expands the characters between a and b.
      Parameters:
      a - the start character.
      b - the stop character.
      Returns:
      the expanded characters.
      See Also:
    • toISeq

      public static ISeq<Character> toISeq(CharSequence chars)
      Helper method for creating a sequence of characters from the given CharSequence. 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

      public static Collector<Character, ?, CharSeq> toCharSeq()
    • map

      public <B> ISeq<B> map(Function<? super Character, ? extends B> mapper)
      Description copied from interface: Seq
      Builds a new sequence by applying a function to all elements of this sequence.
      Specified by:
      map in interface ISeq<T>
      Specified by:
      map in interface Seq<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

      public ISeq<Character> append(Iterable<? extends Character> values)
      Description copied from interface: Seq
      Return a new Seq with the given values appended.
      Specified by:
      append in interface ISeq<T>
      Specified by:
      append in interface Seq<T>
      Parameters:
      values - the values to append
      Returns:
      a new Seq with the elements of this sequence and the given values appended.
    • prepend

      public ISeq<Character> prepend(Iterable<? extends Character> values)
      Description copied from interface: Seq
      Return a new Seq with the given values prepended.
      Specified by:
      prepend in interface ISeq<T>
      Specified by:
      prepend in interface Seq<T>
      Parameters:
      values - the values to append
      Returns:
      a new Seq with the elements of this sequence and the given values prepended.
    • subSeq

      public ISeq<Character> subSeq(int start)
      Description copied from interface: Seq
      Returns a view of the portion of this sequence between the specified start, inclusive, and end, exclusive. (If start and end are 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.

      Specified by:
      subSeq in interface ISeq<T>
      Specified by:
      subSeq in interface Seq<T>
      Parameters:
      start - lower end point (inclusive) of the subarray.
      Returns:
      a view of the specified range within this array.
    • subSeq

      public ISeq<Character> subSeq(int start, int end)
      Description copied from interface: Seq
      Returns a view of the portion of this sequence between the specified start, inclusive, and end, exclusive. (If start and end are 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.

      Specified by:
      subSeq in interface ISeq<T>
      Specified by:
      subSeq in interface Seq<T>
      Parameters:
      start - low-end point (inclusive) of the subsequence.
      end - high-end point (exclusive) of the subsequence.
      Returns:
      a view of the specified range within this sequence.
    • copy

      public MSeq<Character> copy()
      Description copied from interface: ISeq
      Return a shallow copy of this sequence. The sequence elements are not cloned.
      Specified by:
      copy in interface Copyable<T>
      Specified by:
      copy in interface ISeq<T>
      Returns:
      a shallow copy of this sequence.
    • get

      public final Character get(int index)
      Description copied from interface: BaseSeq
      Return the value at the given index.
      Specified by:
      get in interface BaseSeq<T>
      Parameters:
      index - index of the element to return.
      Returns:
      the value at the given index.
    • forEach

      public void forEach(Consumer<? super Character> consumer)
      Specified by:
      forEach in interface BaseSeq<T>
      Specified by:
      forEach in interface Iterable<T>
    • forAll

      public boolean forAll(Predicate<? super Character> predicate)
      Description copied from interface: Seq
      Tests whether a predicate holds for all elements of this sequence.
      Specified by:
      forAll in interface Seq<T>
      Parameters:
      predicate - the predicate to use to test the elements.
      Returns:
      true if the given predicate p holds for all elements of this sequence, false otherwise.
    • indexWhere

      public int indexWhere(Predicate<? super Character> predicate, int start, int end)
      Description copied from interface: Seq

      Returns 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:
      indexWhere in interface Seq<T>
      Parameters:
      predicate - the search predicate.
      start - the search start index
      end - the search end index
      Returns:
      the index of the first element on which the given predicate returns true, or -1 if the predicate returns false for every sequence element.
    • lastIndexWhere

      public int lastIndexWhere(Predicate<? super Character> predicate, int start, int end)
      Description copied from interface: Seq
      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.
      Specified by:
      lastIndexWhere in interface Seq<T>
      Parameters:
      predicate - the search predicate.
      start - the search start index
      end - 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.