cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap AbstractDualBidiMap.java DualHashBidiMap.java DualTreeBidiMap.java

2004-06-11 Thread scolebourne
scolebourne2004/06/11 16:27:38

  Modified:collections RELEASE-NOTES.html
   collections/src/java/org/apache/commons/collections/bidimap
AbstractDualBidiMap.java DualHashBidiMap.java
DualTreeBidiMap.java
  Log:
  Fix bug in DualBidiMaps caused by bad design of createMap method

  bug 29519
  
  Revision  ChangesPath
  1.62  +1 -0  jakarta-commons/collections/RELEASE-NOTES.html
  
  Index: RELEASE-NOTES.html
  ===
  RCS file: /home/cvs/jakarta-commons/collections/RELEASE-NOTES.html,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- RELEASE-NOTES.html10 Jun 2004 22:14:59 -  1.61
  +++ RELEASE-NOTES.html11 Jun 2004 23:27:37 -  1.62
  @@ -104,6 +104,7 @@
   liUnmodifiableSortedBag - Fix to ensure unmodifiable/li
   liMultiHashMap - Fix copy constructor and clone to work properly [28972]/li
   liListOrderedSet - Fix to throw IllegalArgumentException instead of NPE on null 
factory decorate(List)/li
  +li*Dual*BidiMap - Fix poorly designed subclass method call from superclass 
constructor [29519]/li
   /ul
   
   centerh3JAVADOC/h3/center
  
  
  
  1.13  +30 -4 
jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java
  
  Index: AbstractDualBidiMap.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractDualBidiMap.java  15 May 2004 12:13:03 -  1.12
  +++ AbstractDualBidiMap.java  11 Jun 2004 23:27:37 -  1.13
  @@ -68,7 +68,9 @@
   /**
* Creates an empty map, initialised by codecreateMap/code.
* p
  - * The map array must be populated by the subclass.
  + * This constructor remains in place for deserialization.
  + * All other usage is deprecated in favour of
  + * [EMAIL PROTECTED] #AbstractDualBidiMap(Map, Map)}.
*/
   protected AbstractDualBidiMap() {
   super();
  @@ -76,6 +78,25 @@
   maps[1] = createMap();
   }
   
  +/**
  + * Creates an empty map using the two maps specified as storage.
  + * p
  + * The two maps must be a matching pair, normal and reverse.
  + * They will typically both be empty.
  + * p
  + * Neither map is validated, so nulls may be passed in.
  + * If you choose to do this then the subclass constructor must populate
  + * the codemaps[]/code instance variable itself.
  + * 
  + * @param normalMap  the normal direction map
  + * @param reverseMap  the reverse direction map
  + */
  +protected AbstractDualBidiMap(Map normalMap, Map reverseMap) {
  +super();
  +maps[0] = normalMap;
  +maps[1] = reverseMap;
  +}
  +
   /** 
* Constructs a map that decorates the specified maps,
* used by the subclass codecreateBidiMap/code implementation.
  @@ -94,11 +115,16 @@
   /**
* Creates a new instance of the map used by the subclass to store data.
* p
  - * Do not change any instance variables from this method.
  + * This design is deeply flawed and has been deprecated.
  + * It relied on subclass data being used during a superclass constructor.
* 
* @return the map to be used for internal storage
  + * @deprecated For constructors, use the new two map constructor.
  + * For deserialization, populate the maps array directly in readObject.
*/
  -protected abstract Map createMap();
  +protected Map createMap() {
  +return null;
  +}
   
   /**
* Creates a new instance of the subclass.
  
  
  
  1.7   +14 -13
jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/DualHashBidiMap.java
  
  Index: DualHashBidiMap.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/DualHashBidiMap.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DualHashBidiMap.java  18 Feb 2004 00:57:39 -  1.6
  +++ DualHashBidiMap.java  11 Jun 2004 23:27:37 -  1.7
  @@ -26,6 +26,14 @@
   
   /**
* Implementation of codeBidiMap/code that uses two codeHashMap/code 
instances.
  + * p
  + * Two codeHashMap/code instances are used in this class.
  + * This provides fast lookups at the expense of storing two sets of map entries.
  + * Commons Collections would welcome the addition of a direct hash-based
  + * implementation of the codeBidiMap/code interface.
  + * p
  + * NOTE: From Commons Collections 3.1, all subclasses will use codeHashMap/code
  + * 

cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap AbstractDualBidiMap.java

2003-12-28 Thread scolebourne
scolebourne2003/12/28 17:28:20

  Modified:collections/src/java/org/apache/commons/collections/bidimap
AbstractDualBidiMap.java
  Log:
  Increase flexibility by adding factories for view iterators
  
  Revision  ChangesPath
  1.7   +73 -5 
jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java
  
  Index: AbstractDualBidiMap.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractDualBidiMap.java  29 Dec 2003 00:38:08 -  1.6
  +++ AbstractDualBidiMap.java  29 Dec 2003 01:28:20 -  1.7
  @@ -258,6 +258,13 @@
   
   // Map views
   //---
  +/**
  + * Gets a keySet view of the map.
  + * Changes made on the view are reflected in the map.
  + * The set supports remove and clear but not add.
  + * 
  + * @return the keySet view
  + */
   public Set keySet() {
   if (keySet == null) {
   keySet = new KeySet(this);
  @@ -265,6 +272,24 @@
   return keySet;
   }
   
  +/**
  + * Creates a key set iterator.
  + * Subclasses can override this to return iterators with different properties.
  + * 
  + * @param iterator  the iterator to decorate
  + * @return the keySet iterator
  + */
  +protected Iterator createKeySetIterator(Iterator iterator) {
  +return new KeySetIterator(iterator, this);
  +}
  +
  +/**
  + * Gets a values view of the map.
  + * Changes made on the view are reflected in the map.
  + * The set supports remove and clear but not add.
  + * 
  + * @return the values view
  + */
   public Collection values() {
   if (values == null) {
   values = new Values(this);
  @@ -273,6 +298,17 @@
   }
   
   /**
  + * Creates a values iterator.
  + * Subclasses can override this to return iterators with different properties.
  + * 
  + * @param iterator  the iterator to decorate
  + * @return the values iterator
  + */
  +protected Iterator createValuesIterator(Iterator iterator) {
  +return new ValuesIterator(iterator, this);
  +}
  +
  +/**
* Gets an entrySet view of the map.
* Changes made on the set are reflected in the map.
* The set supports remove and clear but not add.
  @@ -290,6 +326,17 @@
   return entrySet;
   }
   
  +/**
  + * Creates an entry set iterator.
  + * Subclasses can override this to return iterators with different properties.
  + * 
  + * @param iterator  the iterator to decorate
  + * @return the entrySet iterator
  + */
  +protected Iterator createEntrySetIterator(Iterator iterator) {
  +return new EntrySetIterator(iterator, this);
  +}
  +
   //---
   /**
* Inner class View.
  @@ -299,6 +346,12 @@
   /** The parent map */
   protected final AbstractDualBidiMap parent;
   
  +/**
  + * Constructs a new view of the BidiMap.
  + * 
  + * @param coll  the collection view being decorated
  + * @param parent  the parent BidiMap
  + */
   protected View(Collection coll, AbstractDualBidiMap parent) {
   super(coll);
   this.parent = parent;
  @@ -349,12 +402,17 @@
*/
   protected static class KeySet extends View implements Set {
   
  +/**
  + * Constructs a new view of the BidiMap.
  + * 
  + * @param parent  the parent BidiMap
  + */
   protected KeySet(AbstractDualBidiMap parent) {
   super(parent.maps[0].keySet(), parent);
   }
   
   public Iterator iterator() {
  -return new KeySetIterator(super.iterator(), parent);
  +return parent.createKeySetIterator(super.iterator());
   }
   
   public boolean contains(Object key) {
  @@ -412,12 +470,17 @@
*/
   protected static class Values extends View implements Set {
   
  +/**
  + * Constructs a new view of the BidiMap.
  + * 
  + * @param parent  the parent BidiMap
  + */
   protected Values(AbstractDualBidiMap parent) {
   super(parent.maps[0].values(), parent);
   }
   
   public Iterator iterator() {
  -return new ValuesIterator(super.iterator(), parent);
  +return parent.createValuesIterator(super.iterator());
   }
   
   public boolean contains(Object value) {
  @@ 

cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap AbstractDualBidiMap.java

2003-12-14 Thread scolebourne
scolebourne2003/12/14 04:59:38

  Modified:collections/src/java/org/apache/commons/collections/bidimap
AbstractDualBidiMap.java
  Log:
  Fix bug in iterator method from coverage testing
  
  Revision  ChangesPath
  1.5   +3 -3  
jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java
  
  Index: AbstractDualBidiMap.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDualBidiMap.java  5 Dec 2003 20:23:58 -   1.4
  +++ AbstractDualBidiMap.java  14 Dec 2003 12:59:38 -  1.5
  @@ -616,7 +616,7 @@
   }
   
   public String toString() {
  -if (last == null) {
  +if (last != null) {
   return MapIterator[ + getKey() + = + getValue() + ];
   } else {
   return MapIterator[];
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]