E - type of contained elementspublic interface XGettingCollection<E> extends XIterable<E>, XJoinable<E>, ExtendedCollection<E>, Iterable<E>, CapacityCarrying, Copyable
| Modifier and Type | Interface and Description |
|---|---|
static interface |
XGettingCollection.Creator<E> |
XIterable.Executor<E>Copyable.Static| Modifier and Type | Method and Description |
|---|---|
boolean |
applies(Predicate<? super E> predicate)
Tests each element of the collection on the given predicate.
|
boolean |
contains(E element)
Checks if the given element is contained in the collection.
|
default boolean |
containsAll(XGettingCollection<? extends E> elements) |
boolean |
containsId(E element)
Special version of contains() that guarantees to use identity comparison (" == ") when searching for the
given element regardless of the collection's internal logic.
This method has the same behavior as containsSearched(Predicate) with a Predicate implementation
that checks for object identity. |
boolean |
containsSearched(Predicate<? super E> predicate) |
XGettingCollection<E> |
copy()
Creates a true copy of this collection which references the same elements as this collection does
at the time the method is called.
|
<T extends Consumer<? super E>> |
copyTo(T target)
Calls
Consumer.accept(Object) on the target Consumer for all the elements of this collection. |
long |
count(E element)
Count how many times this element matches another element in the collection
using the
Equalator. |
long |
countBy(Predicate<? super E> predicate)
Count how many matches are found using the given predicate on each element of the collection.
|
<T extends Consumer<? super E>> |
distinct(T target)
Calls
Consumer.accept(Object) on the target Consumer for all the unique/distinct
elements of this collection. |
<T extends Consumer<? super E>> |
distinct(T target,
Equalator<? super E> equalator)
Calls
Consumer.accept(Object) on the target Consumer for all the unique/distinct
elements of this collection. |
Equalator<? super E> |
equality() |
boolean |
equals(Object o)
Deprecated.
|
boolean |
equals(XGettingCollection<? extends E> samples,
Equalator<? super E> equalator) |
boolean |
equalsContent(XGettingCollection<? extends E> samples,
Equalator<? super E> equalator)
Returns
true if all elements of this list and the passed list are sequentially equal as defined
by the passed equalator. |
<T extends Consumer<? super E>> |
except(XGettingCollection<? extends E> other,
Equalator<? super E> equalator,
T target)
Calls
Consumer.accept(Object) on the target Consumer for each
element of this collection that is not contained in the other collection (through the given equalator). |
<T extends Consumer<? super E>> |
filterTo(T target,
Predicate<? super E> predicate)
Calls
Consumer.accept(Object) on the target Consumer for all the elements of this collection
which test true on the given predicate. |
E |
get()
Gets one element from the collection.
|
int |
hashCode()
Deprecated.
|
boolean |
hasVolatileElements()
Tells if this collection contains volatile elements.
An element is volatile, if it can become no longer reachable by the collection without being removed from the collection. |
XImmutableCollection<E> |
immure()
Provides an instance of an immutable collection type with equal behavior and data as this instance.
|
<T extends Consumer<? super E>> |
intersect(XGettingCollection<? extends E> other,
Equalator<? super E> equalator,
T target)
Tests equality between each element of the two lists and calls
Consumer.accept(Object) on the target Consumer for the
equal elements.Therefore it effectively creates a mathematical intersection between the two collections. |
default int |
intSize() |
Iterator<E> |
iterator() |
default <A> A |
join(BiConsumer<? super E,? super A> joiner,
A aggregate)
Iterates over all elements of the collections and calls the joiner
with each element and the aggregate.
|
E |
max(Comparator<? super E> comparator) |
E |
min(Comparator<? super E> comparator) |
boolean |
nullContained() |
OldCollection<E> |
old() |
E |
search(Predicate<? super E> predicate)
Returns the first contained element matching the passed predicate.
|
E |
seek(E sample)
Returns the first contained element matching the passed sample as defined by the collection's equality logic
or null, if no fitting element is contained.
|
long |
size() |
default Object[] |
toArray()
Returns an array containing all of the elements in this collection.
|
default E[] |
toArray(Class<E> type)
Returns a typed array containing all of the elements in this collection.
|
<T extends Consumer<? super E>> |
union(XGettingCollection<? extends E> other,
Equalator<? super E> equalator,
T target)
Calls
Consumer.accept(Object) on the target Consumer for all the elements of this collection. |
XGettingCollection<E> |
view()
Creates a view of this collection and returns it.
|
nullAllowedforEach, spliteratorisFull, maximumCapacity, remainingCapacityE get()
XGettingSequence, then it is
undefined which element is returned. If the collection is ordered, the element at index 0 is returned.default Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between MicroStream-based collections and Java-native-based APIs.
default E[] toArray(Class<E> type)
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between MicroStream-based collections and Java-native-based APIs.
type - the Class representing type E at runtime.OldCollection<E> old()
boolean hasVolatileElements()
ExtendedCollectionWeakReference of SoftReference or implementations of collection entries
that remove the element contained in an entry by some means outside the collection.WeakReference instances that are added to a a simple (non-volatile) implementation of a
collection do not make the collection volatile, as the elements themselves (the reference instances) are still
strongly referenced.hasVolatileElements in interface ExtendedCollection<E>true if the collection contains volatile elements.default int intSize()
boolean equals(XGettingCollection<? extends E> samples, Equalator<? super E> equalator)
equalator - is used to check the equality of the collectionssamples - is the collection which is checked for equalitytrue if the passed collection is of the same type as this collection and
this.equalsContent(list, equalator) yields trueboolean equalsContent(XGettingCollection<? extends E> samples, Equalator<? super E> equalator)
true if all elements of this list and the passed list are sequentially equal as defined
by the passed equalator.
Note that for colletion types that don't have a defined order of elements, this method is hardly usable
(as is equals(Object) for them as defined in Collection). The core problem of comparing
collections that have no defined order is that they aren't really reliably comparable to any other collection.
equalator - the equalator to use to determine the equality of each elementsamples - is the collection which is checked for equalitytrue if this list is equal to the passed list, false otherwiseXImmutableCollection<E> immure()
If this instance already is of an immutable collection type, it returns itself.
XGettingCollection<E> view()
A view is different from immutable collection (immure())
in the way, that changes in this collection are still affecting the view.
The immutable collection on the other hand has no reference to this collection
and changes therefore do not affect the immutable collection.
XGettingCollection<E> copy()
boolean nullContained()
boolean containsId(E element)
containsSearched(Predicate) with a Predicate implementation
that checks for object identity. The only difference is a performance and usability advantageelement - the element to be searched in the collection by identity.boolean contains(E element)
containsId(Object) method, this method
uses the internal Equalator defined by the collection itself.element - to be searched in the collectionEqualator.default boolean containsAll(XGettingCollection<? extends E> elements)
elements - to be searched in the collection.Equalator.boolean applies(Predicate<? super E> predicate)
predicate - that's tested on each element.long count(E element)
Equalator.element - to countlong countBy(Predicate<? super E> predicate)
predicate - defines which elements are counted and which are notE search(Predicate<? super E> predicate)
predicate - defines which element is searchedE seek(E sample)
contains(Object) with a different return type. For collections with data-dependant equality,
the returned element might be the same as the passed one or a data-wise equal one, depending on the content
of the collection)sample - to seek in the collectionE max(Comparator<? super E> comparator)
E min(Comparator<? super E> comparator)
<T extends Consumer<? super E>> T distinct(T target)
Consumer.accept(Object) on the target Consumer for all the unique/distinct
elements of this collection. This means the elements are not equal to each other.Equalator.
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,2,3);
BulkList<Integer> distinctCollection = collection1.distinct(BulkList.New());
Results in distinctCollection containing 1, 2 and 3.
T - type of the targettarget - on which the Consumer.accept(Object) is called for every distinct element of this collection.<T extends Consumer<? super E>> T distinct(T target, Equalator<? super E> equalator)
Consumer.accept(Object) on the target Consumer for all the unique/distinct
elements of this collection. This means the elements are not equal to each other.Equalator.
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,2,3); BulkList<Integer> distinctCollection = collection1.distinct(BulkList.New(), Equalator.identity());Results in
distinctCollection containing 1, 2 and 3.T - type of the targettarget - on which the Consumer.accept(Object) is called for every distinct element of this collection.equalator - defines what distinct means (which elements are equal to one another)<T extends Consumer<? super E>> T copyTo(T target)
Consumer.accept(Object) on the target Consumer for all the elements of this collection.
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,3); BulkList<Integer> copiedCollection = collection1.copyTo(BulkList.New());Results in
copiedCollection containing 1, 2 and 3.T - type of the targettarget - on which the Consumer.accept(Object) is called for all elements of this collection.<T extends Consumer<? super E>> T filterTo(T target, Predicate<? super E> predicate)
Consumer.accept(Object) on the target Consumer for all the elements of this collection
which test true on the given predicate.
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,3); BulkList<Integer> filteredCollection = collection1.filterTo(BulkList.New(), e-> e % 2 == 0);Results in
filteredCollection containing 2.T - type of the targettarget - on which the Consumer.accept(Object) is called for elements that test true.predicate - on which to test all elements.<T extends Consumer<? super E>> T union(XGettingCollection<? extends E> other, Equalator<? super E> equalator, T target)
Consumer.accept(Object) on the target Consumer for all the elements of this collection.
And calls it for all elements of the other collection, that are not already in this collection
(defined by the given Equalator)
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,3); BulkList<Integer> collection2 = BulkList.New(2,3,4); BulkList<Integer> union = collection1.union(collection2, Equalator.identity(), BulkList.New());Results in
union containing 1, 2, 3 and 4.T - type of the targetother - collection to build a union with.equalator - which is used for the equal-tests.target - on which the Consumer.accept(Object) is called for all unified elements.<T extends Consumer<? super E>> T intersect(XGettingCollection<? extends E> other, Equalator<? super E> equalator, T target)
Consumer.accept(Object) on the target Consumer for the
equal elements.
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,3); BulkList<Integer> collection2 = BulkList.New(2,3,4); BulkList<Integer> intersection = collection1.intersect(collection2, Equalator.identity(), BulkList.New());Results in
intersection containing 2 and 3.T - type of the targetother - collection to intersect with.equalator - which is used for the equal-tests.target - on which the Consumer.accept(Object) is called for equal elements.<T extends Consumer<? super E>> T except(XGettingCollection<? extends E> other, Equalator<? super E> equalator, T target)
Consumer.accept(Object) on the target Consumer for each
element of this collection that is not contained in the other collection (through the given equalator).
Since all MicroStream Collections implement the Consumer interface,
new collections can be used as target.
Example:
BulkList<Integer> collection1 = BulkList.New(1,2,3); BulkList<Integer> collection2 = BulkList.New(2,3,4); BulkList<Integer> exceptCollection = collection1.except(collection2, Equalator.identity(), BulkList.New());Results in
exceptCollection containing 1.T - type of the targetother - collection whose elements are excluded from the target.equalator - which is used for the equal-tests.target - on which the Consumer.accept(Object) is called for elements not contained in the other collection.default <A> A join(BiConsumer<? super E,? super A> joiner, A aggregate)
XJoinable@Deprecated boolean equals(Object o)
Collection.
Note that it is this interface's author opinion that the whole concept of equals() in standard Java, especially
in the collection implementations, is flawed.
The reason is because all different kinds of comparison types that actually depend on the situation
have to be mixed up in a harcoded fashion in one method, from identity comparison over
data indentity comparison to content comparison.
In order to get the right behavior in every situation, one has to distinct between different types of equality
This means several things:
1.) You can't just say for example an ArrayList is the "same" as a LinkedList just because they contain the
same content.
There are different implementations for a good reason, so you have to distinct them when comparing.
There are simple code examples which create massive misbehavior that will catastrophically ruin the runtime
behavior of a programm due to this error in Java / JDK / Sun / whatever.
2.) You can't always determine equality of two collections by determining equality of each element as
Collection defines it.
As a conclusion: don't use this method!
Be clear what type of comparison you really need, then use one of the following methods
and proper comparators:
equals(XGettingCollection, Equalator)
equalsContent(XGettingCollection, Equalator)
@Deprecated int hashCode()
Copyright © 2022 MicroStream Software. All rights reserved.