Interface CIterable<E>
-
- All Superinterfaces:
CBaseState<java.lang.Iterable<E>>
,CBaseVerifier<java.lang.Iterable<E>>
,CBaseWaiter<java.lang.Iterable<E>>
,CIterableState<E>
,CIterableVerifier<E>
,CObjectState<java.lang.Iterable<E>>
,CObjectVerifier<java.lang.Iterable<E>,CIterableState<E>>
,java.lang.Iterable<E>
,java.io.Serializable
- All Known Subinterfaces:
CCollection<E>
- All Known Implementing Classes:
CConfigInfoCollection
,CList
,CSet
public interface CIterable<E> extends java.lang.Iterable<E>, CIterableVerifier<E>, CIterableState<E>
This interfaceCIterable
uses to extendCollection
interface to facilitate testing and reduce coding. We hope to extend this class with more useful methods.- See Also:
Map
,CHashMap
,CLinkedMap
,CSet
,CList
-
-
Field Summary
-
Fields inherited from interface org.catools.common.extensions.states.interfaces.CBaseState
serialVersionUID
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
equals(java.lang.Object c)
Returnstrue
if this collection equals the specified collection.default void
forEach(java.util.function.Consumer<? super E> action)
Performs the given action for each element of theIterable
until all elements have been processed or the action throws an exception.default CList<E>
getAll(java.util.function.Predicate<E> predicate)
Returns CCliItemCollection sequance of values which matched thepredicate
.default E
getAny()
get a random value from the collection.default E
getFirst()
Returns a first element from list.default E
getFirst(java.util.function.Predicate<E> predicate)
Returns a first element from list which matched thepredicate
otherwise throwsNoSuchElementException
.default E
getFirstOrAny(java.util.function.Predicate<E> predicate)
Returns CCliItemCollection first element from list which matched thepredicate
otherwise returns any value.default E
getFirstOrElse(E other)
Returns a first element from list if the list is not empty otherwise returnsother
value.default E
getFirstOrElse(java.util.function.Predicate<E> predicate, E other)
Returns a first element from list which matched thepredicate
otherwise returnsother
value.default E
getFirstOrElse(java.util.function.Predicate<E> predicate, java.util.function.Supplier<E> other)
Returns a first element from list which matched thepredicate
otherwise returnsother
value.default E
getFirstOrNull()
Returns a first element from list if the list is not empty otherwise returnsnull
value.default E
getFirstOrNull(java.util.function.Predicate<E> predicate)
Returns CCliItemCollection first element from list which matched thepredicate
otherwise returnsnull
value.default E
getFirstOrThrow(java.lang.RuntimeException e)
Returns CCliItemCollection first element from list if the list is not empty otherwise throwsRuntimeException
.default <X extends java.lang.RuntimeException>
EgetFirstOrThrow(java.util.function.Predicate<E> predicate, java.util.function.Supplier<? extends X> exceptionSupplier)
Returns CCliItemCollection first element from list which matched thepredicate
otherwise throwsRuntimeException
.default boolean
has(java.util.function.Predicate<E> predicate)
Indicate ifpredicate
condition returns true for any record in the list The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
hasNot(Predicate)
default boolean
hasNot(java.util.function.Predicate<E> predicate)
Indicate ifpredicate
condition returns false for all records in the list The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
has(Predicate)
java.util.Iterator<E>
iterator()
Returns an iterator over the elements in this collection.default java.lang.String
join()
Joins the elements ofCCollection
into CCliItemCollection single String containing the provided elements.default java.lang.String
join(java.lang.String separator)
Joins the elements ofCCollection
into CCliItemCollection single String containing the provided elements.default java.lang.String
join(java.util.function.Function<? super E,? extends java.lang.String> mapper, java.lang.String separator)
Joins the elements ofCCollection
into CCliItemCollection single String containing the provided elements.default <R> java.util.stream.Stream<R>
map(java.util.function.Function<? super E,? extends R> mapper)
Returns CCliItemCollection stream consisting of the results of applying the given function to the elements of this stream.default <R> CList<R>
mapToList(java.util.function.Function<? super E,? extends R> mapper)
Returns CCliItemCollectionCList
consisting of the results of applying the given function to the elements of theCCollection
.default <R> CSet<R>
mapToSet(java.util.function.Function<? super E,? extends R> mapper)
Returns CCliItemCollectionCSet
consisting of the results of applying the given function to the elements of theCCollection
.default java.util.Spliterator<E>
spliterator()
Creates CCliItemCollectionSpliterator
over the elements in this collection.default java.util.stream.Stream<E>
stream()
Returns CCliItemCollection sequentialStream
with this collection as its source.default CList<E>
toList()
ConvertCCollection
toCList
and return the resultdefault CSet<E>
toSet()
ConvertCCollection
toCSet
and return the result-
Methods inherited from interface org.catools.common.extensions.states.interfaces.CBaseState
getBaseValue
-
Methods inherited from interface org.catools.common.extensions.verify.interfaces.CBaseVerifier
_useWaiter, _verify, _verify, _verify, _verify, _verify, _verify, _verify, _verify, _verify, getDefaultMessage, getDefaultMessage, getVerifyMessagePrefix
-
Methods inherited from interface org.catools.common.extensions.wait.interfaces.CBaseWaiter
getDefaultWaitInSeconds, getDefaultWaitIntervalInMilliSeconds
-
Methods inherited from interface org.catools.common.extensions.states.interfaces.CIterableState
contains, containsAll, containsNone, containsNone, emptyOrContains, emptyOrNotContains, isEmpty, isEqual, isEqual, isNotEmpty, notContains, notContainsAll, notContainsAll
-
Methods inherited from interface org.catools.common.extensions.verify.interfaces.CIterableVerifier
_toState, verifyContains, verifyContains, verifyContainsAll, verifyContainsAll, verifyContainsNone, verifyContainsNone, verifyEmptyOrContains, verifyEmptyOrContains, verifyEmptyOrNotContains, verifyEmptyOrNotContains, verifyEquals, verifyEquals, verifyHas, verifyHas, verifyIsEmpty, verifyIsEmpty, verifyIsNotEmpty, verifyIsNotEmpty, verifyNotContains, verifyNotContains, verifyNotContainsAll, verifyNotContainsAll
-
Methods inherited from interface org.catools.common.extensions.states.interfaces.CObjectState
equalsAny, equalsAny, equalsNone, equalsNone, isNotNull, isNull, notEqual, test
-
Methods inherited from interface org.catools.common.extensions.verify.interfaces.CObjectVerifier
verifyEqualsAny, verifyEqualsAny, verifyEqualsNone, verifyEqualsNone, verifyIsNotNull, verifyIsNotNull, verifyIsNull, verifyIsNull, verifyNotEquals, verifyNotEquals
-
-
-
-
Method Detail
-
equals
boolean equals(java.lang.Object c)
Returnstrue
if this collection equals the specified collection.- Overrides:
equals
in classjava.lang.Object
- Parameters:
c
- collection to be checked for equality- Returns:
true
if this collection contains none of the elements in the specified collection- Throws:
java.lang.ClassCastException
- if the collections of one or more elements in the specified collection are incompatible with this collectionjava.lang.NullPointerException
- if the specified collection contains one or more null elements and this collection does not permit null elements , or if the specified collection is null.- See Also:
CIterableState.contains(Object)
-
forEach
default void forEach(java.util.function.Consumer<? super E> action)
Performs the given action for each element of theIterable
until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified CCliItemCollection concurrent modification policy.
- Specified by:
forEach
in interfacejava.lang.Iterable<E>
- Parameters:
action
- The action to be performed for each element- Throws:
java.lang.NullPointerException
- if the specified action is nullfor (T t : this) action.accept(t);
-
getAll
default CList<E> getAll(java.util.function.Predicate<E> predicate)
Returns CCliItemCollection sequance of values which matched thepredicate
.- Parameters:
predicate
- to issue condition- Returns:
- the non-
null
collection of value described by thisOptional
-
getAny
default E getAny()
get a random value from the collection.- Returns:
- random value or null if no value available
-
getFirst
default E getFirst()
Returns a first element from list.- Returns:
- Returns a first element from list.
-
getFirst
default E getFirst(java.util.function.Predicate<E> predicate)
Returns a first element from list which matched thepredicate
otherwise throwsNoSuchElementException
. The preferred alternative to this method isgetFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Parameters:
predicate
- to issue condition- Returns:
- the non-
null
value described by thisOptional
- Throws:
java.util.NoSuchElementException
- if no value is present
-
getFirstOrElse
default E getFirstOrElse(E other)
Returns a first element from list if the list is not empty otherwise returnsother
value. The preferred alternative to this method isgetFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Parameters:
other
- value to be return if not record found- Returns:
- the non-
null
value described by thisOptional
-
getFirstOrElse
default E getFirstOrElse(java.util.function.Predicate<E> predicate, E other)
Returns a first element from list which matched thepredicate
otherwise returnsother
value. The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Parameters:
predicate
- to issue conditionother
- value to be turn if no matched found- Returns:
- the non-
null
value described by thisOptional
-
getFirstOrNull
default E getFirstOrNull()
Returns a first element from list if the list is not empty otherwise returnsnull
value. The preferred alternative to this method isgetFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Returns:
- the non-
null
value described by thisOptional
-
getFirstOrNull
default E getFirstOrNull(java.util.function.Predicate<E> predicate)
Returns CCliItemCollection first element from list which matched thepredicate
otherwise returnsnull
value. The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Parameters:
predicate
- to issue condition- Returns:
- the non-
null
value described by thisOptional
-
getFirstOrAny
default E getFirstOrAny(java.util.function.Predicate<E> predicate)
Returns CCliItemCollection first element from list which matched thepredicate
otherwise returns any value. The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Parameters:
predicate
- to issue condition- Returns:
- the non-
null
value described by thisOptional
-
getFirstOrThrow
default E getFirstOrThrow(java.lang.RuntimeException e)
Returns CCliItemCollection first element from list if the list is not empty otherwise throwsRuntimeException
. The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,#getFirstOrThrow(Predicate, RuntimeException)
.- Parameters:
e
- exception to be throws if no record found- Returns:
- the non-
null
value described by thisOptional
- Throws:
java.lang.RuntimeException
- if no value is present
-
getFirstOrThrow
default <X extends java.lang.RuntimeException> E getFirstOrThrow(java.util.function.Predicate<E> predicate, java.util.function.Supplier<? extends X> exceptionSupplier)
Returns CCliItemCollection first element from list which matched thepredicate
otherwise throwsRuntimeException
. The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,- Parameters:
predicate
- to issue conditionexceptionSupplier
- the supplying function that produces an exception to be thrown- Returns:
- the non-
null
value described by thisOptional
- Throws:
java.lang.RuntimeException
- if no value is present
-
getFirstOrElse
default E getFirstOrElse(java.util.function.Predicate<E> predicate, java.util.function.Supplier<E> other)
Returns a first element from list which matched thepredicate
otherwise returnsother
value. The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrThrow(RuntimeException)
,getFirstOrThrow(Predicate, Supplier)
,- Parameters:
predicate
- to issue conditionother
- supplier to be call if not match found- Returns:
- the non-
null
value described by thisOptional
-
has
default boolean has(java.util.function.Predicate<E> predicate)
Indicate ifpredicate
condition returns true for any record in the list The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
hasNot(Predicate)
- Specified by:
has
in interfaceCIterableState<E>
- Parameters:
predicate
- to issue condition- Returns:
- true if
predicate
condition returns true for any record in the list otherwise return false
-
hasNot
default boolean hasNot(java.util.function.Predicate<E> predicate)
Indicate ifpredicate
condition returns false for all records in the list The preferred alternative to this method isgetFirst()
,getFirstOrElse(Object)
,getFirstOrElse(Predicate, Object)
,getFirstOrThrow(RuntimeException)
,#getFirstOrThrow(Predicate, RuntimeException)
has(Predicate)
- Specified by:
hasNot
in interfaceCIterableState<E>
- Parameters:
predicate
- to issue condition- Returns:
- true if
predicate
condition returns false for all records in the list otherwise return false
-
iterator
java.util.Iterator<E> iterator()
Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides CCliItemCollection guarantee).- Specified by:
iterator
in interfacejava.lang.Iterable<E>
- Returns:
- an
Iterator
over the elements in this collection
-
join
default java.lang.String join()
Joins the elements of
CCollection
into CCliItemCollection single String containing the provided elements.No delimiter is added before or after the list.
See the examples here:
join(String)
.- Returns:
- the joined String with no separator
-
join
default java.lang.String join(java.lang.String separator)
Joins the elements of
CCollection
into CCliItemCollection single String containing the provided elements.No delimiter is added before or after the list. A
null
separator is the same as an empty String (CStringUtil.EMPTY).See the examples here:
join(String)
.- Parameters:
separator
- the separator character to use, null treated as CStringUtil.EMPTY- Returns:
- the joined String separated by separator
-
join
default java.lang.String join(java.util.function.Function<? super E,? extends java.lang.String> mapper, java.lang.String separator)
Joins the elements of
CCollection
into CCliItemCollection single String containing the provided elements.No delimiter is added before or after the list. A
null
separator is the same as an empty String (CStringUtil.EMPTY).See the examples here:
join(String)
.- Parameters:
mapper
- the mapper to use, null treated as CStringUtil.EMPTYseparator
- the separator character to use, null treated as CStringUtil.EMPTY- Returns:
- the joined String separated by separator
-
map
default <R> java.util.stream.Stream<R> map(java.util.function.Function<? super E,? extends R> mapper)
Returns CCliItemCollection stream consisting of the results of applying the given function to the elements of this stream.- Type Parameters:
R
- The element type of the new stream- Parameters:
mapper
- function to apply to each element- Returns:
- the new stream
-
mapToList
default <R> CList<R> mapToList(java.util.function.Function<? super E,? extends R> mapper)
Returns CCliItemCollectionCList
consisting of the results of applying the given function to the elements of theCCollection
.- Type Parameters:
R
- The element type of the newCList
- Parameters:
mapper
- function to apply to each element- Returns:
- the new
CList
-
mapToSet
default <R> CSet<R> mapToSet(java.util.function.Function<? super E,? extends R> mapper)
Returns CCliItemCollectionCSet
consisting of the results of applying the given function to the elements of theCCollection
.- Type Parameters:
R
- The element type of the newCSet
- Parameters:
mapper
- function to apply to each element- Returns:
- the new
CSet
-
spliterator
default java.util.Spliterator<E> spliterator()
Creates CCliItemCollectionSpliterator
over the elements in this collection. Implementations should document characteristic values reported by the spliterator. Such characteristic values are not required to be reported if the spliterator reportsSpliterator.SIZED
and this collection contains no elements.- Specified by:
spliterator
in interfacejava.lang.Iterable<E>
- Returns:
- CCliItemCollection
Spliterator
over the elements in this collection
-
stream
default java.util.stream.Stream<E> stream()
Returns CCliItemCollection sequentialStream
with this collection as its source.This method should be overridden when the
spliterator()
method cannot return CCliItemCollection spliterator that isIMMUTABLE
,CONCURRENT
, or late-binding. (Seespliterator()
for details.)- Returns:
- CCliItemCollection sequential
Stream
over the elements in this collection
-
toList
default CList<E> toList()
ConvertCCollection
toCList
and return the result- Returns:
- get
CList
from elements ofCCollection
and return the result
-
-