java.lang.Object
me.sbasalaev.collection.Collection<T>
- All Implemented Interfaces:
Cloneable,Iterable<T>,Traversable<T>
Collection of elements.
This is a base class for different types of collections
such as lists or sets.
Collections have known size at any time.
Every collection has a notion
of equality though that notion
depends on the type of the collection.
Collection may be cloned to obtain a
shallow immutable copy of the collection of the same type.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Collection<T> clone()Returns a shallow copy of this collection.intcount()Number of elements in this collection.abstract booleanWhether given object is equal to this collection.voidFills array with elements of this collection starting from given index in array.abstract Collection<T> Returns collection of the same type containing only elements matching given condition.abstract inthashCode()Hash code of the collection.booleanisEmpty()Whether this collection has no elements.abstract <R> Collection<R> Returns collection of the same type with given mapping applied to all elements.booleannonEmpty()Whether this collection contains elements.abstract intsize()Number of elements in this collection.abstract Spliterator<T> Creates aSpliteratorover elements of this collection.stream()Returns a sequentialStreamwith this collection as its source.Object[]toArray()Allocates and returns array with the elements of this collection.T[]toArray(IntFunction<@Out T[]> arraySupplier) Allocates and returns array with the elements of this collection.toList()Collects elements of this traversable into an immutable list.toSet()Collects elements of this traversable into an immutable set.toString()String representation of this collection.
-
Constructor Details
-
Collection
public Collection()Constructor for subclasses.
-
-
Method Details
-
size
public abstract int size()Number of elements in this collection. UnlikeTraversable.count()this method is guaranteed to be fast. -
count
public int count()Number of elements in this collection. Returns the same value assize().- Specified by:
countin interfaceTraversable<T>
-
isEmpty
public boolean isEmpty()Description copied from interface:TraversableWhether this collection has no elements.- Specified by:
isEmptyin interfaceTraversable<T>
-
nonEmpty
public boolean nonEmpty()Description copied from interface:TraversableWhether this collection contains elements.- Specified by:
nonEmptyin interfaceTraversable<T>
-
mapped
Returns collection of the same type with given mapping applied to all elements. The collection is immutable and is unaffected by changes to this collection. -
filtered
Returns collection of the same type containing only elements matching given condition. The collection is immutable and is unaffected by changes to this collection. -
toArray
Allocates and returns array with the elements of this collection. -
toArray
Allocates and returns array with the elements of this collection. -
fillArray
Fills array with elements of this collection starting from given index in array.- Throws:
IndexOutOfBoundsException- if the collection does not fit into given array.
-
spliterator
Creates aSpliteratorover elements of this collection. The spliterator reportsSpliterator.NONNULLandSpliterator.SIZED.- Specified by:
spliteratorin interfaceIterable<T>
-
stream
Returns a sequentialStreamwith this collection as its source.- Since:
- 4.1
-
clone
Returns a shallow copy of this collection. The returned collection is immutable, has the same type and contains the same elements. If the collection is ordered, the elements in a copy are in the same order. The collection is allowed to return itself if it is immutable. -
toList
Description copied from interface:TraversableCollects elements of this traversable into an immutable list.- Specified by:
toListin interfaceTraversable<T>
-
toSet
Description copied from interface:TraversableCollects elements of this traversable into an immutable set.- Specified by:
toSetin interfaceTraversable<T>
-
equals
Whether given object is equal to this collection. Different collections have different notions of equality. -
hashCode
public abstract int hashCode()Hash code of the collection. Different collections have different ways to calculate the hash code. -
toString
String representation of this collection. Returns string of the form{e1, e2, ..., eN}where elements are in the order returned by iterator.
-