You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2015/11/22 18:14:43 UTC
svn commit: r1715653 - in
/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap:
AbstractMultiValuedMap.java AbstractSetValuedMap.java
Author: tn
Date: Sun Nov 22 17:14:42 2015
New Revision: 1715653
URL: http://svn.apache.org/viewvc?rev=1715653&view=rev
Log:
Document the todos wrt size() and wrapped collections: for the 4.1 release we leave it as is as it would require too much work and can be improved later.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java?rev=1715653&r1=1715652&r2=1715653&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java Sun Nov 22 17:14:42 2015
@@ -140,7 +140,6 @@ public abstract class AbstractMultiValue
*/
@Override
public Collection<V> get(final K key) {
- // TODO: wrap collection based on class type - needed for proper equals
return new WrappedCollection(key);
}
@@ -194,9 +193,19 @@ public abstract class AbstractMultiValue
return getMap().keySet();
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * This implementation does <b>not</b> cache the total size
+ * of the multi-valued map, but rather calculates it by iterating
+ * over the entries of the underlying map.
+ */
@Override
public int size() {
- // TODO: cache the total size
+ // the total size should be cached to improve performance
+ // but this requires that all modifications of the multimap
+ // (including the wrapped collections and entry/value
+ // collections) are tracked.
int size = 0;
for (final Collection<V> col : getMap().values()) {
size += col.size();
@@ -376,9 +385,16 @@ public abstract class AbstractMultiValue
// -----------------------------------------------------------------------
/**
- * Wrapped collection to handle add and remove on the collection returned by get(object)
+ * Wrapped collection to handle add and remove on the collection returned
+ * by get(object).
+ * <p>
+ * Currently, the wrapped collection is not cached and has to be retrieved
+ * from the underlying map. This is safe, but not very efficient and
+ * should be improved in subsequent releases. For this purpose, the
+ * scope of this collection is set to package private to simplify later
+ * refactoring.
*/
- protected class WrappedCollection implements Collection<V> {
+ class WrappedCollection implements Collection<V> {
protected final K key;
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java?rev=1715653&r1=1715652&r2=1715653&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java Sun Nov 22 17:14:42 2015
@@ -100,7 +100,7 @@ public abstract class AbstractSetValuedM
* Wrapped set to handle add and remove on the collection returned by
* {@code get(Object)}.
*/
- protected class WrappedSet extends WrappedCollection implements Set<V> {
+ private class WrappedSet extends WrappedCollection implements Set<V> {
public WrappedSet(final K key) {
super(key);