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

Public Member Functions

 ParallelMapImpl (MapService< K, V > target)
 
boolean containsKey (Object key)
 
get (Object key)
 
Iterator< java.util.Map.Entry< K, V > > iterator ()
 
Equality<? super K > keyComparator ()
 
void perform (final Consumer< MapService< K, V >> action, MapService< K, V > view)
 
put (K key, V value)
 
remove (Object key)
 
void update (final Consumer< MapService< K, V >> action, MapService< K, V > view)
 
Equality<? super V > valueComparator ()
 
void clear ()
 
MapView< K, V > clone ()
 
boolean containsValue (Object value)
 
SetService< Entry< K, V > > entrySet ()
 
boolean isEmpty ()
 
SetService< K > keySet ()
 
void perform (Consumer< T > action, T part)
 
void putAll (Map<? extends K, ? extends V > m)
 
putIfAbsent (K key, V value)
 
boolean remove (Object key, Object value)
 
replace (K key, V value)
 
boolean replace (K key, V oldValue, V newValue)
 
int size ()
 
MapService< K, V >[] split (int n)
 
MapService< K, V > threadSafe ()
 
void update (Consumer< T > action, T part)
 
CollectionService< V > values ()
 

Protected Member Functions

MapService< K, V > target ()
 

Private Attributes

MapService< K, V > target
 

Static Private Attributes

static final long serialVersionUID = 0x600L
 

Detailed Description

A parallel view over a map.

Definition at line 21 of file ParallelMapImpl.java.

Constructor & Destructor Documentation

◆ ParallelMapImpl()

Definition at line 25 of file ParallelMapImpl.java.

25  {
26  super(target);
27  }

References javolution.util.internal.map.MapView< K, V >.target.

Member Function Documentation

◆ clear()

void javolution.util.internal.map.MapView< K, V >.clear ( )
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.AtomicMapImpl< K, V >, javolution.util.internal.map.UnmodifiableMapImpl< K, V >, and javolution.util.internal.map.FastMapImpl< K, V >.

Definition at line 223 of file MapView.java.

223  {
224  Iterator<Entry<K, V>> it = iterator();
225  while (it.hasNext()) {
226  it.remove();
227  }
228  }

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

Here is the call graph for this function:

◆ clone()

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

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

Implements javolution.util.service.MapService< K, V >.

Reimplemented in javolution.util.internal.map.AtomicMapImpl< K, V >, and javolution.util.internal.map.FastMapImpl< K, V >.

Definition at line 232 of file MapView.java.

232  {
233  try {
234  MapView<K, V> copy = (MapView<K, V>) super.clone();
235  if (target != null) { // Not a root class.
236  copy.target = target.clone();
237  }
238  return copy;
239  } catch (CloneNotSupportedException e) {
240  throw new Error("Should not happen since target is cloneable");
241  }
242  }

References javolution.util.internal.map.MapView< K, V >.clone(), and javolution.util.internal.map.MapView< K, V >.target.

Referenced by javolution.util.internal.map.MapView< K, V >.clone(), and javolution.util.internal.map.MapView< K, V >.split().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsKey()

boolean javolution.util.internal.map.ParallelMapImpl< K, V >.containsKey ( Object  key)

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 30 of file ParallelMapImpl.java.

30  {
31  return target().containsKey(key);
32  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ containsValue()

boolean javolution.util.internal.map.MapView< K, V >.containsValue ( Object  value)
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 248 of file MapView.java.

248  {
249  return values().contains(value);
250  }

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

Here is the call graph for this function:

◆ entrySet()

SetService<Entry<K, V> > javolution.util.internal.map.MapView< K, V >.entrySet ( )
inherited

Returns a set view over the entries of this map. The set support adding/removing entries. Two entries are considered equals if they have the same key regardless of their values.

Implements javolution.util.service.MapService< K, V >.

Reimplemented in javolution.util.internal.map.sorted.SortedMapView< K, V >, javolution.util.internal.map.sorted.SharedSortedMapImpl< K, V >, javolution.util.internal.map.sorted.AtomicSortedMapImpl< K, V >, and javolution.util.internal.map.sorted.UnmodifiableSortedMapImpl< K, V >.

Definition at line 253 of file MapView.java.

253  {
254  return new EntrySet();
255  }

Referenced by javolution.util.internal.map.MapView< K, V >.KeySet.KeySet(), and javolution.util.internal.map.MapView< K, V >.Values.Values().

Here is the caller graph for this function:

◆ get()

V javolution.util.internal.map.ParallelMapImpl< K, V >.get ( Object  key)

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 35 of file ParallelMapImpl.java.

35  {
36  return target().get(key);
37  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ isEmpty()

boolean javolution.util.internal.map.MapView< K, V >.isEmpty ( )
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 261 of file MapView.java.

261  {
262  return iterator().hasNext();
263  }

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

Referenced by javolution.util.internal.map.MapView< K, V >.EntrySet.isEmpty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterator()

Iterator<java.util.Map.Entry<K, V> > javolution.util.internal.map.ParallelMapImpl< K, V >.iterator ( )

Returns an iterator over this map entries.

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 40 of file ParallelMapImpl.java.

40  {
41  return target().iterator();
42  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ keyComparator()

Equality<? super K> javolution.util.internal.map.ParallelMapImpl< K, V >.keyComparator ( )

Returns the key comparator used for key equality or order if the map is sorted.

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 45 of file ParallelMapImpl.java.

45  {
46  return target().keyComparator();
47  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ keySet()

SetService<K> javolution.util.internal.map.MapView< K, V >.keySet ( )
inherited

Returns a set view over the key of this map, the set support adding new key for which the value is automatically

null

.

Implements javolution.util.service.MapService< K, V >.

Reimplemented in javolution.util.internal.map.sorted.SortedMapView< K, V >, javolution.util.internal.map.sorted.SharedSortedMapImpl< K, V >, javolution.util.internal.map.sorted.AtomicSortedMapImpl< K, V >, and javolution.util.internal.map.sorted.UnmodifiableSortedMapImpl< K, V >.

Definition at line 272 of file MapView.java.

272  {
273  return new KeySet();
274  }

Referenced by javolution.util.FastSet< Index >.FastSet().

Here is the caller graph for this function:

◆ perform() [1/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.

◆ perform() [2/2]

void javolution.util.internal.map.ParallelMapImpl< K, V >.perform ( final Consumer< MapService< K, V >>  action,
MapService< K, V >  view 
)

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 50 of file ParallelMapImpl.java.

51  {
52  ConcurrentContext ctx = ConcurrentContext.enter();
53  try {
54  int concurrency = ctx.getConcurrency();
55  MapService<K, V>[] subViews = view.split(concurrency + 1);
56  for (int i = 1; i < subViews.length; i++) {
57  final MapService<K, V> subView = subViews[i];
58  ctx.execute(new Runnable() {
59  @Override
60  public void run() {
61  target().perform(action, subView);
62  }
63  });
64  }
65  target().perform(action, subViews[0]); // This thread works too !
66  } finally {
67  // Any exception raised during parallel iterations will be re-raised here.
68  ctx.exit();
69  }
70  }

References javolution.context.ConcurrentContext.enter(), javolution.context.ConcurrentContext.execute(), javolution.context.ConcurrentContext.exit(), javolution.context.ConcurrentContext.getConcurrency(), javolution.util.function.Splittable< T >.split(), and javolution.util.internal.map.MapView< K, V >.target.

Here is the call graph for this function:

◆ put()

V javolution.util.internal.map.ParallelMapImpl< K, V >.put ( key,
value 
)

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 73 of file ParallelMapImpl.java.

73  {
74  return target().put(key, value);
75  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ putAll()

void javolution.util.internal.map.MapView< K, V >.putAll ( Map<? extends K, ? extends V >  m)
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 290 of file MapView.java.

290  {
291  Iterator<?> it = m.entrySet().iterator();
292  while (it.hasNext()) {
293  Entry<K, V> e = (Entry<K, V>) it.next();
294  put(e.getKey(), e.getValue());
295  }
296  }

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

Referenced by javolution.util.internal.map.FastMapImpl< K, V >.clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putIfAbsent()

V javolution.util.internal.map.MapView< K, V >.putIfAbsent ( key,
value 
)
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 299 of file MapView.java.

299  {
300  if (!containsKey(key)) return put(key, value);
301  else return get(key);
302  }

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:

◆ remove() [1/2]

V javolution.util.internal.map.ParallelMapImpl< K, V >.remove ( Object  key)

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 78 of file ParallelMapImpl.java.

78  {
79  return target().remove(key);
80  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ remove() [2/2]

boolean javolution.util.internal.map.MapView< K, V >.remove ( Object  key,
Object  value 
)
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 308 of file MapView.java.

308  {
309  if (containsKey(key) && get(key).equals(value)) {
310  remove(key);
311  return true;
312  } else return false;
313  }

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

Here is the call graph for this function:

◆ replace() [1/2]

boolean javolution.util.internal.map.MapView< K, V >.replace ( key,
oldValue,
newValue 
)
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 323 of file MapView.java.

323  {
324  if (containsKey(key) && get(key).equals(oldValue)) {
325  put(key, newValue);
326  return true;
327  } else return false;
328  }

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:

◆ replace() [2/2]

V javolution.util.internal.map.MapView< K, V >.replace ( key,
value 
)
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 316 of file MapView.java.

316  {
317  if (containsKey(key)) {
318  return put(key, value);
319  } else return null;
320  }

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:

◆ size()

int javolution.util.internal.map.MapView< K, V >.size ( )
inherited

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 331 of file MapView.java.

331  {
332  int count = 0;
333  Iterator<Entry<K, V>> it = iterator();
334  while (it.hasNext()) {
335  count++;
336  it.next();
337  }
338  return count;
339  }

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

Referenced by javolution.util.internal.map.sorted.FastSortedMapImpl< K, V >.put(), and javolution.util.internal.map.MapView< K, V >.EntrySet.size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ split()

MapService<K, V> [] javolution.util.internal.map.MapView< K, V >.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

Implements javolution.util.function.Splittable< T >.

Reimplemented in javolution.util.internal.map.SharedMapImpl< K, V >, javolution.util.internal.map.FastMapImpl< K, V >, and javolution.util.internal.map.AtomicMapImpl< K, V >.

Definition at line 343 of file MapView.java.

343  {
344  if (target == null) return new MapService[] { this }; // No split.
345  MapService<K, V>[] subTargets = target.split(n);
346  MapService<K, V>[] result = new MapService[subTargets.length];
347  for (int i = 0; i < subTargets.length; i++) {
348  MapView<K, V> copy = this.clone();
349  copy.target = subTargets[i];
350  result[i] = copy;
351  }
352  return result;
353  }

References javolution.util.internal.map.MapView< K, V >.clone(), and javolution.util.internal.map.MapView< K, V >.target.

Referenced by javolution.util.internal.map.MapView< K, V >.EntrySet.split().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ target()

◆ threadSafe()

◆ update() [1/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.

◆ update() [2/2]

void javolution.util.internal.map.ParallelMapImpl< K, V >.update ( final Consumer< MapService< K, V >>  action,
MapService< K, V >  view 
)

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 83 of file ParallelMapImpl.java.

84  {
85  ConcurrentContext ctx = ConcurrentContext.enter();
86  try {
87  int concurrency = ctx.getConcurrency();
88  MapService<K, V>[] subViews = view.threadSafe().split(
89  concurrency + 1);
90  for (int i = 1; i < subViews.length; i++) {
91  final MapService<K, V> subView = subViews[i];
92  ctx.execute(new Runnable() {
93  @Override
94  public void run() {
95  target().update(action, subView);
96  }
97  });
98  }
99  target().perform(action, subViews[0]); // This thread works too !
100  } finally {
101  // Any exception raised during parallel iterations will be re-raised here.
102  ctx.exit();
103  }
104  }

References javolution.context.ConcurrentContext.enter(), javolution.context.ConcurrentContext.execute(), javolution.context.ConcurrentContext.exit(), javolution.context.ConcurrentContext.getConcurrency(), javolution.util.internal.map.MapView< K, V >.target, and javolution.util.service.MapService< K, V >.threadSafe().

Here is the call graph for this function:

◆ valueComparator()

Equality<? super V> javolution.util.internal.map.ParallelMapImpl< K, V >.valueComparator ( )

Returns the value comparator used for value equality.

Reimplemented from javolution.util.internal.map.MapView< K, V >.

Definition at line 107 of file ParallelMapImpl.java.

107  {
108  return target().valueComparator();
109  }

References javolution.util.internal.map.MapView< K, V >.target.

◆ values()

Returns a collection view over the values of this map, the collection support value/entry removal but not adding new values.

Implements javolution.util.service.MapService< K, V >.

Definition at line 373 of file MapView.java.

373  {
374  return new Values();
375  }

Referenced by javolution.util.internal.map.MapView< K, V >.containsValue().

Here is the caller graph for this function:

Member Data Documentation

◆ serialVersionUID

final long javolution.util.internal.map.ParallelMapImpl< K, V >.serialVersionUID = 0x600L
staticprivate

Definition at line 23 of file ParallelMapImpl.java.

◆ target

MapService<K, V> javolution.util.internal.map.MapView< K, V >.target
privateinherited

Reimplemented in javolution.util.internal.map.sorted.SortedMapView< K, V >, javolution.util.internal.map.sorted.SharedSortedMapImpl< K, V >, and javolution.util.internal.map.sorted.UnmodifiableSortedMapImpl< K, V >.

Definition at line 213 of file MapView.java.

Referenced by javolution.util.internal.map.AtomicMapImpl< K, V >.AtomicMapImpl(), javolution.util.internal.map.sorted.AtomicSortedMapImpl< K, V >.AtomicSortedMapImpl(), javolution.util.internal.map.SharedMapImpl< K, V >.clear(), javolution.util.internal.map.MapView< K, V >.clone(), javolution.util.internal.map.AtomicMapImpl< K, V >.cloneTarget(), javolution.util.internal.map.SharedMapImpl< K, V >.cloneTarget(), javolution.util.internal.map.sorted.AtomicSortedMapImpl< K, V >.comparator(), javolution.util.internal.map.SequentialMapImpl< K, V >.containsKey(), javolution.util.internal.map.ParallelMapImpl< K, V >.containsKey(), javolution.util.internal.map.UnmodifiableMapImpl< K, V >.containsKey(), javolution.util.internal.map.SharedMapImpl< K, V >.containsKey(), javolution.util.internal.map.SharedMapImpl< K, V >.containsValue(), javolution.util.internal.map.SequentialMapImpl< K, V >.get(), javolution.util.internal.map.ParallelMapImpl< K, V >.get(), javolution.util.internal.map.UnmodifiableMapImpl< K, V >.get(), javolution.util.internal.map.SharedMapImpl< K, V >.get(), javolution.util.internal.map.SharedMapImpl< K, V >.isEmpty(), javolution.util.internal.map.SequentialMapImpl< K, V >.iterator(), javolution.util.internal.map.ParallelMapImpl< K, V >.iterator(), javolution.util.internal.map.SequentialMapImpl< K, V >.keyComparator(), javolution.util.internal.map.ParallelMapImpl< K, V >.keyComparator(), javolution.util.internal.map.UnmodifiableMapImpl< K, V >.keyComparator(), javolution.util.internal.map.SharedMapImpl< K, V >.keyComparator(), javolution.util.internal.map.MapView< K, V >.MapView(), javolution.util.internal.map.ParallelMapImpl< K, V >.ParallelMapImpl(), javolution.util.internal.map.ParallelMapImpl< K, V >.perform(), javolution.util.internal.map.MapView< K, V >.perform(), javolution.util.internal.map.SequentialMapImpl< K, V >.put(), javolution.util.internal.map.ParallelMapImpl< K, V >.put(), javolution.util.internal.map.AtomicMapImpl< K, V >.put(), javolution.util.internal.map.SharedMapImpl< K, V >.put(), javolution.util.internal.map.AtomicMapImpl< K, V >.putAll(), javolution.util.internal.map.SharedMapImpl< K, V >.putAll(), javolution.util.internal.map.AtomicMapImpl< K, V >.putIfAbsent(), javolution.util.internal.map.SharedMapImpl< K, V >.putIfAbsent(), javolution.util.internal.map.SequentialMapImpl< K, V >.remove(), javolution.util.internal.map.ParallelMapImpl< K, V >.remove(), javolution.util.internal.map.AtomicMapImpl< K, V >.remove(), javolution.util.internal.map.SharedMapImpl< K, V >.remove(), javolution.util.internal.map.AtomicMapImpl< K, V >.replace(), javolution.util.internal.map.SharedMapImpl< K, V >.replace(), javolution.util.internal.map.SequentialMapImpl< K, V >.SequentialMapImpl(), javolution.util.internal.map.SharedMapImpl< K, V >.SharedMapImpl(), javolution.util.internal.map.SharedMapImpl< K, V >.size(), javolution.util.internal.map.SharedMapImpl< K, V >.split(), javolution.util.internal.map.MapView< K, V >.split(), javolution.util.internal.map.MapView< K, V >.target(), javolution.util.internal.map.AtomicMapImpl< K, V >.targetView(), javolution.util.internal.map.UnmodifiableMapImpl< K, V >.UnmodifiableMapImpl(), javolution.util.internal.map.ParallelMapImpl< K, V >.update(), javolution.util.internal.map.AtomicMapImpl< K, V >.update(), javolution.util.internal.map.MapView< K, V >.update(), javolution.util.internal.map.SequentialMapImpl< K, V >.valueComparator(), javolution.util.internal.map.UnmodifiableMapImpl< K, V >.valueComparator(), javolution.util.internal.map.ParallelMapImpl< K, V >.valueComparator(), and javolution.util.internal.map.SharedMapImpl< K, V >.valueComparator().


The documentation for this class was generated from the following file:
javolution.util.internal.map.MapView.iterator
abstract Iterator< Entry< K, V > > iterator()
javolution.util.internal.map.MapView.put
abstract V put(K key, V value)
javolution.util.internal.map.MapView.containsKey
abstract boolean containsKey(Object key)
javolution.util.internal.map.MapView.clone
MapView< K, V > clone()
Definition: MapView.java:232
javolution.util.internal.map.MapView.values
CollectionService< V > values()
Definition: MapView.java:373
EntrySet
javolution.util.internal.map.MapView.target
MapService< K, V > target
Definition: MapView.java:213