You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ma...@apache.org on 2002/03/13 06:40:31 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections AbstractBag.java Bag.java Closure.java DefaultMapEntry.java HashBag.java IteratorEnumeration.java MapUtils.java MultiHashMap.java MultiMap.java Predicate.java SingletonIterator.java SoftRefHashMap.java SortedBag.java TransformIterator.java Transformer.java TreeBag.java
mas 02/03/12 21:40:31
Modified: collections/src/java/org/apache/commons/collections
AbstractBag.java Bag.java Closure.java
DefaultMapEntry.java HashBag.java
IteratorEnumeration.java MapUtils.java
MultiHashMap.java MultiMap.java Predicate.java
SingletonIterator.java SoftRefHashMap.java
SortedBag.java TransformIterator.java
Transformer.java TreeBag.java
Log:
Removed bad line-endings (multiple ^Ms).
Thanks to Christopher Elkins.
see: http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg04102.html
Revision Changes Path
1.5 +338 -338 jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java
Index: AbstractBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractBag.java 22 Feb 2002 04:58:17 -0000 1.4
+++ AbstractBag.java 13 Mar 2002 05:40:30 -0000 1.5
@@ -1,339 +1,339 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java,v 1.4 2002/02/22 04:58:17 mas Exp $
- * $Revision: 1.4 $
- * $Date: 2002/02/22 04:58:17 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.collections;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * This class provides a skeletal implementation of the {@link Bag}
- * interface to minimize the effort required for target implementations.
- * Subclasses need only to call {@link #setMap(Map)} in their constructor
- * specifying a map instance that will be used to store the contents of
- * the bag.
- *
- * @author Chuck Burdick
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java,v 1.5 2002/03/13 05:40:30 mas Exp $
+ * $Revision: 1.5 $
+ * $Date: 2002/03/13 05:40:30 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.collections;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * This class provides a skeletal implementation of the {@link Bag}
+ * interface to minimize the effort required for target implementations.
+ * Subclasses need only to call {@link #setMap(Map)} in their constructor
+ * specifying a map instance that will be used to store the contents of
+ * the bag.
+ *
+ * @author Chuck Burdick
* @author <a href="mas@apache.org">Michael A. Smith</a>
- **/
-public abstract class AbstractBag implements Bag {
- private Map _map = null;
- private int _total = 0;
- private int _mods = 0;
-
- public boolean add(Object o) {
- return add(o, 1);
- }
-
- public boolean add(Object o, int i) {
- _mods++;
- if (i > 0) {
- int count = (i + getCount(o));
- _map.put(o, new Integer(count));
- _total += i;
- return (count == i);
- } else {
- return false;
- }
- }
-
- public boolean addAll(Collection c) {
- boolean changed = false;
- Iterator i = c.iterator();
- while (i.hasNext()) {
- boolean added = add(i.next());
- changed = changed || added;
- }
- return changed;
- }
-
- public void clear() {
- _mods++;
- _map.clear();
- _total = 0;
- }
-
- public boolean contains(Object o) {
- return _map.containsKey(o);
- }
-
- public boolean containsAll(Collection c) {
- return containsAll(new HashBag(c));
- }
-
- /**
- * Returns <code>true</code> if the bag contains all elements in
- * the given collection, respecting cardinality.
- * @see #containsAll(Collection)
- **/
- public boolean containsAll(Bag other) {
- boolean result = true;
- Iterator i = other.uniqueSet().iterator();
- while (i.hasNext()) {
- Object current = i.next();
- boolean contains =
- getCount(current) >= ((Bag)other).getCount(current);
- result = result && contains;
- }
- return result;
- }
-
- public boolean equals(Object o) {
- return (o == this ||
- (o != null && o.getClass().equals(this.getClass()) &&
- ((AbstractBag)o)._map.equals(this._map)));
- }
-
- public int hashCode() {
- return _map.hashCode();
- }
-
- public boolean isEmpty() {
- return _map.isEmpty();
- }
-
- public Iterator iterator() {
- return new BagIterator(this, extractList().iterator());
- }
-
- private class BagIterator implements Iterator {
- private AbstractBag _parent = null;
- private Iterator _support = null;
- private Object _current = null;
- private int _mods = 0;
-
- public BagIterator(AbstractBag parent, Iterator support) {
- _parent = parent;
- _support = support;
- _current = null;
- _mods = parent.modCount();
- }
-
- public boolean hasNext() {
- return _support.hasNext();
- }
-
- public Object next() {
- if (_parent.modCount() != _mods) {
- throw new ConcurrentModificationException();
- }
- _current = _support.next();
- return _current;
- }
-
- public void remove() {
- if (_parent.modCount() != _mods) {
- throw new ConcurrentModificationException();
- }
- _support.remove();
- _parent.remove(_current, 1);
- _mods++;
- }
- }
-
- public boolean remove (Object o) {
- return remove(o, getCount(o));
- }
-
- public boolean remove (Object o, int i) {
- _mods++;
- boolean result = false;
- int count = getCount(o);
- if (i <= 0) {
- result = false;
- } else if (count > i) {
- _map.put(o, new Integer(count - i));
- result = true;
- _total -= i;
- } else { // count > 0 && count <= i
- // need to remove all
- result = (_map.remove(o) != null);
- _total -= count;
- }
- return result;
- }
-
- public boolean removeAll(Collection c) {
- boolean result = false;
- if (c != null) {
- Iterator i = c.iterator();
- while (i.hasNext()) {
- boolean changed = remove(i.next(), 1);
- result = result || changed;
- }
- }
- return result;
- }
-
- public boolean retainAll(Collection c) {
- return retainAll(new HashBag(c));
- }
-
- /**
- * Remove any members of the bag that are not in the given
- * bag, respecting cardinality.
- * @see #retainAll(Collection)
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean retainAll(Bag other) {
- boolean result = false;
- Bag excess = new HashBag();
- Iterator i = uniqueSet().iterator();
- while (i.hasNext()) {
- Object current = i.next();
- int myCount = getCount(current);
- int otherCount = other.getCount(current);
- if (1 <= otherCount && otherCount <= myCount) {
- excess.add(current, myCount - otherCount);
- } else {
- excess.add(current, myCount);
- }
- }
- if (!excess.isEmpty()) {
- result = removeAll(excess);
- }
- return result;
- }
-
- public Object[] toArray() {
- return extractList().toArray();
- }
-
- public Object[] toArray(Object[] a) {
- return extractList().toArray(a);
- }
-
- public int getCount(Object o) {
- int result = 0;
- Integer count = MapUtils.getInteger(_map, o);
- if (count != null) {
- result = count.intValue();
- }
- return result;
- }
-
- public Set uniqueSet() {
- return Collections.unmodifiableSet(_map.keySet());
- }
-
- public int size() {
- return _total;
- }
-
- /**
- * Actually walks the bag to make sure the count is correct and
- * resets the running total
- **/
- protected int calcTotalSize() {
- _total = extractList().size();
- return _total;
- }
-
- /**
- * Utility method for implementations to set the map that backs
- * this bag. Not intended for interactive use outside of
- * subclasses.
- **/
- protected void setMap(Map m) {
- _map = m;
- }
-
- /**
- * Utility method for implementations to access the map that backs
- * this bag. Not intended for interactive use outside of
- * subclasses.
- **/
- protected Map getMap() {
- return _map;
- }
-
- /**
- * Create a list for use in iteration, etc.
- **/
- private List extractList() {
- List result = new ArrayList();
- Iterator i = uniqueSet().iterator();
- while (i.hasNext()) {
- Object current = i.next();
- for (int index = getCount(current); index > 0; index--) {
- result.add(current);
- }
- }
- return result;
- }
-
- /**
- * Return number of modifications for iterator
- **/
- private int modCount() {
- return _mods;
- }
-}
-
-
-
+ **/
+public abstract class AbstractBag implements Bag {
+ private Map _map = null;
+ private int _total = 0;
+ private int _mods = 0;
+
+ public boolean add(Object o) {
+ return add(o, 1);
+ }
+
+ public boolean add(Object o, int i) {
+ _mods++;
+ if (i > 0) {
+ int count = (i + getCount(o));
+ _map.put(o, new Integer(count));
+ _total += i;
+ return (count == i);
+ } else {
+ return false;
+ }
+ }
+
+ public boolean addAll(Collection c) {
+ boolean changed = false;
+ Iterator i = c.iterator();
+ while (i.hasNext()) {
+ boolean added = add(i.next());
+ changed = changed || added;
+ }
+ return changed;
+ }
+
+ public void clear() {
+ _mods++;
+ _map.clear();
+ _total = 0;
+ }
+
+ public boolean contains(Object o) {
+ return _map.containsKey(o);
+ }
+
+ public boolean containsAll(Collection c) {
+ return containsAll(new HashBag(c));
+ }
+
+ /**
+ * Returns <code>true</code> if the bag contains all elements in
+ * the given collection, respecting cardinality.
+ * @see #containsAll(Collection)
+ **/
+ public boolean containsAll(Bag other) {
+ boolean result = true;
+ Iterator i = other.uniqueSet().iterator();
+ while (i.hasNext()) {
+ Object current = i.next();
+ boolean contains =
+ getCount(current) >= ((Bag)other).getCount(current);
+ result = result && contains;
+ }
+ return result;
+ }
+
+ public boolean equals(Object o) {
+ return (o == this ||
+ (o != null && o.getClass().equals(this.getClass()) &&
+ ((AbstractBag)o)._map.equals(this._map)));
+ }
+
+ public int hashCode() {
+ return _map.hashCode();
+ }
+
+ public boolean isEmpty() {
+ return _map.isEmpty();
+ }
+
+ public Iterator iterator() {
+ return new BagIterator(this, extractList().iterator());
+ }
+
+ private class BagIterator implements Iterator {
+ private AbstractBag _parent = null;
+ private Iterator _support = null;
+ private Object _current = null;
+ private int _mods = 0;
+
+ public BagIterator(AbstractBag parent, Iterator support) {
+ _parent = parent;
+ _support = support;
+ _current = null;
+ _mods = parent.modCount();
+ }
+
+ public boolean hasNext() {
+ return _support.hasNext();
+ }
+
+ public Object next() {
+ if (_parent.modCount() != _mods) {
+ throw new ConcurrentModificationException();
+ }
+ _current = _support.next();
+ return _current;
+ }
+
+ public void remove() {
+ if (_parent.modCount() != _mods) {
+ throw new ConcurrentModificationException();
+ }
+ _support.remove();
+ _parent.remove(_current, 1);
+ _mods++;
+ }
+ }
+
+ public boolean remove (Object o) {
+ return remove(o, getCount(o));
+ }
+
+ public boolean remove (Object o, int i) {
+ _mods++;
+ boolean result = false;
+ int count = getCount(o);
+ if (i <= 0) {
+ result = false;
+ } else if (count > i) {
+ _map.put(o, new Integer(count - i));
+ result = true;
+ _total -= i;
+ } else { // count > 0 && count <= i
+ // need to remove all
+ result = (_map.remove(o) != null);
+ _total -= count;
+ }
+ return result;
+ }
+
+ public boolean removeAll(Collection c) {
+ boolean result = false;
+ if (c != null) {
+ Iterator i = c.iterator();
+ while (i.hasNext()) {
+ boolean changed = remove(i.next(), 1);
+ result = result || changed;
+ }
+ }
+ return result;
+ }
+
+ public boolean retainAll(Collection c) {
+ return retainAll(new HashBag(c));
+ }
+
+ /**
+ * Remove any members of the bag that are not in the given
+ * bag, respecting cardinality.
+ * @see #retainAll(Collection)
+ * @return <code>true</code> if this call changed the collection
+ **/
+ public boolean retainAll(Bag other) {
+ boolean result = false;
+ Bag excess = new HashBag();
+ Iterator i = uniqueSet().iterator();
+ while (i.hasNext()) {
+ Object current = i.next();
+ int myCount = getCount(current);
+ int otherCount = other.getCount(current);
+ if (1 <= otherCount && otherCount <= myCount) {
+ excess.add(current, myCount - otherCount);
+ } else {
+ excess.add(current, myCount);
+ }
+ }
+ if (!excess.isEmpty()) {
+ result = removeAll(excess);
+ }
+ return result;
+ }
+
+ public Object[] toArray() {
+ return extractList().toArray();
+ }
+
+ public Object[] toArray(Object[] a) {
+ return extractList().toArray(a);
+ }
+
+ public int getCount(Object o) {
+ int result = 0;
+ Integer count = MapUtils.getInteger(_map, o);
+ if (count != null) {
+ result = count.intValue();
+ }
+ return result;
+ }
+
+ public Set uniqueSet() {
+ return Collections.unmodifiableSet(_map.keySet());
+ }
+
+ public int size() {
+ return _total;
+ }
+
+ /**
+ * Actually walks the bag to make sure the count is correct and
+ * resets the running total
+ **/
+ protected int calcTotalSize() {
+ _total = extractList().size();
+ return _total;
+ }
+
+ /**
+ * Utility method for implementations to set the map that backs
+ * this bag. Not intended for interactive use outside of
+ * subclasses.
+ **/
+ protected void setMap(Map m) {
+ _map = m;
+ }
+
+ /**
+ * Utility method for implementations to access the map that backs
+ * this bag. Not intended for interactive use outside of
+ * subclasses.
+ **/
+ protected Map getMap() {
+ return _map;
+ }
+
+ /**
+ * Create a list for use in iteration, etc.
+ **/
+ private List extractList() {
+ List result = new ArrayList();
+ Iterator i = uniqueSet().iterator();
+ while (i.hasNext()) {
+ Object current = i.next();
+ for (int index = getCount(current); index > 0; index--) {
+ result.add(current);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Return number of modifications for iterator
+ **/
+ private int modCount() {
+ return _mods;
+ }
+}
+
+
+
1.4 +181 -181 jakarta-commons/collections/src/java/org/apache/commons/collections/Bag.java
Index: Bag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Bag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Bag.java 22 Feb 2002 04:39:53 -0000 1.3
+++ Bag.java 13 Mar 2002 05:40:30 -0000 1.4
@@ -1,181 +1,181 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Bag.java,v 1.3 2002/02/22 04:39:53 mas Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/22 04:39:53 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.collections;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A {@link Collection} that keeps a count of its members of the same
- * type, using <code>hashCode</code> to check for equality. Suppose
- * you have a Bag that contains <code>{a, a, b, c}</code>. Calling
- * {@link #getCount} on <code>a</code> would return 2, while calling
- * {@link #uniqueSet} would return <code>{a, b, c}</code>.
- *
- * @author Chuck Burdick
- **/
-public interface Bag extends Collection {
- /**
- * Return the number of occurrences (cardinality) of the given
- * object currently in the bag. If the object does not exist in the
- * bag, return 0.
- **/
- public int getCount(Object o);
-
- /**
- * Add the given object to the bag and keep a count. If the object
- * is already in the {@link #uniqueSet} then increment its count as
- * reported by {@link #getCount}. Otherwise add it to the {@link
- * #uniqueSet} and report its count as 1.
- * @return <code>true</code> if the object was not already in the
- * <code>uniqueSet</code>
- * @see #getCount
- **/
- public boolean add(Object o);
-
- /**
- * Add <code>i</code> copies of the given object to the bag and
- * keep a count.
- * @return <code>true</code> if the object was not already in the
- * <code>uniqueSet</code>
- * @see #add(Object)
- * @see #getCount
- **/
- public boolean add(Object o, int i);
-
- /**
- * Remove all occurrences of the given object from the bag, and do
- * not represent the object in the {@link #uniqueSet}.
- * @see #remove(Object, int)
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean remove(Object o);
-
- /**
- * Remove the given number of occurrences from the bag. If the bag
- * contains <code>i</code> occurrences or less, the item will be
- * removed from the {@link #uniqueSet}.
- * @see #getCount
- * @see #remove(Object)
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean remove(Object o, int i);
-
- /**
- * The {@link Set} of unique members that represent all members in
- * the bag. Uniqueness constraints are the same as those in {@link
- * Set}.
- **/
- public Set uniqueSet();
-
- /**
- * Returns the total number of items in the bag across all types.
- * @see #size
- **/
- public int size();
-
- /**
- * Returns <code>true</code> if the bag contains all elements in
- * the given collection, respecting cardinality. That is, if the
- * given collection <code>C</code> contains <code>n</code> copies
- * of a given object, calling {@link #getCount} on that object must
- * be >= <code>n</code> for all <code>n</code> in <code>C</code>.
- **/
- public boolean containsAll(Collection c);
-
- /**
- * Remove all elements represented in the given collection,
- * respecting cardinality. That is, if the given collection
- * <code>C</code> contains <code>n</code> copies of a given object,
- * the bag will have <code>n</code> fewer copies, assuming the bag
- * had at least <code>n</code> copies to begin with.
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean removeAll(Collection c);
-
- /**
- * Remove any members of the bag that are not in the given
- * collection, respecting cardinality. That is, if the given
- * collection <code>C</code> contains <code>n</code> copies of a
- * given object and the bag has <code>m > n</code> copies, then
- * delete <code>m - n</code> copies from the bag. In addition, if
- * <code>e</code> is an object in the bag but
- * <code>!C.contains(e)</code>, then remove <code>e</code> and any
- * of its copies.
- *
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean retainAll(Collection c);
-
- /**
- * Returns an {@link Iterator} over the entire set of members,
- * including copies due to cardinality. This iterator is fail-fast
- * and will not tolerate concurrent modifications.
- **/
- public Iterator iterator();
-}
-
-
-
-
-
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Bag.java,v 1.4 2002/03/13 05:40:30 mas Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/03/13 05:40:30 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.collections;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A {@link Collection} that keeps a count of its members of the same
+ * type, using <code>hashCode</code> to check for equality. Suppose
+ * you have a Bag that contains <code>{a, a, b, c}</code>. Calling
+ * {@link #getCount} on <code>a</code> would return 2, while calling
+ * {@link #uniqueSet} would return <code>{a, b, c}</code>.
+ *
+ * @author Chuck Burdick
+ **/
+public interface Bag extends Collection {
+ /**
+ * Return the number of occurrences (cardinality) of the given
+ * object currently in the bag. If the object does not exist in the
+ * bag, return 0.
+ **/
+ public int getCount(Object o);
+
+ /**
+ * Add the given object to the bag and keep a count. If the object
+ * is already in the {@link #uniqueSet} then increment its count as
+ * reported by {@link #getCount}. Otherwise add it to the {@link
+ * #uniqueSet} and report its count as 1.
+ * @return <code>true</code> if the object was not already in the
+ * <code>uniqueSet</code>
+ * @see #getCount
+ **/
+ public boolean add(Object o);
+
+ /**
+ * Add <code>i</code> copies of the given object to the bag and
+ * keep a count.
+ * @return <code>true</code> if the object was not already in the
+ * <code>uniqueSet</code>
+ * @see #add(Object)
+ * @see #getCount
+ **/
+ public boolean add(Object o, int i);
+
+ /**
+ * Remove all occurrences of the given object from the bag, and do
+ * not represent the object in the {@link #uniqueSet}.
+ * @see #remove(Object, int)
+ * @return <code>true</code> if this call changed the collection
+ **/
+ public boolean remove(Object o);
+
+ /**
+ * Remove the given number of occurrences from the bag. If the bag
+ * contains <code>i</code> occurrences or less, the item will be
+ * removed from the {@link #uniqueSet}.
+ * @see #getCount
+ * @see #remove(Object)
+ * @return <code>true</code> if this call changed the collection
+ **/
+ public boolean remove(Object o, int i);
+
+ /**
+ * The {@link Set} of unique members that represent all members in
+ * the bag. Uniqueness constraints are the same as those in {@link
+ * Set}.
+ **/
+ public Set uniqueSet();
+
+ /**
+ * Returns the total number of items in the bag across all types.
+ * @see #size
+ **/
+ public int size();
+
+ /**
+ * Returns <code>true</code> if the bag contains all elements in
+ * the given collection, respecting cardinality. That is, if the
+ * given collection <code>C</code> contains <code>n</code> copies
+ * of a given object, calling {@link #getCount} on that object must
+ * be >= <code>n</code> for all <code>n</code> in <code>C</code>.
+ **/
+ public boolean containsAll(Collection c);
+
+ /**
+ * Remove all elements represented in the given collection,
+ * respecting cardinality. That is, if the given collection
+ * <code>C</code> contains <code>n</code> copies of a given object,
+ * the bag will have <code>n</code> fewer copies, assuming the bag
+ * had at least <code>n</code> copies to begin with.
+ * @return <code>true</code> if this call changed the collection
+ **/
+ public boolean removeAll(Collection c);
+
+ /**
+ * Remove any members of the bag that are not in the given
+ * collection, respecting cardinality. That is, if the given
+ * collection <code>C</code> contains <code>n</code> copies of a
+ * given object and the bag has <code>m > n</code> copies, then
+ * delete <code>m - n</code> copies from the bag. In addition, if
+ * <code>e</code> is an object in the bag but
+ * <code>!C.contains(e)</code>, then remove <code>e</code> and any
+ * of its copies.
+ *
+ * @return <code>true</code> if this call changed the collection
+ **/
+ public boolean retainAll(Collection c);
+
+ /**
+ * Returns an {@link Iterator} over the entire set of members,
+ * including copies due to cardinality. This iterator is fail-fast
+ * and will not tolerate concurrent modifications.
+ **/
+ public Iterator iterator();
+}
+
+
+
+
+
1.3 +74 -74 jakarta-commons/collections/src/java/org/apache/commons/collections/Closure.java
Index: Closure.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Closure.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Closure.java 10 Feb 2002 08:07:42 -0000 1.2
+++ Closure.java 13 Mar 2002 05:40:30 -0000 1.3
@@ -1,74 +1,74 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Closure.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-/** An interface to represent some Closure, a block of code which is executed
- * from inside some block, function or iteration which operates on an input
- * object.
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public interface Closure {
-
- /** Performs some operation on the input object
- */
- public void execute(Object input);
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Closure.java,v 1.3 2002/03/13 05:40:30 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:30 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+/** An interface to represent some Closure, a block of code which is executed
+ * from inside some block, function or iteration which operates on an input
+ * object.
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+public interface Closure {
+
+ /** Performs some operation on the input object
+ */
+ public void execute(Object input);
+}
1.4 +139 -139 jakarta-commons/collections/src/java/org/apache/commons/collections/DefaultMapEntry.java
Index: DefaultMapEntry.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/DefaultMapEntry.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultMapEntry.java 22 Feb 2002 04:58:17 -0000 1.3
+++ DefaultMapEntry.java 13 Mar 2002 05:40:30 -0000 1.4
@@ -1,139 +1,139 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/DefaultMapEntry.java,v 1.3 2002/02/22 04:58:17 mas Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/22 04:58:17 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.util.Map;
-
-/** A default implementation of {@link Map.Entry Map.Entry}
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
- */
-
-public class DefaultMapEntry implements Map.Entry {
-
- private Object key;
- private Object value;
-
- public DefaultMapEntry() {
- }
-
- public DefaultMapEntry(Object key, Object value) {
- this.key = key;
- this.value = value;
- }
-
- /**
- * Implemented per API documentation of {@link Map.Entry#equals(Object)}
- **/
- public boolean equals(Object o) {
- if( o == null ) return false;
- if( o == this ) return true;
-
- if ( ! (o instanceof Map.Entry ) )
- return false;
- Map.Entry e2 = (Map.Entry)o;
- return ((getKey() == null ?
- e2.getKey() == null : getKey().equals(e2.getKey())) &&
- (getValue() == null ?
- e2.getValue() == null : getValue().equals(e2.getValue())));
- }
-
-
- /**
- * Implemented per API documentation of {@link Map.Entry#hashCode()}
- **/
- public int hashCode() {
- return ( ( getKey() == null ? 0 : getKey().hashCode() ) ^
- ( getValue() == null ? 0 : getValue().hashCode() ) );
- }
-
-
-
- // Map.Entry interface
- //-------------------------------------------------------------------------
- public Object getKey() {
- return key;
- }
-
- public Object getValue() {
- return value;
- }
-
- // Properties
- //-------------------------------------------------------------------------
- public void setKey(Object key) {
- this.key = key;
- }
-
- /** Note that this method only sets the local reference inside this object and
- * does not modify the original Map.
- *
- * @return the old value of the value
- * @param value the new value
- */
- public Object setValue(Object value) {
- Object answer = this.value;
- this.value = value;
- return answer;
- }
-
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/DefaultMapEntry.java,v 1.4 2002/03/13 05:40:30 mas Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/03/13 05:40:30 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.util.Map;
+
+/** A default implementation of {@link Map.Entry Map.Entry}
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ * @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
+ */
+
+public class DefaultMapEntry implements Map.Entry {
+
+ private Object key;
+ private Object value;
+
+ public DefaultMapEntry() {
+ }
+
+ public DefaultMapEntry(Object key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ /**
+ * Implemented per API documentation of {@link Map.Entry#equals(Object)}
+ **/
+ public boolean equals(Object o) {
+ if( o == null ) return false;
+ if( o == this ) return true;
+
+ if ( ! (o instanceof Map.Entry ) )
+ return false;
+ Map.Entry e2 = (Map.Entry)o;
+ return ((getKey() == null ?
+ e2.getKey() == null : getKey().equals(e2.getKey())) &&
+ (getValue() == null ?
+ e2.getValue() == null : getValue().equals(e2.getValue())));
+ }
+
+
+ /**
+ * Implemented per API documentation of {@link Map.Entry#hashCode()}
+ **/
+ public int hashCode() {
+ return ( ( getKey() == null ? 0 : getKey().hashCode() ) ^
+ ( getValue() == null ? 0 : getValue().hashCode() ) );
+ }
+
+
+
+ // Map.Entry interface
+ //-------------------------------------------------------------------------
+ public Object getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public void setKey(Object key) {
+ this.key = key;
+ }
+
+ /** Note that this method only sets the local reference inside this object and
+ * does not modify the original Map.
+ *
+ * @return the old value of the value
+ * @param value the new value
+ */
+ public Object setValue(Object value) {
+ Object answer = this.value;
+ this.value = value;
+ return answer;
+ }
+
+}
1.3 +89 -89 jakarta-commons/collections/src/java/org/apache/commons/collections/HashBag.java
Index: HashBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/HashBag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HashBag.java 10 Feb 2002 08:07:42 -0000 1.2
+++ HashBag.java 13 Mar 2002 05:40:30 -0000 1.3
@@ -1,89 +1,89 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/HashBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.collections;
-
-import java.util.Collection;
-import java.util.HashMap;
-
-/**
- * An implementation of {@link Bag} that is backed by a {@link
- * HashMap}.
- *
- * @author Chuck Burdick
- **/
-public class HashBag extends AbstractBag implements Bag {
- public HashBag() {
- setMap(new HashMap());
- }
-
- /**
- * New {@link Bag} containing all the members of the given
- * collection.
- * @see #addAll
- **/
- public HashBag(Collection c) {
- this();
- addAll(c);
- }
-}
-
-
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/HashBag.java,v 1.3 2002/03/13 05:40:30 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:30 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.collections;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+/**
+ * An implementation of {@link Bag} that is backed by a {@link
+ * HashMap}.
+ *
+ * @author Chuck Burdick
+ **/
+public class HashBag extends AbstractBag implements Bag {
+ public HashBag() {
+ setMap(new HashMap());
+ }
+
+ /**
+ * New {@link Bag} containing all the members of the given
+ * collection.
+ * @see #addAll
+ **/
+ public HashBag(Collection c) {
+ this();
+ addAll(c);
+ }
+}
+
+
1.3 +102 -102 jakarta-commons/collections/src/java/org/apache/commons/collections/IteratorEnumeration.java
Index: IteratorEnumeration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/IteratorEnumeration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IteratorEnumeration.java 10 Feb 2002 08:07:42 -0000 1.2
+++ IteratorEnumeration.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,102 +1,102 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/IteratorEnumeration.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.util.Enumeration;
-import java.util.Iterator;
-
-/** Adapter to make an {@link Iterator Iterator} instance appear to be an {@link Enumeration Enumeration} instances
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-
-public class IteratorEnumeration implements Enumeration {
-
- private Iterator iterator;
-
- public IteratorEnumeration() {
- }
-
- public IteratorEnumeration( Iterator iterator ) {
- this.iterator = iterator;
- }
-
- // Iterator interface
- //-------------------------------------------------------------------------
- public boolean hasMoreElements() {
- return iterator.hasNext();
- }
-
- public Object nextElement() {
- return iterator.next();
- }
-
- // Properties
- //-------------------------------------------------------------------------
- public Iterator getIterator() {
- return iterator;
- }
-
- public void setIterator( Iterator iterator ) {
- this.iterator = iterator;
- }
-
-}
\ No newline at end of file
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/IteratorEnumeration.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/** Adapter to make an {@link Iterator Iterator} instance appear to be an {@link Enumeration Enumeration} instances
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+
+public class IteratorEnumeration implements Enumeration {
+
+ private Iterator iterator;
+
+ public IteratorEnumeration() {
+ }
+
+ public IteratorEnumeration( Iterator iterator ) {
+ this.iterator = iterator;
+ }
+
+ // Iterator interface
+ //-------------------------------------------------------------------------
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+
+ public Object nextElement() {
+ return iterator.next();
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public Iterator getIterator() {
+ return iterator;
+ }
+
+ public void setIterator( Iterator iterator ) {
+ this.iterator = iterator;
+ }
+
+}
1.4 +428 -428 jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java
Index: MapUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MapUtils.java 23 Feb 2002 03:50:23 -0000 1.3
+++ MapUtils.java 13 Mar 2002 05:40:31 -0000 1.4
@@ -1,428 +1,428 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.3 2002/02/23 03:50:23 bayard Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/23 03:50:23 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.io.*;
-import java.text.*;
-import java.util.*;
-
-/** A helper class for using {@link Map Map} instances.
- *
- * It contains various typesafe methods
- * as well as other useful features like deep copying
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- *
- * @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
- * @author <a href="mailto:knielsen@apache.org">Kasper Nielsen</a>
- */
-public class MapUtils {
-
- private static int debugIndent = 0;
-
-
-
- // Type safe getters
- //-------------------------------------------------------------------------
- public static Object getObject( Map map, Object key ) {
- if ( map != null ) {
- return map.get( key );
- }
- return null;
- }
-
- public static String getString( Map map, Object key ) {
- if ( map != null ) {
- Object answer = map.get( key );
- if ( answer != null ) {
- return answer.toString();
- }
- }
- return null;
- }
-
- public static Boolean getBoolean( Map map, Object key ) {
- if ( map != null ) {
- Object answer = map.get( key );
- if ( answer != null ) {
- if ( answer instanceof Boolean ) {
- return (Boolean) answer;
- }
- else
- if ( answer instanceof String ) {
- return new Boolean( (String) answer );
- }
- else
- if ( answer instanceof Number ) {
- Number n = (Number) answer;
- return ( n.intValue() != 0 ) ? Boolean.TRUE : Boolean.FALSE;
- }
- }
- }
- return null;
- }
-
- public static Number getNumber( Map map, Object key ) {
- if ( map != null ) {
- Object answer = map.get( key );
- if ( answer != null ) {
- if ( answer instanceof Number ) {
- return (Number) answer;
- }
- else
- if ( answer instanceof String ) {
- try {
- String text = (String) answer;
- return NumberFormat.getInstance().parse( text );
- }
- catch (ParseException e) {
- logInfo( e );
- }
- }
- }
- }
- return null;
- }
-
- public static Byte getByte( Map map, Object key ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- return null;
- }
- else
- if ( answer instanceof Byte ) {
- return (Byte) answer;
- }
- return new Byte( answer.byteValue() );
- }
-
- public static Short getShort( Map map, Object key ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- return null;
- }
- else
- if ( answer instanceof Short ) {
- return (Short) answer;
- }
- return new Short( answer.shortValue() );
- }
-
- public static Integer getInteger( Map map, Object key ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- return null;
- }
- else
- if ( answer instanceof Integer ) {
- return (Integer) answer;
- }
- return new Integer( answer.intValue() );
- }
-
- public static Long getLong( Map map, Object key ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- return null;
- }
- else
- if ( answer instanceof Long ) {
- return (Long) answer;
- }
- return new Long( answer.longValue() );
- }
-
- public static Float getFloat( Map map, Object key ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- return null;
- }
- else
- if ( answer instanceof Float ) {
- return (Float) answer;
- }
- return new Float( answer.floatValue() );
- }
-
- public static Double getDouble( Map map, Object key ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- return null;
- }
- else
- if ( answer instanceof Double ) {
- return (Double) answer;
- }
- return new Double( answer.doubleValue() );
- }
-
- public static Map getMap( Map map, Object key ) {
- if ( map != null ) {
- Object answer = map.get( key );
- if ( answer != null && answer instanceof Map ) {
- return (Map) answer;
- }
- }
- return null;
- }
-
- // Type safe getters with default values
- //-------------------------------------------------------------------------
- public static Object getObject( Map map, Object key, Object defaultValue ) {
- if ( map != null ) {
- Object answer = map.get( key );
- if ( answer != null ) {
- return answer;
- }
- }
- return defaultValue;
- }
-
- public static String getString( Map map, Object key, String defaultValue ) {
- String answer = getString( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Boolean getBoolean( Map map, Object key, Boolean defaultValue ) {
- Boolean answer = getBoolean( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Number getNumber( Map map, Object key, Number defaultValue ) {
- Number answer = getNumber( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Byte getByte( Map map, Object key, Byte defaultValue ) {
- Byte answer = getByte( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Short getShort( Map map, Object key, Short defaultValue ) {
- Short answer = getShort( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Integer getInteger( Map map, Object key, Integer defaultValue ) {
- Integer answer = getInteger( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Long getLong( Map map, Object key, Long defaultValue ) {
- Long answer = getLong( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Float getFloat( Map map, Object key, Float defaultValue ) {
- Float answer = getFloat( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Double getDouble( Map map, Object key, Double defaultValue ) {
- Double answer = getDouble( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- public static Map getMap( Map map, Object key, Map defaultValue ) {
- Map answer = getMap( map, key );
- if ( answer == null ) {
- answer = defaultValue;
- }
- return answer;
- }
-
- // Conversion methods
- //-------------------------------------------------------------------------
- public static Properties toProperties(Map input) {
- Properties answer = new Properties();
- if ( input != null ) {
- for ( Iterator iter = input.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object key = entry.getKey();
- Object value = entry.getValue();
- answer.put(key, value);
- }
- }
- return answer;
- }
-
- // Printing methods
- //-------------------------------------------------------------------------
- public static synchronized void verbosePrint( PrintStream out, Object key, Map map ) {
- debugPrintIndent( out );
- out.println( key + " = " );
-
- debugPrintIndent( out );
- out.println( "{" );
- ++debugIndent;
-
- for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- String childKey = (String) entry.getKey();
- Object childValue = entry.getValue();
- if ( childValue instanceof Map ) {
- verbosePrint( out, childKey, (Map) childValue );
- }
- else {
- debugPrintIndent( out );
- out.println( childKey + " = " + childValue);
- }
- }
- --debugIndent;
- debugPrintIndent( out );
- out.println( "}" );
- }
-
- public static synchronized void debugPrint( PrintStream out, Object key, Map map ) {
- debugPrintIndent( out );
- out.println( key + " = " );
-
- debugPrintIndent( out );
- out.println( "{" );
- ++debugIndent;
-
- for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- String childKey = (String) entry.getKey();
- Object childValue = entry.getValue();
- if ( childValue instanceof Map ) {
- verbosePrint( out, childKey, (Map) childValue );
- }
- else {
- debugPrintIndent( out );
-
- String typeName = ( childValue != null )
- ? childValue.getClass().getName()
- : null;
-
- out.println( childKey + " = " + childValue + " class: " + typeName );
- }
- }
- --debugIndent;
- debugPrintIndent( out );
- out.println( "}" );
- }
-
- // Implementation methods
- //-------------------------------------------------------------------------
- protected static void debugPrintIndent( PrintStream out ) {
- for ( int i = 0; i < debugIndent; i++ ) {
- out.print( " " );
- }
- }
-
- protected static void logInfo(Exception e) {
- // XXXX: should probably use log4j here instead...
- System.out.println( "INFO: Exception: " + e );
- }
-
-
- /**
- * Nice method for adding data to a map in such a way
- * as to not get NPE's. The point being that if the
- * value is null, map.put() will throw an exception.
- * That blows in the case of this class cause you may want to
- * essentially treat put("Not Null", null ) == put("Not Null", "")
- * We will still throw a NPE if the key is null cause that should
- * never happen.
- */
- public static final void safeAddToMap(Map map, Object key, Object value)
- throws NullPointerException
- {
- if (value == null)
- {
- map.put ( key, "" );
- }
- else
- {
- map.put ( key, value );
- }
- }
-
-
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.4 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+
+/** A helper class for using {@link Map Map} instances.
+ *
+ * It contains various typesafe methods
+ * as well as other useful features like deep copying
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ *
+ * @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
+ * @author <a href="mailto:knielsen@apache.org">Kasper Nielsen</a>
+ */
+public class MapUtils {
+
+ private static int debugIndent = 0;
+
+
+
+ // Type safe getters
+ //-------------------------------------------------------------------------
+ public static Object getObject( Map map, Object key ) {
+ if ( map != null ) {
+ return map.get( key );
+ }
+ return null;
+ }
+
+ public static String getString( Map map, Object key ) {
+ if ( map != null ) {
+ Object answer = map.get( key );
+ if ( answer != null ) {
+ return answer.toString();
+ }
+ }
+ return null;
+ }
+
+ public static Boolean getBoolean( Map map, Object key ) {
+ if ( map != null ) {
+ Object answer = map.get( key );
+ if ( answer != null ) {
+ if ( answer instanceof Boolean ) {
+ return (Boolean) answer;
+ }
+ else
+ if ( answer instanceof String ) {
+ return new Boolean( (String) answer );
+ }
+ else
+ if ( answer instanceof Number ) {
+ Number n = (Number) answer;
+ return ( n.intValue() != 0 ) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Number getNumber( Map map, Object key ) {
+ if ( map != null ) {
+ Object answer = map.get( key );
+ if ( answer != null ) {
+ if ( answer instanceof Number ) {
+ return (Number) answer;
+ }
+ else
+ if ( answer instanceof String ) {
+ try {
+ String text = (String) answer;
+ return NumberFormat.getInstance().parse( text );
+ }
+ catch (ParseException e) {
+ logInfo( e );
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Byte getByte( Map map, Object key ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ return null;
+ }
+ else
+ if ( answer instanceof Byte ) {
+ return (Byte) answer;
+ }
+ return new Byte( answer.byteValue() );
+ }
+
+ public static Short getShort( Map map, Object key ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ return null;
+ }
+ else
+ if ( answer instanceof Short ) {
+ return (Short) answer;
+ }
+ return new Short( answer.shortValue() );
+ }
+
+ public static Integer getInteger( Map map, Object key ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ return null;
+ }
+ else
+ if ( answer instanceof Integer ) {
+ return (Integer) answer;
+ }
+ return new Integer( answer.intValue() );
+ }
+
+ public static Long getLong( Map map, Object key ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ return null;
+ }
+ else
+ if ( answer instanceof Long ) {
+ return (Long) answer;
+ }
+ return new Long( answer.longValue() );
+ }
+
+ public static Float getFloat( Map map, Object key ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ return null;
+ }
+ else
+ if ( answer instanceof Float ) {
+ return (Float) answer;
+ }
+ return new Float( answer.floatValue() );
+ }
+
+ public static Double getDouble( Map map, Object key ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ return null;
+ }
+ else
+ if ( answer instanceof Double ) {
+ return (Double) answer;
+ }
+ return new Double( answer.doubleValue() );
+ }
+
+ public static Map getMap( Map map, Object key ) {
+ if ( map != null ) {
+ Object answer = map.get( key );
+ if ( answer != null && answer instanceof Map ) {
+ return (Map) answer;
+ }
+ }
+ return null;
+ }
+
+ // Type safe getters with default values
+ //-------------------------------------------------------------------------
+ public static Object getObject( Map map, Object key, Object defaultValue ) {
+ if ( map != null ) {
+ Object answer = map.get( key );
+ if ( answer != null ) {
+ return answer;
+ }
+ }
+ return defaultValue;
+ }
+
+ public static String getString( Map map, Object key, String defaultValue ) {
+ String answer = getString( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Boolean getBoolean( Map map, Object key, Boolean defaultValue ) {
+ Boolean answer = getBoolean( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Number getNumber( Map map, Object key, Number defaultValue ) {
+ Number answer = getNumber( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Byte getByte( Map map, Object key, Byte defaultValue ) {
+ Byte answer = getByte( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Short getShort( Map map, Object key, Short defaultValue ) {
+ Short answer = getShort( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Integer getInteger( Map map, Object key, Integer defaultValue ) {
+ Integer answer = getInteger( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Long getLong( Map map, Object key, Long defaultValue ) {
+ Long answer = getLong( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Float getFloat( Map map, Object key, Float defaultValue ) {
+ Float answer = getFloat( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Double getDouble( Map map, Object key, Double defaultValue ) {
+ Double answer = getDouble( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ public static Map getMap( Map map, Object key, Map defaultValue ) {
+ Map answer = getMap( map, key );
+ if ( answer == null ) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+
+ // Conversion methods
+ //-------------------------------------------------------------------------
+ public static Properties toProperties(Map input) {
+ Properties answer = new Properties();
+ if ( input != null ) {
+ for ( Iterator iter = input.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ answer.put(key, value);
+ }
+ }
+ return answer;
+ }
+
+ // Printing methods
+ //-------------------------------------------------------------------------
+ public static synchronized void verbosePrint( PrintStream out, Object key, Map map ) {
+ debugPrintIndent( out );
+ out.println( key + " = " );
+
+ debugPrintIndent( out );
+ out.println( "{" );
+ ++debugIndent;
+
+ for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String childKey = (String) entry.getKey();
+ Object childValue = entry.getValue();
+ if ( childValue instanceof Map ) {
+ verbosePrint( out, childKey, (Map) childValue );
+ }
+ else {
+ debugPrintIndent( out );
+ out.println( childKey + " = " + childValue);
+ }
+ }
+ --debugIndent;
+ debugPrintIndent( out );
+ out.println( "}" );
+ }
+
+ public static synchronized void debugPrint( PrintStream out, Object key, Map map ) {
+ debugPrintIndent( out );
+ out.println( key + " = " );
+
+ debugPrintIndent( out );
+ out.println( "{" );
+ ++debugIndent;
+
+ for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String childKey = (String) entry.getKey();
+ Object childValue = entry.getValue();
+ if ( childValue instanceof Map ) {
+ verbosePrint( out, childKey, (Map) childValue );
+ }
+ else {
+ debugPrintIndent( out );
+
+ String typeName = ( childValue != null )
+ ? childValue.getClass().getName()
+ : null;
+
+ out.println( childKey + " = " + childValue + " class: " + typeName );
+ }
+ }
+ --debugIndent;
+ debugPrintIndent( out );
+ out.println( "}" );
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected static void debugPrintIndent( PrintStream out ) {
+ for ( int i = 0; i < debugIndent; i++ ) {
+ out.print( " " );
+ }
+ }
+
+ protected static void logInfo(Exception e) {
+ // XXXX: should probably use log4j here instead...
+ System.out.println( "INFO: Exception: " + e );
+ }
+
+
+ /**
+ * Nice method for adding data to a map in such a way
+ * as to not get NPE's. The point being that if the
+ * value is null, map.put() will throw an exception.
+ * That blows in the case of this class cause you may want to
+ * essentially treat put("Not Null", null ) == put("Not Null", "")
+ * We will still throw a NPE if the key is null cause that should
+ * never happen.
+ */
+ public static final void safeAddToMap(Map map, Object key, Object value)
+ throws NullPointerException
+ {
+ if (value == null)
+ {
+ map.put ( key, "" );
+ }
+ else
+ {
+ map.put ( key, value );
+ }
+ }
+
+
+}
1.3 +206 -206 jakarta-commons/collections/src/java/org/apache/commons/collections/MultiHashMap.java
Index: MultiHashMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiHashMap.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MultiHashMap.java 10 Feb 2002 08:07:42 -0000 1.2
+++ MultiHashMap.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,206 +1,206 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiHashMap.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.util.*;
-import java.io.*;
-
-/** see MultiMap for details of an important semantic difference
- * between this and a typical HashMap
- *
- * @author Christopher Berry
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public class MultiHashMap extends HashMap implements MultiMap
-{
- //----------------- Data
- private static int sCount = 0;
- private String mName = null;
-
- public MultiHashMap()
- {
- super();
- setName();
- }
-
- public MultiHashMap( int initialCapacity )
- {
- super( initialCapacity );
- setName();
- }
-
- public MultiHashMap(int initialCapacity, float loadFactor )
- {
- super( initialCapacity, loadFactor);
- setName();
- }
-
- public MultiHashMap( Map mapToCopy )
- {
- super( mapToCopy );
- }
-
- private void setName()
- {
- sCount++;
- mName = "MultiMap-" + sCount;
- }
-
- public String getName()
- { return mName; }
-
- public Object put( Object key, Object value )
- {
- // NOTE:: put might be called during deserialization !!!!!!
- // so we must provide a hook to handle this case
- // This means that we cannot make MultiMaps of ArrayLists !!!
-
- if ( value instanceof ArrayList ) {
- return ( super.put( key, value ) );
- }
-
- ArrayList keyList = (ArrayList)(super.get( key ));
- if ( keyList == null ) {
- keyList = new ArrayList(10);
-
- super.put( key, keyList );
- }
-
- boolean results = keyList.add( value );
-
- return ( results ? value : null );
- }
-
- public boolean containsValue( Object value )
- {
- Set pairs = super.entrySet();
-
- if ( pairs == null )
- return false;
-
- Iterator pairsIterator = pairs.iterator();
- while ( pairsIterator.hasNext() ) {
- Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
- ArrayList list = (ArrayList)(keyValuePair.getValue());
- if( list.contains( value ) )
- return true;
- }
- return false;
- }
-
- public Object remove( Object key, Object item )
- {
- ArrayList valuesForKey = (ArrayList) super.get( key );
-
- if ( valuesForKey == null )
- return null;
-
- valuesForKey.remove( item );
- return item;
- }
-
- public void clear()
- {
- Set pairs = super.entrySet();
- Iterator pairsIterator = pairs.iterator();
- while ( pairsIterator.hasNext() ) {
- Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
- ArrayList list = (ArrayList)(keyValuePair.getValue());
- list.clear();
- }
- super.clear();
- }
-
- public void putAll( Map mapToPut )
- {
- super.putAll( mapToPut );
- }
-
- public Collection values()
- {
- ArrayList returnList = new ArrayList( super.size() );
-
- Set pairs = super.entrySet();
- Iterator pairsIterator = pairs.iterator();
- while ( pairsIterator.hasNext() ) {
- Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
- ArrayList list = (ArrayList)(keyValuePair.getValue());
-
- Object[] values = list.toArray();
- for( int ii=0; ii < values.length; ii++ ) {
- boolean successfulAdd = returnList.add( values[ii] );
- }
- }
- return returnList;
- }
-
- // FIXME:: do we need to implement this??
- // public boolean equals( Object obj ) {}
-
- // --------------- From Cloneable
- public Object clone()
- {
- MultiHashMap obj = (MultiHashMap)(super.clone());
- obj.mName = mName;
- return obj;
- }
-
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiHashMap.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.util.*;
+import java.io.*;
+
+/** see MultiMap for details of an important semantic difference
+ * between this and a typical HashMap
+ *
+ * @author Christopher Berry
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+public class MultiHashMap extends HashMap implements MultiMap
+{
+ //----------------- Data
+ private static int sCount = 0;
+ private String mName = null;
+
+ public MultiHashMap()
+ {
+ super();
+ setName();
+ }
+
+ public MultiHashMap( int initialCapacity )
+ {
+ super( initialCapacity );
+ setName();
+ }
+
+ public MultiHashMap(int initialCapacity, float loadFactor )
+ {
+ super( initialCapacity, loadFactor);
+ setName();
+ }
+
+ public MultiHashMap( Map mapToCopy )
+ {
+ super( mapToCopy );
+ }
+
+ private void setName()
+ {
+ sCount++;
+ mName = "MultiMap-" + sCount;
+ }
+
+ public String getName()
+ { return mName; }
+
+ public Object put( Object key, Object value )
+ {
+ // NOTE:: put might be called during deserialization !!!!!!
+ // so we must provide a hook to handle this case
+ // This means that we cannot make MultiMaps of ArrayLists !!!
+
+ if ( value instanceof ArrayList ) {
+ return ( super.put( key, value ) );
+ }
+
+ ArrayList keyList = (ArrayList)(super.get( key ));
+ if ( keyList == null ) {
+ keyList = new ArrayList(10);
+
+ super.put( key, keyList );
+ }
+
+ boolean results = keyList.add( value );
+
+ return ( results ? value : null );
+ }
+
+ public boolean containsValue( Object value )
+ {
+ Set pairs = super.entrySet();
+
+ if ( pairs == null )
+ return false;
+
+ Iterator pairsIterator = pairs.iterator();
+ while ( pairsIterator.hasNext() ) {
+ Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
+ ArrayList list = (ArrayList)(keyValuePair.getValue());
+ if( list.contains( value ) )
+ return true;
+ }
+ return false;
+ }
+
+ public Object remove( Object key, Object item )
+ {
+ ArrayList valuesForKey = (ArrayList) super.get( key );
+
+ if ( valuesForKey == null )
+ return null;
+
+ valuesForKey.remove( item );
+ return item;
+ }
+
+ public void clear()
+ {
+ Set pairs = super.entrySet();
+ Iterator pairsIterator = pairs.iterator();
+ while ( pairsIterator.hasNext() ) {
+ Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
+ ArrayList list = (ArrayList)(keyValuePair.getValue());
+ list.clear();
+ }
+ super.clear();
+ }
+
+ public void putAll( Map mapToPut )
+ {
+ super.putAll( mapToPut );
+ }
+
+ public Collection values()
+ {
+ ArrayList returnList = new ArrayList( super.size() );
+
+ Set pairs = super.entrySet();
+ Iterator pairsIterator = pairs.iterator();
+ while ( pairsIterator.hasNext() ) {
+ Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
+ ArrayList list = (ArrayList)(keyValuePair.getValue());
+
+ Object[] values = list.toArray();
+ for( int ii=0; ii < values.length; ii++ ) {
+ boolean successfulAdd = returnList.add( values[ii] );
+ }
+ }
+ return returnList;
+ }
+
+ // FIXME:: do we need to implement this??
+ // public boolean equals( Object obj ) {}
+
+ // --------------- From Cloneable
+ public Object clone()
+ {
+ MultiHashMap obj = (MultiHashMap)(super.clone());
+ obj.mName = mName;
+ return obj;
+ }
+
+}
1.3 +80 -80 jakarta-commons/collections/src/java/org/apache/commons/collections/MultiMap.java
Index: MultiMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiMap.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MultiMap.java 10 Feb 2002 08:07:42 -0000 1.2
+++ MultiMap.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,80 +1,80 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiMap.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.util.Map;
-
-/**
- * This is simply a Map with slightly different semantics.
- * Instead of returning an Object, it returns a Collection.
- * So for example, you can put( key, new Integer(1) );
- * and then a Object get( key ); will return you a Collection
- * instead of an Integer.
- * Thus, this is simply a tag interface.
- *
- * @author Christopher Berry
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public interface MultiMap extends Map {
-
- public Object remove( Object key, Object item );
-
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiMap.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.util.Map;
+
+/**
+ * This is simply a Map with slightly different semantics.
+ * Instead of returning an Object, it returns a Collection.
+ * So for example, you can put( key, new Integer(1) );
+ * and then a Object get( key ); will return you a Collection
+ * instead of an Integer.
+ * Thus, this is simply a tag interface.
+ *
+ * @author Christopher Berry
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+public interface MultiMap extends Map {
+
+ public Object remove( Object key, Object item );
+
+}
1.3 +73 -73 jakarta-commons/collections/src/java/org/apache/commons/collections/Predicate.java
Index: Predicate.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Predicate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Predicate.java 10 Feb 2002 08:07:42 -0000 1.2
+++ Predicate.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,73 +1,73 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Predicate.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-/** Performs some predicate which returns true or false based on the input object.
- * Predicate instances can be used to implement queries or to do filtering.
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public interface Predicate {
-
- /** @return true if the input object matches this predicate, else returns false
- */
- public boolean evaluate(Object input);
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Predicate.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+/** Performs some predicate which returns true or false based on the input object.
+ * Predicate instances can be used to implement queries or to do filtering.
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+public interface Predicate {
+
+ /** @return true if the input object matches this predicate, else returns false
+ */
+ public boolean evaluate(Object input);
+}
1.4 +98 -98 jakarta-commons/collections/src/java/org/apache/commons/collections/SingletonIterator.java
Index: SingletonIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SingletonIterator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SingletonIterator.java 26 Feb 2002 21:30:40 -0000 1.3
+++ SingletonIterator.java 13 Mar 2002 05:40:31 -0000 1.4
@@ -1,98 +1,98 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SingletonIterator.java,v 1.3 2002/02/26 21:30:40 morgand Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/26 21:30:40 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/** <p><code>SingletonIterator</code> is an {@link Iterator} over a single
- * object instance.</p>
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Revision: 1.3 $
- */
-public class SingletonIterator implements Iterator {
-
- private boolean first = true;
- private Object object;
-
- public SingletonIterator(Object object) {
- this.object = object;
- }
-
- public boolean hasNext() {
- return first;
- }
-
- public Object next() {
- if (! first ) {
- throw new NoSuchElementException();
- }
- Object answer = object;
- object = null;
- first = false;
- return answer;
- }
-
- public void remove() {
- throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
- }
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SingletonIterator.java,v 1.4 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/** <p><code>SingletonIterator</code> is an {@link Iterator} over a single
+ * object instance.</p>
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ * @version $Revision: 1.4 $
+ */
+public class SingletonIterator implements Iterator {
+
+ private boolean first = true;
+ private Object object;
+
+ public SingletonIterator(Object object) {
+ this.object = object;
+ }
+
+ public boolean hasNext() {
+ return first;
+ }
+
+ public Object next() {
+ if (! first ) {
+ throw new NoSuchElementException();
+ }
+ Object answer = object;
+ object = null;
+ first = false;
+ return answer;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
+ }
+}
1.3 +344 -344 jakarta-commons/collections/src/java/org/apache/commons/collections/SoftRefHashMap.java
Index: SoftRefHashMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SoftRefHashMap.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SoftRefHashMap.java 10 Feb 2002 08:07:42 -0000 1.2
+++ SoftRefHashMap.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,344 +1,344 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SoftRefHashMap.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.lang.ref.*;
-import java.lang.reflect.*;
-import java.util.*;
-
-/** <p>
- * HashMap with SoftReference links to values which allows the values of the Map
- * to be garbage collected by the JVM if it becomes low on memory.
- * Derive from this class and
- * override the factory method <code>createReference()</code> method to make
- * a Map wrapped in other types of Reference.
- * </p>
- *
- * <p>
- * A synchronized version can be obtained with:
- * <code>Collections.synchronizedMap( theMapToSynchronize )</code>
- * </p>
- *
- * <p>
- * <b>WARNING</b> the values() and entrySet() methods require optimisation
- * like the standard {@link HashMap} implementations so that iteration
- * over this Map is efficient.
- * </p>
- *
- * @author James.Dodd
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public class SoftRefHashMap implements Map {
-
- /** The wrapped HashMap */
- private Map hashMap = new HashMap();
-
-
- public SoftRefHashMap() {
- }
-
-
- /**
- * Removes References that have had their referents garbage collected
- */
- public void purge() {
- Map map = getMap();
- Set keys = map.keySet();
- if ( keys == null ) {
- return;
- }
- for ( Iterator i = keys.iterator(); i.hasNext(); ) {
- Object key = (Object) i.next();
- Reference ref = (Reference) map.get( key );
- if ( ref.get() == null ) {
- map.remove( key );
- }
- }
- }
-
- // Map implementation
- // -------------------------------------------------------
-
- /**
- * Retrieves the referent of the Referenced value
- * @param key The key with which to retrieve the value
- */
- public Object get( final Object key ) {
- Reference ref = (Reference) getMap().get( key );
- if ( ref == null ) {
- return null;
- }
- return ref.get();
- }
-
- /**
- * Adds a key-value mapping, wrapping the value in a Reference
- */
- public Object put( final Object key, final Object value ) {
- Object answer = getMap().put( key, createReference( value ) );
- if ( answer != null ) {
- return ((Reference) answer).get();
- }
- return null;
- }
-
- /**
- * Returns a collection of the Referenced values
- */
- public Collection values() {
- Set wrappedValues = (Set) getMap().values();
- Set values = new TreeSet();
- if ( wrappedValues == null ) {
- return values;
- }
- for ( Iterator i = wrappedValues.iterator(); i.hasNext(); ) {
- Reference ref = (Reference) i.next();
- if ( ref != null ) {
- values.add( ref.get() );
- }
- }
- return values;
- }
-
- /**
- * Answers whether the argument is in the domain of the mappings
- */
- public boolean containsKey( Object key ) {
- return getMap().containsKey( key );
- }
-
- /**
- * Answers whether the argument is a Referenced value
- */
- public boolean containsValue( Object value ) {
- Collection values = (Collection) getMap().values();
- if ( values == null ) {
- return false;
- }
- for ( Iterator i = values.iterator(); i.hasNext(); ) {
- Reference ref = (Reference) i.next();
- if ( ref == null ) {
- continue;
- }
- Object target = ref.get();
- if ( target == value ) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Put all of the mappings in the argument into this wrapped map
- */
- public void putAll( final java.util.Map map ) {
- if ( map == null || map.size() == 0 ) {
- return;
- }
- for ( Iterator i = map.keySet().iterator(); i.hasNext(); ) {
- Object key = (Object) i.next();
- put( key, map.get( key ) );
- }
- }
-
- /**
- * Returns a set view of the mappings in the wrapped map
- */
- public Set entrySet() {
- Set entries = new HashSet();
- if ( size() == 0 ) {
- return entries;
- }
- for ( Iterator i = keySet().iterator(); i.hasNext(); ) {
- Object key = i.next();
- Object value = get( key );
- Entry entry = new Entry( key, value );
- entries.add( entry );
- }
- return entries;
- }
-
- /**
- * Removes a mapping from this map
- */
- public Object remove( final Object key ) {
- Reference ref = (Reference) getMap().remove( key );
- if ( ref != null ) {
- return ref.get();
- }
- return null;
- }
-
- /**
- * Clears all mappings
- */
- public void clear() {
- getMap().clear();
- }
-
- /**
- * Calculates the hash code for this map
- */
- public int hashCode() {
- return getMap().hashCode();
- }
-
- /**
- * Returns the domain of the mappings
- */
- public Set keySet() {
- return getMap().keySet();
- }
-
- /**
- * Answers whether there are any mappings
- */
- public boolean isEmpty() {
- return getMap().isEmpty();
- }
-
- /**
- * Answers whether this map and the argument are 'the same'
- */
- public boolean equals( final Object object ) {
- return getMap().equals( object );
- }
-
- /**
- * Returns the number of mappings in this map
- */
- public int size() {
- return getMap().size();
- }
-
- // Inner Classes
- // ---------------------------------------------------------------------
-
- /**
- * A map entry, which is backed by this RefHashMap
- */
- class Entry implements Map.Entry {
-
- /**
- * Constructor
- */
- public Entry( Object key, Object value ) {
- this.key = key;
- this.value = value;
- }
-
- // Map.Entry interface
- // -----------------------------------------------------------
-
- /**
- * Retrieves the key of this mapping
- */
- public Object getKey() {
- return key;
- }
-
- /**
- * Retrieves the value of this mapping
- */
- public Object getValue() {
- return value;
- }
-
- /**
- * Sets the value of this mapping
- */
- public Object setValue( Object value ) {
- this.value = value;
- put( key, value );
- return value;
- }
-
- /**
- * Return the hash code of this mapping.
- * This algorithm was taken from the JavaDoc for Map.Entry
- */
- public int hashCode() {
- return ( getKey() == null ? 0 : getKey().hashCode() ) ^
- ( getValue() == null ? 0 : getValue().hashCode() );
- }
-
- /** The domain of this mapping */
- private Object key;
- /** The range of this mapping */
- private Object value;
- }
-
- /**
- * Returns a reference to the argument.
- * Override this method to make wrapped maps for other Reference types
- */
- protected Reference createReference( Object referent ) {
- return new SoftReference( referent );
- }
-
- /**
- * Retrieves the wrapped HashMap
- * @return The wrapped HashMap
- */
- protected Map getMap() {
- return hashMap;
- }
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SoftRefHashMap.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.lang.ref.*;
+import java.lang.reflect.*;
+import java.util.*;
+
+/** <p>
+ * HashMap with SoftReference links to values which allows the values of the Map
+ * to be garbage collected by the JVM if it becomes low on memory.
+ * Derive from this class and
+ * override the factory method <code>createReference()</code> method to make
+ * a Map wrapped in other types of Reference.
+ * </p>
+ *
+ * <p>
+ * A synchronized version can be obtained with:
+ * <code>Collections.synchronizedMap( theMapToSynchronize )</code>
+ * </p>
+ *
+ * <p>
+ * <b>WARNING</b> the values() and entrySet() methods require optimisation
+ * like the standard {@link HashMap} implementations so that iteration
+ * over this Map is efficient.
+ * </p>
+ *
+ * @author James.Dodd
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+public class SoftRefHashMap implements Map {
+
+ /** The wrapped HashMap */
+ private Map hashMap = new HashMap();
+
+
+ public SoftRefHashMap() {
+ }
+
+
+ /**
+ * Removes References that have had their referents garbage collected
+ */
+ public void purge() {
+ Map map = getMap();
+ Set keys = map.keySet();
+ if ( keys == null ) {
+ return;
+ }
+ for ( Iterator i = keys.iterator(); i.hasNext(); ) {
+ Object key = (Object) i.next();
+ Reference ref = (Reference) map.get( key );
+ if ( ref.get() == null ) {
+ map.remove( key );
+ }
+ }
+ }
+
+ // Map implementation
+ // -------------------------------------------------------
+
+ /**
+ * Retrieves the referent of the Referenced value
+ * @param key The key with which to retrieve the value
+ */
+ public Object get( final Object key ) {
+ Reference ref = (Reference) getMap().get( key );
+ if ( ref == null ) {
+ return null;
+ }
+ return ref.get();
+ }
+
+ /**
+ * Adds a key-value mapping, wrapping the value in a Reference
+ */
+ public Object put( final Object key, final Object value ) {
+ Object answer = getMap().put( key, createReference( value ) );
+ if ( answer != null ) {
+ return ((Reference) answer).get();
+ }
+ return null;
+ }
+
+ /**
+ * Returns a collection of the Referenced values
+ */
+ public Collection values() {
+ Set wrappedValues = (Set) getMap().values();
+ Set values = new TreeSet();
+ if ( wrappedValues == null ) {
+ return values;
+ }
+ for ( Iterator i = wrappedValues.iterator(); i.hasNext(); ) {
+ Reference ref = (Reference) i.next();
+ if ( ref != null ) {
+ values.add( ref.get() );
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Answers whether the argument is in the domain of the mappings
+ */
+ public boolean containsKey( Object key ) {
+ return getMap().containsKey( key );
+ }
+
+ /**
+ * Answers whether the argument is a Referenced value
+ */
+ public boolean containsValue( Object value ) {
+ Collection values = (Collection) getMap().values();
+ if ( values == null ) {
+ return false;
+ }
+ for ( Iterator i = values.iterator(); i.hasNext(); ) {
+ Reference ref = (Reference) i.next();
+ if ( ref == null ) {
+ continue;
+ }
+ Object target = ref.get();
+ if ( target == value ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Put all of the mappings in the argument into this wrapped map
+ */
+ public void putAll( final java.util.Map map ) {
+ if ( map == null || map.size() == 0 ) {
+ return;
+ }
+ for ( Iterator i = map.keySet().iterator(); i.hasNext(); ) {
+ Object key = (Object) i.next();
+ put( key, map.get( key ) );
+ }
+ }
+
+ /**
+ * Returns a set view of the mappings in the wrapped map
+ */
+ public Set entrySet() {
+ Set entries = new HashSet();
+ if ( size() == 0 ) {
+ return entries;
+ }
+ for ( Iterator i = keySet().iterator(); i.hasNext(); ) {
+ Object key = i.next();
+ Object value = get( key );
+ Entry entry = new Entry( key, value );
+ entries.add( entry );
+ }
+ return entries;
+ }
+
+ /**
+ * Removes a mapping from this map
+ */
+ public Object remove( final Object key ) {
+ Reference ref = (Reference) getMap().remove( key );
+ if ( ref != null ) {
+ return ref.get();
+ }
+ return null;
+ }
+
+ /**
+ * Clears all mappings
+ */
+ public void clear() {
+ getMap().clear();
+ }
+
+ /**
+ * Calculates the hash code for this map
+ */
+ public int hashCode() {
+ return getMap().hashCode();
+ }
+
+ /**
+ * Returns the domain of the mappings
+ */
+ public Set keySet() {
+ return getMap().keySet();
+ }
+
+ /**
+ * Answers whether there are any mappings
+ */
+ public boolean isEmpty() {
+ return getMap().isEmpty();
+ }
+
+ /**
+ * Answers whether this map and the argument are 'the same'
+ */
+ public boolean equals( final Object object ) {
+ return getMap().equals( object );
+ }
+
+ /**
+ * Returns the number of mappings in this map
+ */
+ public int size() {
+ return getMap().size();
+ }
+
+ // Inner Classes
+ // ---------------------------------------------------------------------
+
+ /**
+ * A map entry, which is backed by this RefHashMap
+ */
+ class Entry implements Map.Entry {
+
+ /**
+ * Constructor
+ */
+ public Entry( Object key, Object value ) {
+ this.key = key;
+ this.value = value;
+ }
+
+ // Map.Entry interface
+ // -----------------------------------------------------------
+
+ /**
+ * Retrieves the key of this mapping
+ */
+ public Object getKey() {
+ return key;
+ }
+
+ /**
+ * Retrieves the value of this mapping
+ */
+ public Object getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value of this mapping
+ */
+ public Object setValue( Object value ) {
+ this.value = value;
+ put( key, value );
+ return value;
+ }
+
+ /**
+ * Return the hash code of this mapping.
+ * This algorithm was taken from the JavaDoc for Map.Entry
+ */
+ public int hashCode() {
+ return ( getKey() == null ? 0 : getKey().hashCode() ) ^
+ ( getValue() == null ? 0 : getValue().hashCode() );
+ }
+
+ /** The domain of this mapping */
+ private Object key;
+ /** The range of this mapping */
+ private Object value;
+ }
+
+ /**
+ * Returns a reference to the argument.
+ * Override this method to make wrapped maps for other Reference types
+ */
+ protected Reference createReference( Object referent ) {
+ return new SoftReference( referent );
+ }
+
+ /**
+ * Retrieves the wrapped HashMap
+ * @return The wrapped HashMap
+ */
+ protected Map getMap() {
+ return hashMap;
+ }
+}
1.3 +88 -88 jakarta-commons/collections/src/java/org/apache/commons/collections/SortedBag.java
Index: SortedBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SortedBag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SortedBag.java 10 Feb 2002 08:07:42 -0000 1.2
+++ SortedBag.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,88 +1,88 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SortedBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.collections;
-
-import java.util.Comparator;
-
-/**
- * A type of {@link Bag} that maintains order among its unique
- * representative members.
- * @author Chuck Burdick
- **/
-public interface SortedBag extends Bag {
-
- /**
- * Returns the comparator associated with this sorted set, or null
- * if it uses its elements' natural ordering.
- **/
- public Comparator comparator();
-
- /**
- * Returns the first (lowest) member.
- **/
- public Object first();
-
- /**
- * Returns the last (highest) member.
- **/
- public Object last();
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SortedBag.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.collections;
+
+import java.util.Comparator;
+
+/**
+ * A type of {@link Bag} that maintains order among its unique
+ * representative members.
+ * @author Chuck Burdick
+ **/
+public interface SortedBag extends Bag {
+
+ /**
+ * Returns the comparator associated with this sorted set, or null
+ * if it uses its elements' natural ordering.
+ **/
+ public Comparator comparator();
+
+ /**
+ * Returns the first (lowest) member.
+ **/
+ public Object first();
+
+ /**
+ * Returns the last (highest) member.
+ **/
+ public Object last();
+}
1.3 +120 -120 jakarta-commons/collections/src/java/org/apache/commons/collections/TransformIterator.java
Index: TransformIterator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TransformIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransformIterator.java 10 Feb 2002 08:07:42 -0000 1.2
+++ TransformIterator.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,120 +1,120 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TransformIterator.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-import java.util.Enumeration;
-import java.util.Iterator;
-
-/** A Proxy {@link Iterator Iterator} which uses a {@link Transformer Transformer} instance to
- * transform the contents of the {@link Iterator Iterator} into some other form
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-
-public class TransformIterator extends ProxyIterator {
-
- /** Holds value of property transformer. */
- private Transformer transformer;
-
-
- public TransformIterator() {
- }
-
- public TransformIterator( Iterator iterator ) {
- super( iterator );
- }
-
- public TransformIterator( Iterator iterator, Transformer transformer ) {
- super( iterator );
- this.transformer = transformer;
- }
-
- // Iterator interface
- //-------------------------------------------------------------------------
- public Object next() {
- return transform( super.next() );
- }
-
- // Properties
- //-------------------------------------------------------------------------
- /** Getter for property transformer.
- * @return Value of property transformer.
- */
- public Transformer getTransformer() {
- return transformer;
- }
- /** Setter for property transformer.
- * @param transformer New value of property transformer.
- */
- public void setTransformer(Transformer transformer) {
- this.transformer = transformer;
- }
-
- // Implementation methods
- //-------------------------------------------------------------------------
- protected Object transform( Object source ) {
- Transformer transformer = getTransformer();
- if ( transformer != null ) {
- return transformer.transform( source );
- }
- return source;
- }
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TransformIterator.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/** A Proxy {@link Iterator Iterator} which uses a {@link Transformer Transformer} instance to
+ * transform the contents of the {@link Iterator Iterator} into some other form
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+
+public class TransformIterator extends ProxyIterator {
+
+ /** Holds value of property transformer. */
+ private Transformer transformer;
+
+
+ public TransformIterator() {
+ }
+
+ public TransformIterator( Iterator iterator ) {
+ super( iterator );
+ }
+
+ public TransformIterator( Iterator iterator, Transformer transformer ) {
+ super( iterator );
+ this.transformer = transformer;
+ }
+
+ // Iterator interface
+ //-------------------------------------------------------------------------
+ public Object next() {
+ return transform( super.next() );
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ /** Getter for property transformer.
+ * @return Value of property transformer.
+ */
+ public Transformer getTransformer() {
+ return transformer;
+ }
+ /** Setter for property transformer.
+ * @param transformer New value of property transformer.
+ */
+ public void setTransformer(Transformer transformer) {
+ this.transformer = transformer;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected Object transform( Object source ) {
+ Transformer transformer = getTransformer();
+ if ( transformer != null ) {
+ return transformer.transform( source );
+ }
+ return source;
+ }
+}
1.3 +73 -73 jakarta-commons/collections/src/java/org/apache/commons/collections/Transformer.java
Index: Transformer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Transformer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Transformer.java 10 Feb 2002 08:07:42 -0000 1.2
+++ Transformer.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,73 +1,73 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Transformer.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.commons.collections;
-
-/** An object capable of transforming an input object into some output object.
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public interface Transformer {
-
- /** Transforms the input object (leaving it unchanged) into some output object.
- * @return the transformation of the input object to the output object
- */
- public Object transform(Object input);
-}
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/Transformer.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.commons.collections;
+
+/** An object capable of transforming an input object into some output object.
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+public interface Transformer {
+
+ /** Transforms the input object (leaving it unchanged) into some output object.
+ * @return the transformation of the input object to the output object
+ */
+ public Object transform(Object input);
+}
1.3 +117 -117 jakarta-commons/collections/src/java/org/apache/commons/collections/TreeBag.java
Index: TreeBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TreeBag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TreeBag.java 10 Feb 2002 08:07:42 -0000 1.2
+++ TreeBag.java 13 Mar 2002 05:40:31 -0000 1.3
@@ -1,117 +1,117 @@
-/*
- * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TreeBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.collections;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-/**
- * An implementation of {@link Bag} that is backed by a {@link
- * TreeMap}. Order will be maintained among the unique representative
- * members.
- *
- * @author Chuck Burdick
- **/
-public class TreeBag extends AbstractBag implements SortedBag, Bag {
- public TreeBag() {
- setMap(new TreeMap());
- }
-
- /**
- * New {@link Bag} that maintains order on its unique
- * representative members according to the given {@link
- * Comparator}.
- **/
- public TreeBag(Comparator c) {
- setMap(new TreeMap(c));
- }
-
- /**
- * New {@link Bag} containing all the members of the given
- * collection.
- * @see #addAll
- **/
- public TreeBag(Collection c) {
- this();
- addAll(c);
- }
-
- public Object first() {
- return ((SortedMap)getMap()).firstKey();
- }
-
- public Object last() {
- return ((SortedMap)getMap()).lastKey();
- }
-
- public Comparator comparator() {
- return ((SortedMap)getMap()).comparator();
- }
-}
-
-
-
-
-
-
+/*
+ * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/TreeBag.java,v 1.3 2002/03/13 05:40:31 mas Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/13 05:40:31 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.collections;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * An implementation of {@link Bag} that is backed by a {@link
+ * TreeMap}. Order will be maintained among the unique representative
+ * members.
+ *
+ * @author Chuck Burdick
+ **/
+public class TreeBag extends AbstractBag implements SortedBag, Bag {
+ public TreeBag() {
+ setMap(new TreeMap());
+ }
+
+ /**
+ * New {@link Bag} that maintains order on its unique
+ * representative members according to the given {@link
+ * Comparator}.
+ **/
+ public TreeBag(Comparator c) {
+ setMap(new TreeMap(c));
+ }
+
+ /**
+ * New {@link Bag} containing all the members of the given
+ * collection.
+ * @see #addAll
+ **/
+ public TreeBag(Collection c) {
+ this();
+ addAll(c);
+ }
+
+ public Object first() {
+ return ((SortedMap)getMap()).firstKey();
+ }
+
+ public Object last() {
+ return ((SortedMap)getMap()).lastKey();
+ }
+
+ public Comparator comparator() {
+ return ((SortedMap)getMap()).comparator();
+ }
+}
+
+
+
+
+
+
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
CVS interface
Posted by Daniel Rall <dl...@finemaltcoding.com>.
[moved to infrastructure@]
"Michael A. Smith" <ma...@apache.org> writes:
> On 13 Mar 2002 mas@apache.org wrote:
> > Log:
>> Removed bad line-endings (multiple ^Ms).
> [snip]
> > Revision Changes Path
>> 1.5 +338 -338 jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java
>
> I find it interesting that cvs says the entire file changes (+338 -338),
> yet if you look at the "colored diff" using viewcvs, it says "No changes"
>
> http://cvs.apache.org/viewcvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java.diff?r1=1.4&r2=1.5&diff_format=h
ViewCVS ignores whitespace by default when generating diffs. See the
view_diff() function in lib/viewcvs.py, and the diff_format and
hr_ignore_white properties in cgi/viewcvs.conf.dist for the details.
You can take off the diff_format=h argument from the query string (or
just change the "h" to a "u") to see the unidiff in ViewCVS.
The change_summary() function of the CVSROOT/log_accum.pl script
(which is fired off by CVSROOT/loginfo) is not setup to ignore
white space. Adding the -b option would turn that on.
open(DIFF, "-|")
|| exec 'cvs', '-Qn', 'diff', '-u',
"-r$prev_rev", "-r$rev", $file;
It would present a more uniform (and arguably therefore more
user-friendly) interface if the default views for the ViewCVS and CVS
commit log diffs were normalized, but perhaps that's over simplifying
matters. Thoughts?
- Dan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections
AbstractBag.java Bag.java Closure.java DefaultMapEntry.java HashBag.java
IteratorEnumeration.java MapUtils.java MultiHas
Posted by "Michael A. Smith" <ma...@apache.org>.
On 13 Mar 2002 mas@apache.org wrote:
> Log:
> Removed bad line-endings (multiple ^Ms).
[snip]
> Revision Changes Path
> 1.5 +338 -338 jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java
I find it interesting that cvs says the entire file changes (+338 -338),
yet if you look at the "colored diff" using viewcvs, it says "No changes"
http://cvs.apache.org/viewcvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractBag.java.diff?r1=1.4&r2=1.5&diff_format=h
regards,
michael
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>