Class CharAdapter
- java.lang.Object
-
- org.eclipse.collections.impl.primitive.AbstractCharIterable
-
- org.eclipse.collections.impl.string.immutable.CharAdapter
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,CharIterable,ImmutableCharCollection,CharList,ImmutableCharList,OrderedCharIterable,ReversibleCharIterable,PrimitiveIterable
public class CharAdapter extends AbstractCharIterable implements java.lang.CharSequence, ImmutableCharList, java.io.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classCharAdapter.InternalCharIterator
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringadaptedprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description CharAdapter(java.lang.String value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CharAdapteradapt(java.lang.String value)booleanallSatisfy(CharPredicate predicate)Returns true if all of the elements in the CharIterable return true for the specified predicate, otherwise returns false.booleananySatisfy(CharPredicate predicate)Returns true if any of the elements in the CharIterable return true for the specified predicate, otherwise returns false.voidappendString(java.lang.Appendable appendable, java.lang.String start, java.lang.String separator, java.lang.String end)Prints a string representation of this collection onto the givenAppendable.LazyCharIterableasReversed()intbinarySearch(char value)charcharAt(int index)CharIteratorcharIterator()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.CharAdaptercollectChar(CharToCharFunction function)booleancontains(char expected)Returns true if the value is contained in the CharIterable, and false if it is not.intcount(CharPredicate predicate)Returns a count of the number of elements in the CharIterable that return true for the specified predicate.chardetectIfNone(CharPredicate predicate, char ifNone)CharAdapterdistinct()longdotProduct(CharList list)voideach(CharProcedure procedure)A synonym for forEach.booleanequals(java.lang.Object otherList)Follows the same general contract asList.equals(Object).voidforEachWithIndex(CharIntProcedure procedure)static CharAdapterfrom(char... chars)static CharAdapterfrom(CharIterable iterable)charget(int index)java.lang.CharactergetCharacter(int index)chargetFirst()chargetLast()inthashCode()Follows the same general contract asList.hashCode().intindexOf(char value)<T> TinjectInto(T injectedValue, ObjectCharToObjectFunction<? super T,? extends T> function)<T> TinjectIntoWithIndex(T injectedValue, ObjectCharIntToObjectFunction<? super T,? extends T> function)booleanisEmpty()Returns true if this iterable has zero items.intlastIndexOf(char value)intlength()charmax()charmin()CharAdapternewWith(char element)CharAdapternewWithAll(CharIterable elements)CharAdapternewWithout(char element)CharAdapternewWithoutAll(CharIterable elements)booleannoneSatisfy(CharPredicate predicate)Returns true if none of the elements in the CharIterable return true for the specified predicate, otherwise returns false.CharAdapterreject(CharPredicate predicate)Returns a new CharIterable with all of the elements in the CharIterable that return false for the specified predicate.CharAdapterselect(CharPredicate predicate)Returns a new CharIterable with all of the elements in the CharIterable that return true for the specified predicate.intsize()Returns the number of items in this iterable.ImmutableCharListsubList(int fromIndex, int toIndex)java.lang.StringsubSequence(int start, int end)longsum()char[]toArray()Converts the CharIterable to a primitive char array.char[]toArray(char[] target)Converts the CharIterable to a primitive char array.MutableCharBagtoBag()Converts the CharIterable to a new MutableCharBag.ImmutableCharListtoImmutable()Returns an immutable copy of this list.MutableCharListtoList()Converts the CharIterable to a new MutableCharList.CharAdaptertoReversed()MutableCharSettoSet()Converts the CharIterable to a new MutableCharSet.MutableCharStacktoStack()Converts the collection to a CharStack.java.lang.StringtoString()The value of toString must be strictly implemented as defined in CharSequence.java.lang.StringBuildertoStringBuilder()<T> ImmutableList<CharObjectPair<T>>zip(java.lang.Iterable<T> iterable)Returns anImmutableListformed from thisImmutableCharListand aListIterableby combining corresponding elements in pairs.ImmutableList<CharCharPair>zipChar(CharIterable iterable)Returns anImmutableListformed from thisImmutableCharListand anotherCharListby combining corresponding elements in pairs.-
Methods inherited from class org.eclipse.collections.impl.primitive.AbstractCharIterable
asLazy, average, maxIfEmpty, median, minIfEmpty, toSortedArray, toSortedList
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.CharIterable
asLazy, average, averageIfEmpty, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAll, containsAll, containsAny, containsAny, containsNone, containsNone, flatCollect, forEach, injectIntoBoolean, injectIntoByte, injectIntoChar, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, injectIntoShort, maxIfEmpty, median, medianIfEmpty, minIfEmpty, reduce, reduceIfEmpty, reject, select, summaryStatistics, toSortedArray, toSortedList, toSortedList, toSortedListBy, toSortedListBy
-
Methods inherited from interface org.eclipse.collections.api.list.primitive.CharList
forEachInBoth
-
Methods inherited from interface org.eclipse.collections.api.list.primitive.ImmutableCharList
collectWithIndex, rejectWithIndex, selectWithIndex, tap
-
Methods inherited from interface org.eclipse.collections.api.ordered.primitive.OrderedCharIterable
collectWithIndex, rejectWithIndex, selectWithIndex
-
Methods inherited from interface org.eclipse.collections.api.PrimitiveIterable
appendString, appendString, makeString, makeString, makeString, notEmpty
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
adapted
private final java.lang.String adapted
-
-
Method Detail
-
adapt
public static CharAdapter adapt(java.lang.String value)
-
from
public static CharAdapter from(char... chars)
-
from
public static CharAdapter from(CharIterable iterable)
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfacejava.lang.CharSequence
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence
-
isEmpty
public boolean isEmpty()
Description copied from interface:PrimitiveIterableReturns true if this iterable has zero items.- Specified by:
isEmptyin interfacePrimitiveIterable
-
subSequence
public java.lang.String subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence
-
toStringBuilder
public java.lang.StringBuilder toStringBuilder()
-
toString
public java.lang.String toString()
The value of toString must be strictly implemented as defined in CharSequence.- Specified by:
toStringin interfacejava.lang.CharSequence- Specified by:
toStringin interfacePrimitiveIterable- Overrides:
toStringin classAbstractCharIterable- Returns:
- a string representation of this PrimitiveIterable
- See Also:
AbstractCollection.toString()
-
charIterator
public CharIterator charIterator()
Description copied from interface:CharIterableReturns a primitive iterator that can be used to iterate over the CharIterable in an imperative style.- Specified by:
charIteratorin interfaceCharIterable
-
toArray
public char[] toArray()
Description copied from interface:CharIterableConverts the CharIterable to a primitive char array.- Specified by:
toArrayin interfaceCharIterable
-
toArray
public char[] toArray(char[] target)
Description copied from interface:CharIterableConverts 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:
toArrayin interfaceCharIterable
-
contains
public boolean contains(char expected)
Description copied from interface:CharIterableReturns true if the value is contained in the CharIterable, and false if it is not.- Specified by:
containsin interfaceCharIterable
-
each
public void each(CharProcedure procedure)
Description copied from interface:CharIterableA synonym for forEach.- Specified by:
eachin interfaceCharIterable
-
distinct
public CharAdapter distinct()
- Specified by:
distinctin interfaceCharList- Specified by:
distinctin interfaceImmutableCharList- Specified by:
distinctin interfaceReversibleCharIterable
-
newWith
public CharAdapter newWith(char element)
- Specified by:
newWithin interfaceImmutableCharCollection- Specified by:
newWithin interfaceImmutableCharList
-
newWithout
public CharAdapter newWithout(char element)
- Specified by:
newWithoutin interfaceImmutableCharCollection- Specified by:
newWithoutin interfaceImmutableCharList
-
newWithAll
public CharAdapter newWithAll(CharIterable elements)
- Specified by:
newWithAllin interfaceImmutableCharCollection- Specified by:
newWithAllin interfaceImmutableCharList
-
newWithoutAll
public CharAdapter newWithoutAll(CharIterable elements)
- Specified by:
newWithoutAllin interfaceImmutableCharCollection- Specified by:
newWithoutAllin interfaceImmutableCharList
-
toReversed
public CharAdapter toReversed()
- Specified by:
toReversedin interfaceCharList- Specified by:
toReversedin interfaceImmutableCharList- Specified by:
toReversedin interfaceReversibleCharIterable
-
subList
public ImmutableCharList subList(int fromIndex, int toIndex)
- Specified by:
subListin interfaceCharList- Specified by:
subListin interfaceImmutableCharList- See Also:
List.subList(int fromIndex, int toIndex)
-
getCharacter
public java.lang.Character getCharacter(int index)
-
dotProduct
public long dotProduct(CharList list)
- Specified by:
dotProductin interfaceCharList
-
binarySearch
public int binarySearch(char value)
- Specified by:
binarySearchin interfaceCharList
-
lastIndexOf
public int lastIndexOf(char value)
- Specified by:
lastIndexOfin interfaceCharList
-
toImmutable
public ImmutableCharList toImmutable()
Description copied from interface:CharListReturns an immutable copy of this list. If the list is immutable, it returns itself.- Specified by:
toImmutablein interfaceCharList
-
getLast
public char getLast()
- Specified by:
getLastin interfaceReversibleCharIterable
-
asReversed
public LazyCharIterable asReversed()
- Specified by:
asReversedin interfaceReversibleCharIterable
-
injectIntoWithIndex
public <T> T injectIntoWithIndex(T injectedValue, ObjectCharIntToObjectFunction<? super T,? extends T> function)- Specified by:
injectIntoWithIndexin interfaceOrderedCharIterable- Specified by:
injectIntoWithIndexin interfaceReversibleCharIterable
-
getFirst
public char getFirst()
- Specified by:
getFirstin interfaceOrderedCharIterable
-
indexOf
public int indexOf(char value)
- Specified by:
indexOfin interfaceOrderedCharIterable
-
forEachWithIndex
public void forEachWithIndex(CharIntProcedure procedure)
- Specified by:
forEachWithIndexin interfaceOrderedCharIterable
-
select
public CharAdapter select(CharPredicate predicate)
Description copied from interface:CharIterableReturns a new CharIterable with all of the elements in the CharIterable that return true for the specified predicate.- Specified by:
selectin interfaceCharIterable- Specified by:
selectin interfaceCharList- Specified by:
selectin interfaceImmutableCharCollection- Specified by:
selectin interfaceImmutableCharList- Specified by:
selectin interfaceOrderedCharIterable- Specified by:
selectin interfaceReversibleCharIterable
-
reject
public CharAdapter reject(CharPredicate predicate)
Description copied from interface:CharIterableReturns a new CharIterable with all of the elements in the CharIterable that return false for the specified predicate.- Specified by:
rejectin interfaceCharIterable- Specified by:
rejectin interfaceCharList- Specified by:
rejectin interfaceImmutableCharCollection- Specified by:
rejectin interfaceImmutableCharList- Specified by:
rejectin interfaceOrderedCharIterable- Specified by:
rejectin interfaceReversibleCharIterable
-
collect
public <V> ImmutableList<V> collect(CharToObjectFunction<? extends V> function)
Description copied from interface:CharIterableReturns 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:
collectin interfaceCharIterable- Specified by:
collectin interfaceCharList- Specified by:
collectin interfaceImmutableCharCollection- Specified by:
collectin interfaceImmutableCharList- Specified by:
collectin interfaceOrderedCharIterable- Specified by:
collectin interfaceReversibleCharIterable
-
collectChar
public CharAdapter collectChar(CharToCharFunction function)
-
detectIfNone
public char detectIfNone(CharPredicate predicate, char ifNone)
- Specified by:
detectIfNonein interfaceCharIterable
-
count
public int count(CharPredicate predicate)
Description copied from interface:CharIterableReturns a count of the number of elements in the CharIterable that return true for the specified predicate.- Specified by:
countin interfaceCharIterable
-
anySatisfy
public boolean anySatisfy(CharPredicate predicate)
Description copied from interface:CharIterableReturns true if any of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
anySatisfyin interfaceCharIterable
-
allSatisfy
public boolean allSatisfy(CharPredicate predicate)
Description copied from interface:CharIterableReturns true if all of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
allSatisfyin interfaceCharIterable
-
noneSatisfy
public boolean noneSatisfy(CharPredicate predicate)
Description copied from interface:CharIterableReturns true if none of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
noneSatisfyin interfaceCharIterable
-
toList
public MutableCharList toList()
Description copied from interface:CharIterableConverts the CharIterable to a new MutableCharList.- Specified by:
toListin interfaceCharIterable- Overrides:
toListin classAbstractCharIterable
-
toSet
public MutableCharSet toSet()
Description copied from interface:CharIterableConverts the CharIterable to a new MutableCharSet.- Specified by:
toSetin interfaceCharIterable- Overrides:
toSetin classAbstractCharIterable
-
toBag
public MutableCharBag toBag()
Description copied from interface:CharIterableConverts the CharIterable to a new MutableCharBag.- Specified by:
toBagin interfaceCharIterable- Overrides:
toBagin classAbstractCharIterable
-
injectInto
public <T> T injectInto(T injectedValue, ObjectCharToObjectFunction<? super T,? extends T> function)- Specified by:
injectIntoin interfaceCharIterable
-
chunk
public RichIterable<CharIterable> chunk(int size)
Description copied from interface:CharIterablePartitions elements in fixed size chunks.- Specified by:
chunkin interfaceCharIterable- Parameters:
size- the number of elements per chunk- Returns:
- A
RichIterablecontainingCharIterables of sizesize, except the last will be truncated if the elements don't divide evenly.
-
sum
public long sum()
- Specified by:
sumin interfaceCharIterable
-
max
public char max()
- Specified by:
maxin interfaceCharIterable
-
min
public char min()
- Specified by:
minin interfaceCharIterable
-
size
public int size()
Description copied from interface:PrimitiveIterableReturns the number of items in this iterable.- Specified by:
sizein interfacePrimitiveIterable
-
appendString
public void appendString(java.lang.Appendable appendable, java.lang.String start, java.lang.String separator, java.lang.String end)Description copied from interface:PrimitiveIterablePrints a string representation of this collection onto the givenAppendable. Prints the string returned byPrimitiveIterable.makeString(String, String, String).- Specified by:
appendStringin interfacePrimitiveIterable
-
equals
public boolean equals(java.lang.Object otherList)
Description copied from interface:CharListFollows the same general contract asList.equals(Object).
-
hashCode
public int hashCode()
Description copied from interface:CharListFollows the same general contract asList.hashCode().
-
zipChar
public ImmutableList<CharCharPair> zipChar(CharIterable iterable)
Description copied from interface:ImmutableCharListReturns anImmutableListformed from thisImmutableCharListand anotherCharListby combining corresponding elements in pairs. If one of the twoCharLists is longer than the other, its remaining elements are ignored.- Specified by:
zipCharin interfaceCharList- Specified by:
zipCharin interfaceImmutableCharList- Since:
- 9.1.
-
zip
public <T> ImmutableList<CharObjectPair<T>> zip(java.lang.Iterable<T> iterable)
Description copied from interface:ImmutableCharListReturns anImmutableListformed from thisImmutableCharListand aListIterableby combining corresponding elements in pairs. If one of the two Lists is longer than the other, its remaining elements are ignored.- Specified by:
zipin interfaceCharList- Specified by:
zipin interfaceImmutableCharList- Since:
- 9.1.
-
toStack
public MutableCharStack toStack()
Description copied from interface:OrderedCharIterableConverts the collection to a CharStack.- Specified by:
toStackin interfaceOrderedCharIterable
-
-