Author: scolebourne Date: Sat Oct 28 06:03:11 2006 New Revision: 468690 URL: http://svn.apache.org/viewvc?view=rev&rev=468690 Log: COLLECTIONS-229 - Remove deprecated classes and code
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/CollectionUtils.java jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/CollectionUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/CollectionUtils.java?view=diff&rev=468690&r1=468689&r2=468690 ============================================================================== --- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/CollectionUtils.java (original) +++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/CollectionUtils.java Sat Oct 28 06:03:11 2006 @@ -688,114 +688,7 @@ collection.add(elements[i]); } } - - /** - * Given an Object, and an index, returns the nth value in the - * object. - * <ul> - * <li>If obj is a Map, returns the nth value from the <b>keySet</b> iterator, unless - * the Map contains an Integer key with integer value = idx, in which case the - * corresponding map entry value is returned. If idx exceeds the number of entries in - * the map, an empty Iterator is returned. - * <li>If obj is a List or an array, returns the nth value, throwing IndexOutOfBoundsException, - * ArrayIndexOutOfBoundsException, resp. if the nth value does not exist. - * <li>If obj is an iterator, enumeration or Collection, returns the nth value from the iterator, - * returning an empty Iterator (resp. Enumeration) if the nth value does not exist. - * <li>Returns the original obj if it is null or not a Collection or Iterator. - * </ul> - * - * @param obj the object to get an index of, may be null - * @param idx the index to get - * @throws IndexOutOfBoundsException - * @throws ArrayIndexOutOfBoundsException - * - * @deprecated use [EMAIL PROTECTED] #get(Object, int)} instead. Will be removed in v4.0 - */ - public static Object index(Object obj, int idx) { - return index(obj, new Integer(idx)); - } - - /** - * Given an Object, and a key (index), returns the value associated with - * that key in the Object. The following checks are made: - * <ul> - * <li>If obj is a Map, use the index as a key to get a value. If no match continue. - * <li>Check key is an Integer. If not, return the object passed in. - * <li>If obj is a Map, get the nth value from the <b>keySet</b> iterator. - * If the Map has fewer than n entries, return an empty Iterator. - * <li>If obj is a List or an array, get the nth value, throwing IndexOutOfBoundsException, - * ArrayIndexOutOfBoundsException, resp. if the nth value does not exist. - * <li>If obj is an iterator, enumeration or Collection, get the nth value from the iterator, - * returning an empty Iterator (resp. Enumeration) if the nth value does not exist. - * <li>Return the original obj. - * </ul> - * - * @param obj the object to get an index of - * @param index the index to get - * @return the object at the specified index - * @throws IndexOutOfBoundsException - * @throws ArrayIndexOutOfBoundsException - * - * @deprecated use [EMAIL PROTECTED] #get(Object, int)} instead. Will be removed in v4.0 - */ - public static Object index(Object obj, Object index) { - if(obj instanceof Map) { - Map map = (Map)obj; - if(map.containsKey(index)) { - return map.get(index); - } - } - int idx = -1; - if(index instanceof Integer) { - idx = ((Integer)index).intValue(); - } - if(idx < 0) { - return obj; - } - else if(obj instanceof Map) { - Map map = (Map)obj; - Iterator iterator = map.keySet().iterator(); - return index(iterator, idx); - } - else if(obj instanceof List) { - return ((List)obj).get(idx); - } - else if(obj instanceof Object[]) { - return ((Object[])obj)[idx]; - } - else if(obj instanceof Enumeration) { - Enumeration it = (Enumeration)obj; - while(it.hasMoreElements()) { - idx--; - if(idx == -1) { - return it.nextElement(); - } else { - it.nextElement(); - } - } - } - else if(obj instanceof Iterator) { - return index((Iterator)obj, idx); - } - else if(obj instanceof Collection) { - Iterator iterator = ((Collection)obj).iterator(); - return index(iterator, idx); - } - return obj; - } - private static Object index(Iterator iterator, int idx) { - while(iterator.hasNext()) { - idx--; - if(idx == -1) { - return iterator.next(); - } else { - iterator.next(); - } - } - return iterator; - } - /** * Returns the <code>index</code>-th value in <code>object</code>, throwing * <code>IndexOutOfBoundsException</code> if there is no such element or Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java?view=diff&rev=468690&r1=468689&r2=468690 ============================================================================== --- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java (original) +++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bidimap/AbstractDualBidiMap.java Sat Oct 28 06:03:11 2006 @@ -75,8 +75,6 @@ */ protected AbstractDualBidiMap() { super(); - maps[0] = createMap(); - maps[1] = createMap(); } /** @@ -112,20 +110,6 @@ maps[0] = normalMap; maps[1] = reverseMap; this.inverseBidiMap = inverseBidiMap; - } - - /** - * Creates a new instance of the map used by the subclass to store data. - * <p> - * This design is deeply flawed and has been deprecated. - * It relied on subclass data being used during a superclass constructor. - * - * @return the map to be used for internal storage - * @deprecated For constructors, use the new two map constructor. - * For deserialization, populate the maps array directly in readObject. - */ - protected Map createMap() { - return null; } /** Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java?view=diff&rev=468690&r1=468689&r2=468690 ============================================================================== --- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java (original) +++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java Sat Oct 28 06:03:11 2006 @@ -465,119 +465,7 @@ } } - public void testIndex() { - // normal map behavior when index is an Integer and a key - Map map = new HashMap(); - map.put(new Integer(0), "zero"); - map.put(new Integer(-1), "minusOne"); - Object test = CollectionUtils.index(map, 0); - assertTrue(test.equals("zero")); - test = CollectionUtils.index(map, new Integer(-1)); - assertTrue(test.equals("minusOne")); - - // map, non-integer key that does not exist -- map returned - test = CollectionUtils.index(map, "missing"); - assertTrue(test.equals(map)); - - // map, integer not a key, valid index -- "some" element of keyset returned - test = CollectionUtils.index(map, new Integer(1)); - assertTrue(map.keySet().contains(test)); - - // map, integer not a key, not valid index -- "dead" keyset iterator returned - test = CollectionUtils.index(map, new Integer(4)); - assertTrue((test instanceof Iterator) && !((Iterator) test).hasNext()); - - // sorted map, integer not a key, valid index -- ith key returned - SortedMap map2 = new TreeMap(); - map2.put(new Integer(23), "u"); - map2.put(new Integer(21), "x"); - map2.put(new Integer(17), "v"); - map2.put(new Integer(42), "w"); - Integer val = (Integer) CollectionUtils.index(map2, 0); - assertTrue(val.intValue() == 17); - val = (Integer) CollectionUtils.index(map2, 1); - assertTrue(val.intValue() == 21); - val = (Integer) CollectionUtils.index(map2, 2); - assertTrue(val.intValue() == 23); - val = (Integer) CollectionUtils.index(map2, 3); - assertTrue(val.intValue() == 42); - - // list, entry exists - List list = new ArrayList(); - list.add("zero"); - list.add("one"); - test = CollectionUtils.index(list, 0); - assertTrue(test.equals("zero")); - test = CollectionUtils.index(list, 1); - assertTrue(test.equals("one")); - - // list, non-existent entry -- IndexOutOfBoundsException - try { - test = CollectionUtils.index(list, 2); - fail("Expecting IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // expected - } - - // iterator, entry exists - Iterator iterator = list.iterator(); - test = CollectionUtils.index(iterator,0); - assertTrue(test.equals("zero")); - iterator = list.iterator(); - test = CollectionUtils.index(iterator,1); - assertTrue(test.equals("one")); - - // iterator, non-existent entry -- "dead" iterator returned - test = CollectionUtils.index(iterator,3); - assertTrue(test.equals(iterator) && !iterator.hasNext()); - - // Enumeration, entry exists - Vector vector = new Vector(list); - Enumeration en = vector.elements(); - test = CollectionUtils.index(en,0); - assertTrue(test.equals("zero")); - en = vector.elements(); - test = CollectionUtils.index(en,1); - assertTrue(test.equals("one")); - - // Enumeration, non-existent entry -- "dead" enumerator returned - test = CollectionUtils.index(en,3); - assertTrue(test.equals(en) && !en.hasMoreElements()); - - // Collection, entry exists - Bag bag = new HashBag(); - bag.add("element", 1); - test = CollectionUtils.index(bag, 0); - assertTrue(test.equals("element")); - - // Collection, non-existent entry -- "dead" iterator returned - test = CollectionUtils.index(bag, 2); - assertTrue((test instanceof Iterator) && !((Iterator) test).hasNext()); - - // Object array, entry exists - Object[] objArray = new Object[2]; - objArray[0] = "zero"; - objArray[1] = "one"; - test = CollectionUtils.index(objArray,0); - assertTrue(test.equals("zero")); - test = CollectionUtils.index(objArray,1); - assertTrue(test.equals("one")); - - // Object array, non-existent entry -- ArrayIndexOutOfBoundsException - try { - test = CollectionUtils.index(objArray,2); - fail("Expecting ArrayIndexOutOfBoundsException."); - } catch (ArrayIndexOutOfBoundsException ex) { - // expected - } - - // Non-collection object -- returned unchanged - Object obj = new Object(); - test = CollectionUtils.index(obj, obj); - assertTrue(test.equals(obj)); - } - - public void testGet() { + public void testGet() { { // Unordered map, entries exist Map expected = new HashMap(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]