public final class CharSeq extends Object implements CharSequence, ISeq<Character>, Comparable<CharSeq>, Immutable, Serializable
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));
Constructor and Description |
---|
CharSeq(char[] characters)
Create a new (distinct) CharSeq from the given
characters . |
CharSeq(CharSequence characters)
Create a new (distinct) CharSeq from the given
characters . |
Modifier and Type | Method and Description |
---|---|
List<T> |
asList()
Returns a fixed-size list backed by the specified sequence.
|
char |
charAt(int index) |
int |
compareTo(CharSeq set) |
boolean |
contains(char c)
Test whether this character set contains the given character
c . |
boolean |
contains(Character c)
Test whether this character set contains the given character
c . |
boolean |
contains(Object object)
Returns
true if this sequence contains the specified element. |
MSeq<T> |
copy()
Return a shallow copy of this sequence.
|
boolean |
equals(Object object)
Compares the specified object with this sequence for equality.
|
static String |
expand(char a,
char b)
Expands the characters between
a and b . |
static String |
expand(CharSequence pattern)
Expands the character range for the given
pattern . |
boolean |
forall(Function<? super T,Boolean> predicate)
Deprecated.
Align the naming with the upcoming JDK 1.8 release. Use
forAll(Function) instead. |
boolean |
forAll(Function<? super T,Boolean> predicate)
Tests whether a predicate holds for all elements of this sequence.
|
<R> void |
foreach(Function<? super T,? extends R> function)
Deprecated.
Align the naming with the upcoming JDK 1.8 release. Use
forEach(Function) instead. |
<R> void |
forEach(Function<? super T,? extends R> function)
Applies a
function to all elements of this sequence. |
T |
get(int index)
Return the value at the given
index . |
int |
hashCode()
Returns the hash code value for this sequence.
|
int |
indexOf(Object element)
Returns the index of the first occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
int |
indexOf(Object element,
int start)
Returns the index of the first occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
int |
indexOf(Object element,
int start,
int end)
Returns the index of the first occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
int |
indexWhere(Function<? super T,Boolean> predicate)
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. |
int |
indexWhere(Function<? super T,Boolean> predicate,
int start)
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. |
int |
indexWhere(Function<? super T,Boolean> predicate,
int start,
int end)
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. |
boolean |
isEmpty()
Test whether this character set is empty.
|
Iterator<Character> |
iterator() |
<B> Iterator<B> |
iterator(Function<? super T,? extends B> converter)
Return an iterator with the new type
B . |
int |
lastIndexOf(Object element)
Returns the index of the last occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
int |
lastIndexOf(Object element,
int end)
Returns the index of the last occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
int |
lastIndexOf(Object element,
int start,
int end)
Returns the index of the last occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
int |
lastIndexWhere(Function<? super T,Boolean> predicate)
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. |
int |
lastIndexWhere(Function<? super T,Boolean> predicate,
int end)
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. |
int |
lastIndexWhere(Function<? super T,Boolean> predicate,
int start,
int end)
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. |
int |
length()
Return the length of this sequence.
|
<B> ISeq<B> |
map(Function<? super T,? extends B> converter)
Builds a new sequence by applying a function to all elements of this
sequence.
|
static CharSeq |
of(char a,
char b)
Expands the characters between
a and b . |
static CharSeq |
of(CharSequence pattern)
Expands the character range for the given
pattern . |
ISeq<T> |
subSeq(int start)
Returns a view of the portion of this sequence between the specified
start , inclusive, and end , exclusive. |
ISeq<T> |
subSeq(int start,
int end)
Returns a view of the portion of this sequence between the specified
start , inclusive, and end , exclusive. |
CharSeq |
subSequence(int start,
int end) |
Object[] |
toArray()
Return an array containing all of the elements in this sequence in right
order.
|
T[] |
toArray(T[] array)
Return an array containing all of the elements in this sequence in right
order; the runtime type of the returned array is that of the specified
array.
|
static ISeq<Character> |
toISeq(CharSequence chars)
Helper method for creating a sequence of characters from the given
CharSequence . |
String |
toString() |
String |
toString(String separator)
Create a string representation of the given sequence.
|
String |
toString(String prefix,
String separator,
String suffix)
Create a string representation of the given sequence.
|
<A> ISeq<A> |
upcast(ISeq<? extends A> seq)
Deprecated.
|
static CharSeq |
valueOf(char a,
char b)
Deprecated.
Use
of(char, char) instead. |
static CharSeq |
valueOf(CharSequence pattern)
Deprecated.
Use
of(CharSequence) instead. |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
asList, forall, forAll, foreach, forEach, get, indexOf, indexOf, indexOf, indexWhere, indexWhere, indexWhere, iterator, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, lastIndexWhere, toArray, toArray, toString, toString
public CharSeq(char[] characters)
characters
. The
given CharSequence
is sorted and duplicate values are removedcharacters
- the characters.NullPointerException
- if the characters
are null
.CharSeq(CharSequence)
public CharSeq(CharSequence characters)
characters
. The
given CharSequence
is sorted and duplicate values are removed.characters
- the characters.NullPointerException
- if the characters
are null
.public boolean contains(Object object)
Seq
true
if this sequence contains the specified element.public boolean contains(Character c)
c
.c
- the character to test.true
if this character set contains the given character,
false
otherwise.NullPointerException
- if the given character c
is
null
.public boolean contains(char c)
c
.c
- the character to test.true
if this character set contains the given character,
false
otherwise.public char charAt(int index)
charAt
in interface CharSequence
public int length()
Seq
length
in interface CharSequence
length
in interface Seq<Character>
public CharSeq subSequence(int start, int end)
subSequence
in interface CharSequence
public boolean isEmpty()
true
if this character set is empty, false
otherwise.public int hashCode()
Seq
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());
}
hashCode
in interface Seq<Character>
List.hashCode()
public boolean equals(Object object)
Seq
equals
in interface Seq<Character>
object
- the object to be compared for equality with this sequence.true
if the specified object is equal to this sequence,
false
otherwise.List.equals(Object)
public int compareTo(CharSeq set)
compareTo
in interface Comparable<CharSeq>
public String toString()
toString
in interface CharSequence
public static String expand(CharSequence pattern)
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.pattern
- the pattern
to expand.PatternSyntaxException
- if the pattern could not be expanded.NullPointerException
- if the pattern is null
.public static String expand(char a, char b)
a
and b
.a
- the start character.b
- the stop character.public static CharSeq of(CharSequence pattern)
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.pattern
- the pattern
to expand.PatternSyntaxException
- if the pattern could not be expanded.NullPointerException
- if the pattern is null
.expand(CharSequence)
@Deprecated public static CharSeq valueOf(CharSequence pattern)
of(CharSequence)
instead.public static CharSeq of(char a, char b)
a
and b
.a
- the start character.b
- the stop character.expand(char, char)
@Deprecated public static CharSeq valueOf(char a, char b)
of(char, char)
instead.public static ISeq<Character> toISeq(CharSequence chars)
CharSequence
. The returned sequence will contain all characters
in the original order.chars
- the char sequence to convert.public ISeq<T> subSeq(int start, int end)
Seq
start
, inclusive, and end
, exclusive. (If start
and end
are equal, the returned sequence has the 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
sort that commonly exist for arrays). Any operation that expects an array
can be used as a range operation by passing an sub sequence view instead of
an whole sequence.public ISeq<T> subSeq(int start)
Seq
start
, inclusive, and end
, exclusive. (If start
and end
are equal, the returned sequence has the 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
sort that commonly exist for arrays). Any operation that expects an sequence
can be used as a range operation by passing an sub sequence view instead of
an whole sequence.public <B> ISeq<B> map(Function<? super T,? extends B> converter)
Seq
map
in interface ISeq<T>
map
in interface Seq<T>
B
- the element type of the returned collection.converter
- the function to apply to each element.public MSeq<T> copy()
ISeq
@Deprecated public <A> ISeq<A> upcast(ISeq<? extends A> seq)
ISeq
Helper method for up-casting an given immutable sequence. This allows you
to assign this sequence to an sequence where the element type is a super
type of T
.
ISeq<Double> da = new Array<Double>(0.0, 1.0, 2.0).toISeq();
ISeq<Number> na = da.upcast(da);
ISeq<Object> oa = na.upcast(na);
public T get(int index)
Seq
index
.public int indexOf(Object element)
Seq
public int indexOf(Object element, int start)
Seq
public int indexOf(Object element, int start, int end)
Seq
indexOf
in interface Seq<T>
element
- element to search for, can be null
start
- the start index (inclusively) for the element search.end
- the end index (exclusively) for the element search.public int indexWhere(Function<? super T,Boolean> predicate)
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 first null value.
final int index = seq.indexOf(new Predicates.Nil());
// Assert of no null values.
assert (sequence.indexOf(new Predicates.Nil()) == -1);
indexWhere
in interface Seq<T>
predicate
- the search predicate.true
, or -1 if the predicate returns false
for every sequence element.public int indexWhere(Function<? super T,Boolean> predicate, int start)
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 first null value.
final int index = seq.indexOf(new Predicates.Nil());
// Assert of no null values.
assert (sequence.indexOf(new Predicates.Nil()) == -1);
indexWhere
in interface Seq<T>
predicate
- the search predicate.true
, or -1 if the predicate returns false
for every sequence element.public int indexWhere(Function<? super T,Boolean> predicate, int start, int end)
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 first null value.
final int index = seq.indexOf(new Predicates.Nil());
// Assert of no null values.
assert (sequence.indexOf(new Predicates.Nil()) == -1);
indexWhere
in interface Seq<T>
predicate
- the search predicate.true
, or -1 if the predicate returns false
for every sequence element.public int lastIndexOf(Object element)
Seq
lastIndexOf
in interface Seq<T>
element
- element to search for, can be null
public int lastIndexOf(Object element, int end)
Seq
lastIndexOf
in interface Seq<T>
element
- element to search for, can be null
public int lastIndexOf(Object element, int start, int end)
Seq
lastIndexOf
in interface Seq<T>
element
- element to search for, can be null
public int lastIndexWhere(Function<? super T,Boolean> predicate)
Seq
true
, or -1 if the predicate returns false for every
sequence element.lastIndexWhere
in interface Seq<T>
predicate
- the search predicate.true
, or -1 if the predicate returns false for
every sequence element.public int lastIndexWhere(Function<? super T,Boolean> predicate, int end)
Seq
true
, or -1 if the predicate returns false for every
sequence element.lastIndexWhere
in interface Seq<T>
predicate
- the search predicate.true
, or -1 if the predicate returns false for
every sequence element.public int lastIndexWhere(Function<? super T,Boolean> predicate, int start, int end)
Seq
true
, or -1 if the predicate returns false for every
sequence element.lastIndexWhere
in interface Seq<T>
predicate
- the search predicate.true
, or -1 if the predicate returns false for
every sequence element.@Deprecated public <R> void foreach(Function<? super T,? extends R> function)
forEach(Function)
instead.public <R> void forEach(Function<? super T,? extends R> function)
Seq
function
to all elements of this sequence.@Deprecated public boolean forall(Function<? super T,Boolean> predicate)
forAll(Function)
instead.public boolean forAll(Function<? super T,Boolean> predicate)
Seq
public <B> Iterator<B> iterator(Function<? super T,? extends B> converter)
Seq
B
.public Object[] toArray()
Seq
toArray
in interface Seq<T>
Collection.toArray()
public T[] toArray(T[] array)
Seq
toArray
in interface Seq<T>
array
- the array into which the elements of this array are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose.Collection.toArray(Object[])
public List<T> asList()
Seq
RandomAccess
.public String toString(String prefix, String separator, String suffix)
Seq
© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)