From 89d8791f05f0d28199820e87c683696f96d42f40 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Sun, 24 Feb 2013 18:17:27 +0000 Subject: [PATCH] [COLLECTIONS-441] Cleanup MultiKeyMap, remove duplicated field map. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1449519 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 3 ++ .../commons/collections/map/MultiKeyMap.java | 42 +++++++++++++++--- .../collections/map/MultiKeyMapTest.java | 6 +-- ...MultiKeyMap.emptyCollection.version3.1.obj | Bin 206 -> 0 bytes ...MultiKeyMap.emptyCollection.version4.0.obj | Bin 0 -> 144 bytes .../MultiKeyMap.fullCollection.version3.1.obj | Bin 952 -> 0 bytes .../MultiKeyMap.fullCollection.version4.0.obj | Bin 0 -> 831 bytes 7 files changed, 42 insertions(+), 9 deletions(-) delete mode 100644 src/test/resources/data/test/MultiKeyMap.emptyCollection.version3.1.obj create mode 100644 src/test/resources/data/test/MultiKeyMap.emptyCollection.version4.0.obj delete mode 100644 src/test/resources/data/test/MultiKeyMap.fullCollection.version3.1.obj create mode 100644 src/test/resources/data/test/MultiKeyMap.fullCollection.version4.0.obj diff --git a/src/changes/changes.xml b/src/changes/changes.xml index dc8c3c2a7..229405ba7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,9 @@ + + MultiKeyMap.clone() now correctly calls super.clone(). + Use of final keyword where applicable, minor performance improvements by properly initializing the capacity of newly created collections when known in advance. diff --git a/src/main/java/org/apache/commons/collections/map/MultiKeyMap.java b/src/main/java/org/apache/commons/collections/map/MultiKeyMap.java index 42cc29196..87491fc9e 100644 --- a/src/main/java/org/apache/commons/collections/map/MultiKeyMap.java +++ b/src/main/java/org/apache/commons/collections/map/MultiKeyMap.java @@ -16,6 +16,9 @@ */ package org.apache.commons.collections.map; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Map; @@ -78,10 +81,6 @@ public class MultiKeyMap extends AbstractMapDecorator, V> map; - //----------------------------------------------------------------------- /** * Decorates the specified map to add the MultiKeyMap API and fast query. @@ -819,9 +818,14 @@ public class MultiKeyMap extends AbstractMapDecorator clone() { - return new MultiKeyMap(decorated().clone()); + try { + return (MultiKeyMap) super.clone(); + } catch (CloneNotSupportedException e) { + throw new InternalError(); + } } /** @@ -867,6 +871,32 @@ public class MultiKeyMap extends AbstractMapDecorator, V> decorated() { - return map; + return (AbstractHashedMap, V>) super.decorated(); } + + //----------------------------------------------------------------------- + /** + * Write the map out using a custom routine. + * + * @param out the output stream + * @throws IOException + */ + private void writeObject(final ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + out.writeObject(map); + } + + /** + * Read the map in using a custom routine. + * + * @param in the input stream + * @throws IOException + * @throws ClassNotFoundException + */ + @SuppressWarnings("unchecked") + private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + map = (Map, V>) in.readObject(); + } + } diff --git a/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java b/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java index 1a82ab95c..7913551f5 100644 --- a/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java @@ -441,18 +441,18 @@ public class MultiKeyMapTest extends AbstractIterableMapTest3RWCU|H#a}87)a;jq$ZbSg4nr<1$w@vIVG9isg=Ho z1<&=l-1z*9KQJ*c`Y3RWCU|H#a}87)a;jq$ZbSg4nr<1$w@vIVG9isg=Ho r1<&=l-1z*9KQJ>eR1^TU>ky&cBe6ImH3eOBIgh;q0|*F!h>8jT*6%QO literal 0 HcmV?d00001 diff --git a/src/test/resources/data/test/MultiKeyMap.fullCollection.version3.1.obj b/src/test/resources/data/test/MultiKeyMap.fullCollection.version3.1.obj deleted file mode 100644 index d649706442aee070d2028a7a025aa8a68f8c2f16..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 952 zcma)&yH6WI5XQ%QK4Y1~b_gygkkUqq?jpb_5<-bFF9#D^B&xMp`N7#f?g4faDNRzO zp@13+O8yVJ^y#8VQ7R<5q|D61jY(ugPP*N>o8Nr%&0JoC8TerL{Dv((S#K)4-s^OF z-2iXbRrRn%aYuUgR^*1QO*Pn(-cKj9mfa3+1SG0pU^0Y-DoQxF63(3j-YnrD<&?il^lYFi#k$CcfNvt4WBLeMid%SC>iv?*!dC6B-CoaKY( zt{{8J(RQDZ#4T0nhN_|b$?xYEzdn3=g$t~JsU7uw$Pc-9QKzQ-kC&%2<0s!f$6`is z0Pi8AW#cHt|He2L3RWCU|H#a}87)a;jq$ZbSg4nr<1$w@vIVG9isg=Ho z1<&=l-1z*9KQJ>eR1^TU>ky&cBe6ImH3eOBIgh;q0|+PpF%Qrv0|G{6r&g9F=9H$w zon!l>^k(_-r>sm2jL{4%KRi1ezsp+XjLXQ?K`QF%W0kp=Gffek8iXsL9ggU>{ z+@#c^wlz~_xu-nnh8f0OT*y$zzzH@M#$tnuvBOy$B@9faK430ODM%qZPzw`Wni0-o z0xC3eL{|vX!3|f#0#f6QriK}$Mi@?r0M!_~U{k{lQo{!#ctL91(A2PkWJEv&SfK=n z#RF4q>W!wF385O~C?_;&7Lc?soPZb$RA}OkO(EDqUXW_A^Y}puJ<$|`y@}*JkQZFh f)PQXTt3h?Wi3gfOuwRAIoCo4c0F5>Es;B?}${Nrn literal 0 HcmV?d00001