A mapped view over a collection.
Definition at line 21 of file MappedCollectionImpl.java.
◆ MappedCollectionImpl()
◆ add() [1/2]
Adds the specified element to this collection
◆ add() [2/2]
◆ addAll()
Adds all the specified elements to this collection.
Definition at line 46 of file CollectionView.java.
47 boolean changed =
false;
48 Iterator<? extends E> it = c.iterator();
49 while (it.hasNext()) {
50 if (
add(it.next())) changed =
true;
◆ clear()
◆ clone()
Returns a copy of this collection; updates of the copy should not impact the original.
Definition at line 66 of file CollectionView.java.
68 CollectionView<E> copy = (CollectionView<E>) super.clone();
70 copy.target =
target.clone();
73 }
catch (CloneNotSupportedException e) {
74 throw new Error(
"Should not happen since target is cloneable");
◆ comparator()
◆ contains()
Indicates if this collection contains the specified element.
Definition at line 83 of file CollectionView.java.
84 Iterator<? extends E> it =
iterator();
85 Equality<Object> cmp = (Equality<Object>)
comparator();
86 while (it.hasNext()) {
87 if (cmp.areEqual(obj, it.next()))
return true;
◆ containsAll()
Indicates if this collection contains all the specified elements.
Definition at line 93 of file CollectionView.java.
◆ equals()
Compares the specified object with this collection for equality. This method follows the Collection#equals(Object) specification if this collection comparator is Equalities#STANDARD (default). Otherwise, only collections using the same comparator can be considered equals.
- Parameters
-
obj | the object to be compared for equality with this collection |
- Returns
true
if both collections are considered equals; false
otherwise.
Definition at line 102 of file CollectionView.java.
104 if (
this == o)
return true;
106 if (o instanceof CollectionService) {
112 if (
this instanceof Set) {
113 if (!(o instanceof Set))
return false;
114 Set<E>
set = (Set<E>) o;
116 }
else if (
this instanceof List) {
117 if (!(o instanceof List))
return false;
118 List<E> list = (List<E>) o;
119 if (
size() != list.size())
return false;
122 Iterator<E> it2 = list.iterator();
123 while (it1.hasNext()) {
124 if (!it2.hasNext())
return false;
125 if (!cmp.areEqual(it1.next(), it2.next()))
return false;
127 if (it2.hasNext())
return false;
◆ hashCode()
Returns the hash code of this collection. This method follows the Collection#hashCode() specification if this collection comparator is Equalities#STANDARD.
- Returns
- this collection hash code.
Definition at line 135 of file CollectionView.java.
140 if (
this instanceof Set) {
141 while (it.hasNext()) {
142 hash += cmp.hashCodeOf(it.next());
144 }
else if (
this instanceof List) {
145 while (it.hasNext()) {
146 hash += 31 * hash + cmp.hashCodeOf(it.next());
149 hash = super.hashCode();
◆ isEmpty()
◆ iterator()
◆ perform()
◆ remove()
Removes the specified element from this collection.
Definition at line 173 of file CollectionView.java.
174 Iterator<? extends E> it =
iterator();
175 Equality<Object> cmp = (Equality<Object>)
comparator();
176 while (it.hasNext()) {
177 if (cmp.areEqual(obj, it.next())) {
◆ removeAll()
Removes all the specified element from this collection.
Definition at line 186 of file CollectionView.java.
187 boolean changed =
false;
188 Iterator<? extends E> it =
iterator();
189 while (it.hasNext()) {
190 if (c.contains(it.next())) {
◆ retainAll()
Removes all the elements except those in the specified collection.
Definition at line 199 of file CollectionView.java.
200 boolean changed =
false;
201 Iterator<? extends E> it =
iterator();
202 while (it.hasNext()) {
203 if (!c.contains(it.next())) {
◆ service()
Returns the service implementation of this collection (for sub-classes).
Definition at line 274 of file CollectionView.java.
◆ size()
◆ split()
Returns
distinct parts of this object. This method may return an array of size less than
(e.g. an array of size one if this object cannot split).
- Parameters
-
- Returns
- the distinct parts (or views) for this object.
- Exceptions
-
IllegalArgumentException | if |
Definition at line 224 of file CollectionView.java.
225 if (
target ==
null)
return new CollectionService[] {
this };
226 CollectionService<E>[] subTargets =
target.split(n);
227 CollectionService<E>[] result =
new CollectionService[subTargets.length];
228 for (
int i = 0; i < subTargets.length; i++) {
229 CollectionView<E> copy = this.
clone();
230 copy.target = subTargets[i];
◆ target()
◆ threadSafe()
Returns a thread-safe version of this service (used during parallel updates).
Definition at line 237 of file CollectionView.java.
239 return new SharedCollectionImpl<E>(
this);
◆ toArray() [1/2]
◆ toArray() [2/2]
Returns the specified array holding this collection elements if enough capacity.
Definition at line 249 of file CollectionView.java.
251 final T[] result = (
size <= a.length) ? a
252 : (T[]) java.lang.reflect.Array.newInstance(a.getClass()
253 .getComponentType(),
size);
256 while (it.hasNext()) {
257 result[i++] = (T) it.next();
259 if (result.length >
size) {
◆ update()
◆ function
◆ serialVersionUID
◆ target
The documentation for this class was generated from the following file: