Javolution 6.0.0 java
javolution.util.internal.map.MapView< K, V >.KeySet Class Reference
Inheritance diagram for javolution.util.internal.map.MapView< K, V >.KeySet:
[legend]
Collaboration diagram for javolution.util.internal.map.MapView< K, V >.KeySet:
[legend]

Public Member Functions

 KeySet ()
 
boolean add (K key)
 
Equality<? super K > comparator ()
 
boolean contains (Object obj)
 
boolean remove (Object obj)
 
abstract boolean add (R r)
 
abstract boolean add (E element)
 
SetService< R > threadSafe ()
 
void clear ()
 
boolean isEmpty ()
 
Iterator< R > iterator ()
 
int size ()
 
boolean addAll (Collection<? extends E > c)
 
CollectionView< E > clone ()
 
CollectionService< E > clone () throws CloneNotSupportedException
 
boolean containsAll (Collection<?> c)
 
boolean equals (Object o)
 
int hashCode ()
 
void perform (Consumer< CollectionService< E >> action, CollectionService< E > view)
 
void perform (Consumer< T > action, T part)
 
boolean removeAll (Collection<?> c)
 
boolean retainAll (Collection<?> c)
 
CollectionService< E >[] split (int n)
 
T[] split (int n)
 
Object[] toArray ()
 
void update (Consumer< CollectionService< E >> action, CollectionService< E > view)
 
void update (Consumer< T > action, T part)
 

Protected Member Functions

CollectionService< E > target ()
 
CollectionService< E > service ()
 

Protected Attributes

final Function<? super E, ? extends R > function
 

Package Functions

public< T > T[] toArray (T[] a)
 

Private Attributes

CollectionService< E > target
 

Static Private Attributes

static final long serialVersionUID = MapView.serialVersionUID
 

Detailed Description

Key Set View

Definition at line 153 of file MapView.java.

Constructor & Destructor Documentation

◆ KeySet()

javolution.util.internal.map.MapView< K, V >.KeySet.KeySet ( )

Definition at line 156 of file MapView.java.

156  {
157  super(entrySet(), new Function<Entry<K, V>, K>() {
158  @Override
159  public K apply(Map.Entry<K, V> e) {
160  return e.getKey();
161  }
162  });
163 
164  }

References javolution.util.internal.map.MapView< K, V >.entrySet().

Here is the call graph for this function:

Member Function Documentation

◆ add() [1/3]

abstract boolean javolution.util.internal.collection.CollectionView< E >.add ( element)
abstractinherited

Adds the specified element to this collection

◆ add() [2/3]

boolean javolution.util.internal.map.MapView< K, V >.KeySet.add ( key)

Definition at line 167 of file MapView.java.

167  { // Supports adding new key with null value.
168  if (containsKey(key)) return false;
169  put(key, null);
170  return true;
171  }

References javolution.util.internal.map.MapView< K, V >.containsKey(), and javolution.util.internal.map.MapView< K, V >.put().

Here is the call graph for this function:

◆ add() [3/3]

abstract boolean javolution.util.internal.set.MappedSetImpl< E, R >.add ( r)
abstractinherited

◆ addAll()

boolean javolution.util.internal.collection.CollectionView< E >.addAll ( Collection<? extends E >  that)
inherited

Adds all the specified elements to this collection.

Definition at line 46 of file CollectionView.java.

46  {
47  boolean changed = false;
48  Iterator<? extends E> it = c.iterator();
49  while (it.hasNext()) {
50  if (add(it.next())) changed = true;
51  }
52  return changed;
53  }

◆ clear()

Definition at line 66 of file MappedCollectionImpl.java.

66  {
67  target().clear();
68  }

◆ clone() [1/2]

◆ clone() [2/2]

Returns a copy of this collection; updates of the copy should not impact the original.

Definition at line 66 of file CollectionView.java.

66  {
67  try {
68  CollectionView<E> copy = (CollectionView<E>) super.clone();
69  if (target != null) { // Not a root class.
70  copy.target = target.clone();
71  }
72  return copy;
73  } catch (CloneNotSupportedException e) {
74  throw new Error("Should not happen since target is cloneable");
75  }
76  }

◆ comparator()

Equality<? super K> javolution.util.internal.map.MapView< K, V >.KeySet.comparator ( )

Reimplemented from javolution.util.internal.collection.MappedCollectionImpl< E, R >.

Definition at line 174 of file MapView.java.

174  {
175  return keyComparator();
176  }

References javolution.util.internal.map.MapView< K, V >.keyComparator().

Here is the call graph for this function:

◆ contains()

boolean javolution.util.internal.map.MapView< K, V >.KeySet.contains ( Object  obj)

Reimplemented from javolution.util.internal.set.MappedSetImpl< E, R >.

Definition at line 180 of file MapView.java.

180  {
181  return containsKey((K) obj);
182  }

References javolution.util.internal.map.MapView< K, V >.containsKey().

Here is the call graph for this function:

◆ containsAll()

boolean javolution.util.internal.collection.CollectionView< E >.containsAll ( Collection<?>  that)
inherited

Indicates if this collection contains all the specified elements.

Definition at line 93 of file CollectionView.java.

93  {
94  for (Object e : c) {
95  if (!contains(e)) return false;
96  }
97  return true;
98  }

◆ equals()

boolean javolution.util.internal.collection.CollectionView< E >.equals ( Object  obj)
inherited

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
objthe 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.

102  {
103  // Follow Collection.equals specification if this comparator is standard.
104  if (this == o) return true;
105  // Check comparators consistency.
106  if (o instanceof CollectionService) {
107  if (!comparator().equals(((CollectionService<E>) o).comparator())) return false; // Different comparators.
108  } else {
109  if (!comparator().equals(Equalities.STANDARD)) return false;
110  }
111  // Collection.equals contract.
112  if (this instanceof Set) {
113  if (!(o instanceof Set)) return false;
114  Set<E> set = (Set<E>) o;
115  return (size() == set.size()) && containsAll(set);
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; // Short-cut.
120  Equality<? super E> cmp = comparator();
121  Iterator<E> it1 = this.iterator();
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;
126  }
127  if (it2.hasNext()) return false;
128  return true;
129  } else {
130  return false;
131  }
132  }

◆ hashCode()

int javolution.util.internal.collection.CollectionView< E >.hashCode ( )
inherited

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.

135  {
136  // Follow Collection.equals specification if this comparator is standard.
137  Equality<? super E> cmp = comparator();
138  Iterator<E> it = this.iterator();
139  int hash = 0;
140  if (this instanceof Set) {
141  while (it.hasNext()) {
142  hash += cmp.hashCodeOf(it.next());
143  }
144  } else if (this instanceof List) {
145  while (it.hasNext()) {
146  hash += 31 * hash + cmp.hashCodeOf(it.next());
147  }
148  } else {
149  hash = super.hashCode();
150  }
151  return hash;
152  }

◆ isEmpty()

boolean javolution.util.internal.collection.MappedCollectionImpl< E, R >.isEmpty ( )
inherited

Definition at line 76 of file MappedCollectionImpl.java.

76  {
77  return target().isEmpty();
78  }

◆ iterator()

Iterator<R> javolution.util.internal.collection.MappedCollectionImpl< E, R >.iterator ( )
inherited

Definition at line 81 of file MappedCollectionImpl.java.

81  {
82  return new IteratorImpl();
83  }

◆ perform() [1/2]

void javolution.util.internal.collection.CollectionView< E >.perform ( Consumer< CollectionService< E >>  action,
CollectionService< E >  view 
)
inherited

Definition at line 163 of file CollectionView.java.

163  {
164  if (target == null) {
165  action.accept(view);
166  } else {
167  target.perform(action, view);
168  }
169  }

◆ perform() [2/2]

void javolution.util.function.Splittable< T >.perform ( Consumer< T >  action,
part 
)
inherited

Executes a read-only action on the specified part of this object.

Parameters
actionthe read-only action.
partthis object or a part of it.
Exceptions
UnsupportedOperationExceptionif the action tries to update the specified part.

◆ remove()

boolean javolution.util.internal.map.MapView< K, V >.KeySet.remove ( Object  obj)

Reimplemented from javolution.util.internal.set.MappedSetImpl< E, R >.

Definition at line 186 of file MapView.java.

186  {
187  if (!containsKey((K) obj)) return false;
188  MapView.this.remove((K) obj);
189  return true;
190  }

References javolution.util.internal.map.MapView< K, V >.containsKey(), and javolution.util.internal.map.MapView< K, V >.remove().

Here is the call graph for this function:

◆ removeAll()

boolean javolution.util.internal.collection.CollectionView< E >.removeAll ( Collection<?>  that)
inherited

Removes all the specified element from this collection.

Definition at line 186 of file CollectionView.java.

186  {
187  boolean changed = false;
188  Iterator<? extends E> it = iterator();
189  while (it.hasNext()) {
190  if (c.contains(it.next())) {
191  it.remove();
192  changed = true;
193  }
194  }
195  return changed;
196  }

◆ retainAll()

boolean javolution.util.internal.collection.CollectionView< E >.retainAll ( Collection<?>  that)
inherited

Removes all the elements except those in the specified collection.

Definition at line 199 of file CollectionView.java.

199  {
200  boolean changed = false;
201  Iterator<? extends E> it = iterator();
202  while (it.hasNext()) {
203  if (!c.contains(it.next())) {
204  it.remove();
205  changed = true;
206  }
207  }
208  return changed;
209  }

◆ service()

Returns the service implementation of this collection (for sub-classes).

Definition at line 274 of file CollectionView.java.

274  {
275  return this;
276  }

◆ size()

Definition at line 86 of file MappedCollectionImpl.java.

86  {
87  return target().size();
88  }

◆ split() [1/2]

T [] javolution.util.function.Splittable< T >.split ( int  n)
inherited

Returns

n

distinct parts of this object. This method may return an array of size less than

n

(e.g. an array of size one if this object cannot split).

Parameters
nthe number of parts.
Returns
the distinct parts (or views) for this object.
Exceptions
IllegalArgumentExceptionif
n <= 1

Implemented in javolution.util.internal.map.MapView< K, V >, javolution.util.internal.table.SharedTableImpl< E >, javolution.util.internal.table.TableView< E >, javolution.util.internal.collection.SharedCollectionImpl< E >, javolution.util.internal.collection.CollectionView< E >, javolution.util.internal.table.AtomicTableImpl< E >, javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, javolution.util.internal.map.AtomicMapImpl< K, V >, javolution.util.internal.collection.AtomicCollectionImpl< E >, and javolution.util.internal.map.MapView< K, V >.EntrySet.

Referenced by javolution.util.internal.map.ParallelMapImpl< K, V >.perform(), and javolution.util.internal.collection.ParallelCollectionImpl< E >.perform().

Here is the caller graph for this function:

◆ split() [2/2]

Returns

n

distinct parts of this object. This method may return an array of size less than

n

(e.g. an array of size one if this object cannot split).

Parameters
nthe number of parts.
Returns
the distinct parts (or views) for this object.
Exceptions
IllegalArgumentExceptionif
n <= 1

Definition at line 224 of file CollectionView.java.

224  {
225  if (target == null) return new CollectionService[] { this }; // No split.
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];
231  result[i] = copy;
232  }
233  return result;
234  }

◆ target()

Returns the actual target

Definition at line 279 of file CollectionView.java.

279  {
280  return target;
281  }

◆ threadSafe()

SetService<R> javolution.util.internal.set.MappedSetImpl< E, R >.threadSafe ( )
inherited

Returns a thread-safe version of this service (used during parallel updates).

Implements javolution.util.service.SetService< E >.

Reimplemented in javolution.util.internal.map.sorted.SortedMapView< K, V >.KeySortedSet.

Definition at line 38 of file MappedSetImpl.java.

38  {
39  return new SharedSetImpl<R>(this);
40  }

◆ toArray() [1/2]

Object [] javolution.util.internal.collection.CollectionView< E >.toArray ( )
inherited

Returns an array holding this collection elements.

Definition at line 243 of file CollectionView.java.

243  {
244  return toArray(new Object[size()]);
245  }

◆ toArray() [2/2]

public<T> T [] javolution.util.internal.collection.CollectionView< E >.toArray ( T[]  array)
packageinherited

Returns the specified array holding this collection elements if enough capacity.

Definition at line 249 of file CollectionView.java.

249  {
250  final int size = size();
251  final T[] result = (size <= a.length) ? a
252  : (T[]) java.lang.reflect.Array.newInstance(a.getClass()
253  .getComponentType(), size);
254  int i = 0;
255  Iterator<E> it = iterator();
256  while (it.hasNext()) {
257  result[i++] = (T) it.next();
258  }
259  if (result.length > size) {
260  result[size] = null; // As per Collection contract.
261  }
262  return result;
263  }

◆ update() [1/2]

void javolution.util.internal.collection.CollectionView< E >.update ( Consumer< CollectionService< E >>  action,
CollectionService< E >  view 
)
inherited

Definition at line 266 of file CollectionView.java.

266  {
267  if (target == null) {
268  action.accept(view);
269  } else {
270  target.perform(action, view);
271  }
272  }

◆ update() [2/2]

void javolution.util.function.Splittable< T >.update ( Consumer< T >  action,
part 
)
inherited

Executes an update action on the specified part of this object. Any change to the part is reflected in the whole (this object).

Parameters
actionthe action authorized to update this object part.
partthis object or a part of it.

Member Data Documentation

◆ function

final Function<? super E, ? extends R> javolution.util.internal.collection.MappedCollectionImpl< E, R >.function
protectedinherited

Definition at line 50 of file MappedCollectionImpl.java.

◆ serialVersionUID

final long javolution.util.internal.map.MapView< K, V >.KeySet.serialVersionUID = MapView.serialVersionUID
staticprivate

Definition at line 154 of file MapView.java.

◆ target

Definition at line 33 of file CollectionView.java.


The documentation for this class was generated from the following file:
javolution.util.internal.collection.CollectionView< R >::add
abstract boolean add(E element)
javolution.util.internal.map.MapView.put
abstract V put(K key, V value)
javolution.util.internal.collection.CollectionView< R >::contains
boolean contains(Object obj)
Definition: CollectionView.java:83
javolution.util.internal.collection.CollectionView< R >::comparator
abstract Equality<? super E > comparator()
javolution.util.internal.collection.CollectionView< R >::size
int size()
Definition: CollectionView.java:212
javolution.util.internal.collection.CollectionView< R >::target
CollectionService< E > target
Definition: CollectionView.java:33
javolution.util.internal.collection.CollectionView< R >::iterator
abstract Iterator< E > iterator()
javolution.util.internal.collection.CollectionView< R >::equals
boolean equals(Object o)
Definition: CollectionView.java:102
javolution.util.internal.map.MapView.MapView
MapView(MapService< K, V > target)
Definition: MapView.java:218
javolution.util.internal.map.MapView.containsKey
abstract boolean containsKey(Object key)
javolution.util.internal.map.MapView.entrySet
SetService< Entry< K, V > > entrySet()
Definition: MapView.java:253
javolution.util.internal.collection.CollectionView< R >::toArray
Object[] toArray()
Definition: CollectionView.java:243
javolution.util.internal.collection.CollectionView< R >::clone
CollectionView< E > clone()
Definition: CollectionView.java:66
javolution.util.internal.map.MapView.keyComparator
abstract Equality<? super K > keyComparator()
javolution.util.internal.collection.CollectionView< R >::containsAll
boolean containsAll(Collection<?> c)
Definition: CollectionView.java:93