From: <th...@us...> - 2008-10-31 02:52:03
|
Revision: 8263 http://pcgen.svn.sourceforge.net/pcgen/?rev=8263&view=rev Author: thpr Date: 2008-10-31 02:51:56 +0000 (Fri, 31 Oct 2008) Log Message: ----------- [ 2168755 ] [5.15.4] AssociationSupport is not cloned with Equipment Issue#: 2168755 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/base/util/DoubleKeyMapToList.java Trunk/pcgen/code/src/java/pcgen/core/AssociationSupport.java Trunk/pcgen/code/src/java/pcgen/core/Equipment.java Modified: Trunk/pcgen/code/src/java/pcgen/base/util/DoubleKeyMapToList.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/base/util/DoubleKeyMapToList.java 2008-10-31 01:44:41 UTC (rev 8262) +++ Trunk/pcgen/code/src/java/pcgen/base/util/DoubleKeyMapToList.java 2008-10-31 02:51:56 UTC (rev 8263) @@ -19,6 +19,7 @@ */ package pcgen.base.util; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -109,12 +110,12 @@ if (cl1 == null) { throw new IllegalArgumentException( - "First underlying Class cannot be null for DoubleKeyMap"); + "First underlying Class cannot be null for DoubleKeyMapToList"); } if (cl2 == null) { throw new IllegalArgumentException( - "Second underlying Class cannot be null for DoubleKeyMap"); + "Second underlying Class cannot be null for DoubleKeyMapToList"); } firstClass = cl1; secondClass = cl2; @@ -158,6 +159,37 @@ } /** + * Adds all of the Objects in the given list to the (internal) List for the + * given keys. The null value cannot be used as a key in a + * DoubleKeyMapToList. This method will automatically initialize the list + * for the given key if there is not already a List for that key. + * + * This method is reference-semantic and this DoubleKeyMapToList will + * maintain a strong reference to both the key objects and the objects in + * the given list. + * + * @param key1 + * The primary key indicating which List the given objects should + * be added to. + * @param key2 + * The secondary key indicating which List the given objects + * should be added to. + * @param list + * A Collection containing the items to be added to the List for + * the given keys. + */ + public void addAllToListFor(K1 key1, K2 key2, Collection<V> value) + { + MapToList<K2, V> localMap = mtmtl.get(key1); + if (localMap == null) + { + localMap = GenericMapToList.getMapToList(secondClass); + mtmtl.put(key1, localMap); + } + localMap.addAllToListFor(key2, value); + } + + /** * Returns a copy of the List contained in this DoubleKeyMapToList for the * given keys. This method returns null if the given key is not in this * DoubleKeyMapToList. Modified: Trunk/pcgen/code/src/java/pcgen/core/AssociationSupport.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/AssociationSupport.java 2008-10-31 01:44:41 UTC (rev 8262) +++ Trunk/pcgen/code/src/java/pcgen/core/AssociationSupport.java 2008-10-31 02:51:56 UTC (rev 8263) @@ -25,11 +25,13 @@ import pcgen.cdom.enumeration.AssociationKey; import pcgen.cdom.enumeration.AssociationListKey; -public class AssociationSupport +public class AssociationSupport implements Cloneable { - private final DoubleKeyMapToList assocMTL = new DoubleKeyMapToList(IdentityHashMap.class, IdentityHashMap.class); - private final DoubleKeyMap assocMap = new DoubleKeyMap(IdentityHashMap.class, IdentityHashMap.class); + private DoubleKeyMapToList assocMTL = new DoubleKeyMapToList( + IdentityHashMap.class, IdentityHashMap.class); + private DoubleKeyMap assocMap = new DoubleKeyMap(IdentityHashMap.class, + IdentityHashMap.class); public <T> void addAssoc(Object obj, AssociationListKey<T> ak, T o) { @@ -85,4 +87,25 @@ { return (T) assocMap.get(obj, ak); } + + public AssociationSupport clone() throws CloneNotSupportedException + { + AssociationSupport as = (AssociationSupport) super.clone(); + as.assocMTL = assocMTL.clone(); + as.assocMap = assocMap.clone(); + return as; + } + + public void convertAssociations(Object oldTarget, Object newTarget) + { + for (Object secKey : assocMap.getSecondaryKeySet(oldTarget)) + { + assocMap.put(newTarget, secKey, assocMap.remove(oldTarget, secKey)); + } + for (Object secKey : assocMTL.getSecondaryKeySet(oldTarget)) + { + assocMTL.addAllToListFor(newTarget, secKey, assocMTL.removeListFor( + oldTarget, secKey)); + } + } } Modified: Trunk/pcgen/code/src/java/pcgen/core/Equipment.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/Equipment.java 2008-10-31 01:44:41 UTC (rev 8262) +++ Trunk/pcgen/code/src/java/pcgen/core/Equipment.java 2008-10-31 02:51:56 UTC (rev 8263) @@ -2749,8 +2749,9 @@ eq.d_containedEquipment = new ArrayList<Equipment>(d_containedEquipment); - eq.eqModifierList = cloneEqModList(true); - eq.altEqModifierList = cloneEqModList(false); + eq.assocSupt = assocSupt.clone(); + eq.eqModifierList = cloneEqModList(eq, true); + eq.altEqModifierList = cloneEqModList(eq, false); } catch (CloneNotSupportedException e) { ShowMessageDelegate.showMessageDialog(e.getMessage(), Constants.s_APPNAME, MessageType.ERROR); @@ -4226,7 +4227,7 @@ || !("".equals(pickChildType(aTypeList, aQuant))); } - private List<EquipmentModifier> cloneEqModList(final boolean primary) { + private List<EquipmentModifier> cloneEqModList(Equipment other, boolean primary) { final List<EquipmentModifier> clonedList = new ArrayList<EquipmentModifier>(); @@ -4235,7 +4236,9 @@ // only make a copy if we need to add qualifiers to modifier if (eqMod.getChoiceString().length() != 0) { - eqMod = eqMod.clone(); + EquipmentModifier newEqMod = eqMod.clone(); + other.assocSupt.convertAssociations(eqMod, newEqMod); + eqMod = newEqMod; } clonedList.add(eqMod); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |