Commit Graph

270 Commits

Author SHA1 Message Date
Michael Smith 91e030ff08 Fixed the following Bag related problems:
- In Bag.java, the statement "If the bag contains less than i occurences,
the item item will be removed from the unique set" implies that if the bag
contains 5 occurences and i is 5, (5 is not less than 5) then the item will
not be removed from the unique set, even though there should be no more
occurances in the bag.

 - In AbstractBag.java, the documentation does not specify exactly what a
subcless needs to do to extend AbstractBag to make a concrete subclass.

 - AbstractBag.add(Object,int) has two calls to getCount(o), when only one
is necessary.  This wastes a few cycles to perform method invocations, a
map lookup, a cast, and a few comparisons.

 - The AbstractBag.equals(Object) method will incorrectly throw a
NullPointerException if a null value is passed.  The Object.equals(Object)
API specifies "For any non-null reference value x, x.equals(null) should
return false".

 - The AbstractBag.equals(Object) method will only work if the object
passed in extends AbstractMap or implements Map.  Neither of these facts
is documented, and neither is correct.  The contract for
Object.equals(Object) states: "for any reference values x and y,
x.equals(y) should return true if and only if y.equals(x) returns true. ".
Returning true when the argument is a Map is incorrect since he reverse
(the map checking to see if its equal to the bag) will most certainly be
false.  The same can be said for AbstractMap.  A subclass of AbstractMap
may add extra data to be stored within the Bag that must also be compared
for them to be equal.  The reverse comparison (specialized subclass equals
basic abstract bap) will fail.  You can read more about this in a three-
year old, but still valid java world article:
http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html

 - if AbstractBag.remove(Object,int) is called passing in 0 as the number
to remove and specifying an object that exists in the bag, true will be
returned from the method. Per the Bag API specification, true should only
return when an object is actually removed.  Since no objects are removed,
false should be returned instead. Additionally, if a negative number is
specified, not only is the object not removed, but object(s) are *added*
(well, in the sense that it is equivalent of calling add(o, -i))

 - the uniqueSet() method returns the set of unique objects, however the
set is modifiable.  If the underlying map implementation has the set
backed by the map (as per the map contract -- so it should), then elements
can be removed from the unique set and have them removed from the
underlying map as well.  This causes consistency problems with the Bag
since _total will then be incorrect.

 - in extractList(), getCount(current) is called each time through the
inner loop, adding lots of extra overhead.  Reversing the loop (starting
at the count and going down to 0) eliminates the excess overhead.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130557 13f79535-47bb-0310-9956-ffa450edef68
2002-02-22 04:39:53 +00:00
Michael Smith 5bf5481408 Added documentation, and updating formatting of some documentation
(i.e. put "code" within <code>...</code>)

Added check for a valid capacity argument passed to constructor.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130556 13f79535-47bb-0310-9956-ffa450edef68
2002-02-22 04:16:19 +00:00
Michael Smith 6bb40f4086 Implement Externalizable in SequencedHashMap
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130555 13f79535-47bb-0310-9956-ffa450edef68
2002-02-22 03:17:40 +00:00
Michael Smith 2af7a322ef Odd how that compiled for me before my commit, but it doesn't
afterwards (for obvious reasons)


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130554 13f79535-47bb-0310-9956-ffa450edef68
2002-02-22 02:37:56 +00:00
Michael Smith ef5aa20db3 There is no backwards compatibility issue since this class is new
since collections 1.0.  Therefore, since the entire Map interface
is implemented, there's no reason to inherit from HashMap.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130553 13f79535-47bb-0310-9956-ffa450edef68
2002-02-22 02:34:59 +00:00
Michael Smith 95ccabfc7c Added a bunch of generic tests to the TestMap.java class. Also added
cooresponding changes to other tests.  These tests expose a few deviations from
the Map contract in BeanMap.  These should either be fixed, or BeanMap should be
documented to describe how it differs from the Map contract.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130552 13f79535-47bb-0310-9956-ffa450edef68
2002-02-22 02:18:50 +00:00
Morgan James Delagrange a87ee3a6f5 release notes portion of the release 2.0 status
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130551 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 22:20:55 +00:00
Morgan James Delagrange fa16599553 more detail for testEntrySetContains()
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130550 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 20:14:37 +00:00
Morgan James Delagrange 8dc203d033 unit test to reproduce a SequencedHashMap 1.3 bug
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130549 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 20:08:15 +00:00
Morgan James Delagrange 8dddc7ac42 unit test to reproduce a SequencedHashMap 1.3 bug
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130548 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 19:57:33 +00:00
Henri Yandell 449753321f Added myself as a committer as I've been committing changes and plan to
continue committing changes unless there's disagreement.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130547 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 17:38:28 +00:00
Michael Smith 90646843f9 Fix a NullPointerException when an object passed to an entrySet method is not mapping found in the map. Exhibited with entrySet().remove(Object) and entrySet().contains(Object)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130546 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 13:46:25 +00:00
Michael Smith 31bc597e42 Added myself as a committer. This also acts as a test to make sure I have things setup properly.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130545 13f79535-47bb-0310-9956-ffa450edef68
2002-02-21 02:01:21 +00:00
Morgan James Delagrange c6be081c1d extended TestDoubleOrderedMap from TestMap
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130544 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 23:48:13 +00:00
Morgan James Delagrange 9708644399 added stub for BeanMap unit tests...definitely needs more tests
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130543 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 23:33:23 +00:00
Morgan James Delagrange 787edf0f34 moved some generic map tests up to TestMap, and implemented a marker
interface to indicate when a TestMap class can test
put(Object,Object) operations


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130542 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 22:38:46 +00:00
Morgan James Delagrange e4a9a024e7 changed superclass from TestHashMap to TestMap, in anticipation
of making SequencedHashMap a subclass of AbstractMap


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130541 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 22:17:18 +00:00
Morgan James Delagrange ce5559b6d4 added methods for testing serialization and a simple sanity check for
all serializable collections


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130540 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 21:50:16 +00:00
Morgan James Delagrange cc0da9db95 inherit all tests from SequencedHashMap
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130539 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 20:51:38 +00:00
Morgan James Delagrange 7b2312f796 made testing of SequencedHashMap subclasses easier
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130538 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 20:50:23 +00:00
Morgan James Delagrange cd6254ae22 fixed line feed problem over whole file
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130537 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 18:30:36 +00:00
Morgan James Delagrange ca6c97a99a removed unnecessary else block and fixed indenting
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130536 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 18:05:07 +00:00
Morgan James Delagrange 89417ef747 LRUMap reimplemented, based on SequencedHashMap
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130535 13f79535-47bb-0310-9956-ffa450edef68
2002-02-20 18:01:34 +00:00
Morgan James Delagrange b5b971bf9f added stub for confirming true LRU algorithm, and added test
for setMaximumSize (fails)


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130534 13f79535-47bb-0310-9956-ffa450edef68
2002-02-19 21:28:53 +00:00
Morgan James Delagrange 37bb856fff TestHashMap is no longer the superclass, in anticipation of reimplementing
LRUMap as a subclass of SequencedHashMap


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130533 13f79535-47bb-0310-9956-ffa450edef68
2002-02-19 21:17:41 +00:00
Morgan James Delagrange 3b9b229b36 complete re-implementation of SequencedHashMap submitted by
Michael Smith


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130532 13f79535-47bb-0310-9956-ffa450edef68
2002-02-18 20:34:57 +00:00
Morgan James Delagrange b688f162ac added tests to make sure "youngest" promotion recognizes null values
in all cases


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130531 13f79535-47bb-0310-9956-ffa450edef68
2002-02-15 21:08:38 +00:00
Morgan James Delagrange 1fe14f43e1 added test for inserting null values to the map
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130530 13f79535-47bb-0310-9956-ffa450edef68
2002-02-15 20:50:37 +00:00
Morgan James Delagrange 6c42be5cd0 Undo. Put is an optional operation for a Map.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130529 13f79535-47bb-0310-9956-ffa450edef68
2002-02-15 20:48:18 +00:00
Morgan James Delagrange f05739cf89 makes sure that a Map inserts null values correctly
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130528 13f79535-47bb-0310-9956-ffa450edef68
2002-02-15 20:40:14 +00:00
Morgan James Delagrange 4cf4e68603 Fixed javadocs
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130526 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 22:44:01 +00:00
Morgan James Delagrange d27ed7fcc3 added unit test to insure backward compatibility of externalized
LRUMaps


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130525 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 22:42:45 +00:00
Morgan James Delagrange ce972ca58f Externalized version of an LRUMap for Collections 1.x (created by
CVS version 1.3 of the LRUMap class)


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130524 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 22:41:54 +00:00
Morgan James Delagrange c9cc92c63e LRUMap does not support concurrent access to any of its methods
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130523 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 21:24:32 +00:00
Morgan James Delagrange f22d9bce8c added contract to LRUMap - subclasses can override removeLRU()
and remove(Object) to manipulate objects on their way out of the cache


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130522 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 20:58:48 +00:00
Morgan James Delagrange 766b98572a unit tests for subclass behaviour
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130521 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 20:57:59 +00:00
Morgan James Delagrange b0a305ab05 added fully qualified package names for imports
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130520 13f79535-47bb-0310-9956-ffa450edef68
2002-02-14 20:21:49 +00:00
Morgan James Delagrange 832be0e38f added test to make sure that putAll(Map) operation obeys the maximum
Map size


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130519 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 23:55:41 +00:00
Morgan James Delagrange 02bc992242 fixed bubble sort, so that the number of elements in the bubble sort
will always equal the size of the LRUMap


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130518 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 23:07:31 +00:00
Morgan James Delagrange 5dcc5d8747 added test for map capacity, which fails right now
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130517 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 22:32:37 +00:00
Morgan James Delagrange 4733a995ff unit test for reassigning keys
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130516 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 21:49:38 +00:00
Morgan James Delagrange c5c64c02d3 fixed IndexOutOfBoundsException
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130515 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 21:03:20 +00:00
Morgan James Delagrange e71840e0bb added unit test for LRUMap.removeLRU(), which needs fixing
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130514 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 20:59:12 +00:00
Morgan James Delagrange 97f0e7ff26 adding myself as a contributor
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130513 13f79535-47bb-0310-9956-ffa450edef68
2002-02-13 20:21:05 +00:00
James Strachan 328f30989e Patched the LRUMap so that remove() does indeed remove items from the bubble list
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130512 13f79535-47bb-0310-9956-ffa450edef68
2002-02-10 12:56:39 +00:00
James Strachan 25c1cb6b4a Updated all the licences to the full long form and ensured that the copyright notice extends to 2002. Also applied Michael Smith's patch for FilterIterator, Closure, DefaultMapEntry and LRUMap
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130511 13f79535-47bb-0310-9956-ffa450edef68
2002-02-10 08:07:42 +00:00
James Strachan 4b266ff8bc Applied patch submitted by Michael Smith that clarifies the description of the FilterIterator
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130510 13f79535-47bb-0310-9956-ffa450edef68
2002-02-01 16:27:40 +00:00
Craig R. McClanahan 6a5c4a72c6 Committed the DoubleOrderedMap class and associated unit tests (gotta love
it when the unit test source is 50% longer than the class being tested :-).
The only change I made was to use the long-form version of the Apache
license -- according to the Apache board, that is the only acceptable
approach at the moment.  Any remaining classes in commons-collections (or
elsewhere) using the short form license should be updated.

Submitted by:	Marc Johnson <marc_johnson27591@hotmail.com>


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130509 13f79535-47bb-0310-9956-ffa450edef68
2002-01-20 04:36:08 +00:00
Henri Yandell 3d6c8c5fab An empty iterator. It is immutable and always the same object instance.
Submitted by:	Christopher Elkins <chrise@scardini.com>


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130508 13f79535-47bb-0310-9956-ffa450edef68
2001-11-26 17:15:33 +00:00
James Strachan 51a5b46632 Applied patch submitted by Richard Wan that containsKey() took a String by mistake
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130507 13f79535-47bb-0310-9956-ffa450edef68
2001-11-02 14:44:35 +00:00