Class CharAdapter
java.lang.Object
org.eclipse.collections.impl.primitive.AbstractCharIterable
org.eclipse.collections.impl.string.immutable.CharAdapter
- All Implemented Interfaces:
Serializable
,CharSequence
,CharIterable
,ImmutableCharCollection
,CharList
,ImmutableCharList
,OrderedCharIterable
,ReversibleCharIterable
,PrimitiveIterable
public class CharAdapter extends AbstractCharIterable implements CharSequence, ImmutableCharList, Serializable
Provides a view into the char[] stored in a String as an ImmutableCharList. This is a cleaner more OO way of
providing many of the iterable protocols available in StringIterate for char values.
- Since:
- 7.0
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description CharAdapter(String value)
-
Method Summary
Modifier and Type Method Description static CharAdapter
adapt(String value)
boolean
allSatisfy(CharPredicate predicate)
Returns true if all of the elements in the CharIterable return true for the specified predicate, otherwise returns false.boolean
anySatisfy(CharPredicate predicate)
Returns true if any of the elements in the CharIterable return true for the specified predicate, otherwise returns false.void
appendString(Appendable appendable, String start, String separator, String end)
Prints a string representation of this collection onto the givenAppendable
.LazyCharIterable
asReversed()
int
binarySearch(char value)
char
charAt(int index)
CharIterator
charIterator()
Returns a primitive iterator that can be used to iterate over the CharIterable in an imperative style.RichIterable<CharIterable>
chunk(int size)
Partitions elements in fixed size chunks.<V> ImmutableList<V>
collect(CharToObjectFunction<? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source collection.CharAdapter
collectChar(CharToCharFunction function)
boolean
contains(char expected)
Returns true if the value is contained in the CharIterable, and false if it is not.int
count(CharPredicate predicate)
Returns a count of the number of elements in the CharIterable that return true for the specified predicate.char
detectIfNone(CharPredicate predicate, char ifNone)
CharAdapter
distinct()
long
dotProduct(CharList list)
void
each(CharProcedure procedure)
A synonym for forEach.boolean
equals(Object otherList)
Follows the same general contract asList.equals(Object)
.void
forEach(CharProcedure procedure)
Applies the CharProcedure to each element in the CharIterable.void
forEachWithIndex(CharIntProcedure procedure)
static CharAdapter
from(char... chars)
static CharAdapter
from(CharIterable iterable)
char
get(int index)
Character
getCharacter(int index)
char
getFirst()
char
getLast()
int
hashCode()
Follows the same general contract asList.hashCode()
.int
indexOf(char value)
<T> T
injectInto(T injectedValue, ObjectCharToObjectFunction<? super T,? extends T> function)
<T> T
injectIntoWithIndex(T injectedValue, ObjectCharIntToObjectFunction<? super T,? extends T> function)
boolean
isEmpty()
Returns true if this iterable has zero items.int
lastIndexOf(char value)
int
length()
char
max()
char
min()
CharAdapter
newWith(char element)
CharAdapter
newWithAll(CharIterable elements)
CharAdapter
newWithout(char element)
CharAdapter
newWithoutAll(CharIterable elements)
boolean
noneSatisfy(CharPredicate predicate)
Returns true if none of the elements in the CharIterable return true for the specified predicate, otherwise returns false.CharAdapter
reject(CharPredicate predicate)
Returns a new CharIterable with all of the elements in the CharIterable that return false for the specified predicate.CharAdapter
select(CharPredicate predicate)
Returns a new CharIterable with all of the elements in the CharIterable that return true for the specified predicate.int
size()
Returns the number of items in this iterable.ImmutableCharList
subList(int fromIndex, int toIndex)
String
subSequence(int start, int end)
long
sum()
char[]
toArray()
Converts the CharIterable to a primitive char array.char[]
toArray(char[] target)
Converts the CharIterable to a primitive char array.MutableCharBag
toBag()
Converts the CharIterable to a new MutableCharBag.ImmutableCharList
toImmutable()
Returns an immutable copy of this list.MutableCharList
toList()
Converts the CharIterable to a new MutableCharList.CharAdapter
toReversed()
MutableCharSet
toSet()
Converts the CharIterable to a new MutableCharSet.String
toString()
The value of toString must be strictly implemented as defined in CharSequence.StringBuilder
toStringBuilder()
<T> ImmutableList<CharObjectPair<T>>
zip(Iterable<T> iterable)
Returns anImmutableList
formed from thisImmutableCharList
and aListIterable
by combining corresponding elements in pairs.ImmutableList<CharCharPair>
zipChar(CharIterable iterable)
Returns anImmutableList
formed from thisImmutableCharList
and anotherCharList
by combining corresponding elements in pairs.Methods inherited from class org.eclipse.collections.impl.primitive.AbstractCharIterable
asLazy, average, containsAll, containsAll, maxIfEmpty, median, minIfEmpty, toSortedArray, toSortedList
Methods inherited from interface org.eclipse.collections.api.CharIterable
asLazy, average, averageIfEmpty, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAll, containsAll, flatCollect, maxIfEmpty, median, medianIfEmpty, minIfEmpty, reduce, reduceIfEmpty, reject, select, summaryStatistics, toSortedArray, toSortedList
Methods inherited from interface org.eclipse.collections.api.list.primitive.ImmutableCharList
collectWithIndex, tap
Methods inherited from interface org.eclipse.collections.api.ordered.primitive.OrderedCharIterable
collectWithIndex
Methods inherited from interface org.eclipse.collections.api.PrimitiveIterable
appendString, appendString, makeString, makeString, makeString, notEmpty
-
Constructor Details
-
Method Details
-
adapt
-
from
-
from
-
charAt
public char charAt(int index)- Specified by:
charAt
in interfaceCharSequence
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
isEmpty
public boolean isEmpty()Description copied from interface:PrimitiveIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfacePrimitiveIterable
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
toStringBuilder
-
toString
The value of toString must be strictly implemented as defined in CharSequence.- Specified by:
toString
in interfaceCharSequence
- Specified by:
toString
in interfacePrimitiveIterable
- Overrides:
toString
in classAbstractCharIterable
- Returns:
- a string representation of this PrimitiveIterable
- See Also:
AbstractCollection.toString()
-
charIterator
Description copied from interface:CharIterable
Returns a primitive iterator that can be used to iterate over the CharIterable in an imperative style.- Specified by:
charIterator
in interfaceCharIterable
-
toArray
public char[] toArray()Description copied from interface:CharIterable
Converts the CharIterable to a primitive char array.- Specified by:
toArray
in interfaceCharIterable
-
toArray
public char[] toArray(char[] target)Description copied from interface:CharIterable
Converts the CharIterable to a primitive char array. If the collection fits into the provided array it is used to store its elements and is returned from the method, otherwise a new array of the appropriate size is allocated and returned. If the iterable is empty, the target array is returned unchanged.- Specified by:
toArray
in interfaceCharIterable
-
contains
public boolean contains(char expected)Description copied from interface:CharIterable
Returns true if the value is contained in the CharIterable, and false if it is not.- Specified by:
contains
in interfaceCharIterable
-
forEach
Description copied from interface:CharIterable
Applies the CharProcedure to each element in the CharIterable.- Specified by:
forEach
in interfaceCharIterable
-
each
Description copied from interface:CharIterable
A synonym for forEach.- Specified by:
each
in interfaceCharIterable
-
distinct
- Specified by:
distinct
in interfaceCharList
- Specified by:
distinct
in interfaceImmutableCharList
- Specified by:
distinct
in interfaceReversibleCharIterable
-
newWith
- Specified by:
newWith
in interfaceImmutableCharCollection
- Specified by:
newWith
in interfaceImmutableCharList
-
newWithout
- Specified by:
newWithout
in interfaceImmutableCharCollection
- Specified by:
newWithout
in interfaceImmutableCharList
-
newWithAll
- Specified by:
newWithAll
in interfaceImmutableCharCollection
- Specified by:
newWithAll
in interfaceImmutableCharList
-
newWithoutAll
- Specified by:
newWithoutAll
in interfaceImmutableCharCollection
- Specified by:
newWithoutAll
in interfaceImmutableCharList
-
toReversed
- Specified by:
toReversed
in interfaceCharList
- Specified by:
toReversed
in interfaceImmutableCharList
- Specified by:
toReversed
in interfaceReversibleCharIterable
-
subList
- Specified by:
subList
in interfaceCharList
- Specified by:
subList
in interfaceImmutableCharList
- See Also:
List.subList(int fromIndex, int toIndex)
-
get
public char get(int index) -
getCharacter
-
dotProduct
- Specified by:
dotProduct
in interfaceCharList
-
binarySearch
public int binarySearch(char value)- Specified by:
binarySearch
in interfaceCharList
-
lastIndexOf
public int lastIndexOf(char value)- Specified by:
lastIndexOf
in interfaceCharList
-
toImmutable
Description copied from interface:CharList
Returns an immutable copy of this list. If the list is immutable, it returns itself.- Specified by:
toImmutable
in interfaceCharList
-
getLast
public char getLast()- Specified by:
getLast
in interfaceReversibleCharIterable
-
asReversed
- Specified by:
asReversed
in interfaceReversibleCharIterable
-
injectIntoWithIndex
public <T> T injectIntoWithIndex(T injectedValue, ObjectCharIntToObjectFunction<? super T,? extends T> function)- Specified by:
injectIntoWithIndex
in interfaceOrderedCharIterable
- Specified by:
injectIntoWithIndex
in interfaceReversibleCharIterable
-
getFirst
public char getFirst()- Specified by:
getFirst
in interfaceOrderedCharIterable
-
indexOf
public int indexOf(char value)- Specified by:
indexOf
in interfaceOrderedCharIterable
-
forEachWithIndex
- Specified by:
forEachWithIndex
in interfaceOrderedCharIterable
-
select
Description copied from interface:CharIterable
Returns a new CharIterable with all of the elements in the CharIterable that return true for the specified predicate.- Specified by:
select
in interfaceCharIterable
- Specified by:
select
in interfaceCharList
- Specified by:
select
in interfaceImmutableCharCollection
- Specified by:
select
in interfaceImmutableCharList
- Specified by:
select
in interfaceOrderedCharIterable
- Specified by:
select
in interfaceReversibleCharIterable
-
reject
Description copied from interface:CharIterable
Returns a new CharIterable with all of the elements in the CharIterable that return false for the specified predicate.- Specified by:
reject
in interfaceCharIterable
- Specified by:
reject
in interfaceCharList
- Specified by:
reject
in interfaceImmutableCharCollection
- Specified by:
reject
in interfaceImmutableCharList
- Specified by:
reject
in interfaceOrderedCharIterable
- Specified by:
reject
in interfaceReversibleCharIterable
-
collect
Description copied from interface:CharIterable
Returns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.- Specified by:
collect
in interfaceCharIterable
- Specified by:
collect
in interfaceCharList
- Specified by:
collect
in interfaceImmutableCharCollection
- Specified by:
collect
in interfaceImmutableCharList
- Specified by:
collect
in interfaceOrderedCharIterable
- Specified by:
collect
in interfaceReversibleCharIterable
-
collectChar
-
detectIfNone
- Specified by:
detectIfNone
in interfaceCharIterable
-
count
Description copied from interface:CharIterable
Returns a count of the number of elements in the CharIterable that return true for the specified predicate.- Specified by:
count
in interfaceCharIterable
-
anySatisfy
Description copied from interface:CharIterable
Returns true if any of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
anySatisfy
in interfaceCharIterable
-
allSatisfy
Description copied from interface:CharIterable
Returns true if all of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
allSatisfy
in interfaceCharIterable
-
noneSatisfy
Description copied from interface:CharIterable
Returns true if none of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
noneSatisfy
in interfaceCharIterable
-
toList
Description copied from interface:CharIterable
Converts the CharIterable to a new MutableCharList.- Specified by:
toList
in interfaceCharIterable
- Overrides:
toList
in classAbstractCharIterable
-
toSet
Description copied from interface:CharIterable
Converts the CharIterable to a new MutableCharSet.- Specified by:
toSet
in interfaceCharIterable
- Overrides:
toSet
in classAbstractCharIterable
-
toBag
Description copied from interface:CharIterable
Converts the CharIterable to a new MutableCharBag.- Specified by:
toBag
in interfaceCharIterable
- Overrides:
toBag
in classAbstractCharIterable
-
injectInto
public <T> T injectInto(T injectedValue, ObjectCharToObjectFunction<? super T,? extends T> function)- Specified by:
injectInto
in interfaceCharIterable
-
chunk
Description copied from interface:CharIterable
Partitions elements in fixed size chunks.- Specified by:
chunk
in interfaceCharIterable
- Parameters:
size
- the number of elements per chunk- Returns:
- A
RichIterable
containingCharIterable
s of sizesize
, except the last will be truncated if the elements don't divide evenly.
-
sum
public long sum()- Specified by:
sum
in interfaceCharIterable
-
max
public char max()- Specified by:
max
in interfaceCharIterable
-
min
public char min()- Specified by:
min
in interfaceCharIterable
-
size
public int size()Description copied from interface:PrimitiveIterable
Returns the number of items in this iterable.- Specified by:
size
in interfacePrimitiveIterable
-
appendString
Description copied from interface:PrimitiveIterable
Prints a string representation of this collection onto the givenAppendable
. Prints the string returned byPrimitiveIterable.makeString(String, String, String)
.- Specified by:
appendString
in interfacePrimitiveIterable
-
equals
Description copied from interface:CharList
Follows the same general contract asList.equals(Object)
. -
hashCode
public int hashCode()Description copied from interface:CharList
Follows the same general contract asList.hashCode()
. -
zipChar
Description copied from interface:ImmutableCharList
Returns anImmutableList
formed from thisImmutableCharList
and anotherCharList
by combining corresponding elements in pairs. If one of the twoCharList
s is longer than the other, its remaining elements are ignored.- Specified by:
zipChar
in interfaceCharList
- Specified by:
zipChar
in interfaceImmutableCharList
- Since:
- 9.1.
-
zip
Description copied from interface:ImmutableCharList
Returns anImmutableList
formed from thisImmutableCharList
and aListIterable
by combining corresponding elements in pairs. If one of the two Lists is longer than the other, its remaining elements are ignored.- Specified by:
zip
in interfaceCharList
- Specified by:
zip
in interfaceImmutableCharList
- Since:
- 9.1.
-