Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 28457 invoked from network); 13 Nov 2005 17:00:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Nov 2005 17:00:31 -0000 Received: (qmail 33868 invoked by uid 500); 13 Nov 2005 17:00:20 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 33843 invoked by uid 500); 13 Nov 2005 17:00:19 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 33832 invoked by uid 500); 13 Nov 2005 17:00:19 -0000 Received: (qmail 33829 invoked by uid 99); 13 Nov 2005 17:00:19 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 13 Nov 2005 09:00:19 -0800 Received: (qmail 27707 invoked by uid 65534); 13 Nov 2005 16:59:58 -0000 Message-ID: <20051113165958.27702.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r333060 - in /jakarta/commons/proper/collections/trunk: RELEASE-NOTES.html src/java/org/apache/commons/collections/ExtendedProperties.java src/test/org/apache/commons/collections/TestExtendedProperties.java Date: Sun, 13 Nov 2005 16:59:57 -0000 To: commons-cvs@jakarta.apache.org From: scolebourne@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: scolebourne Date: Sun Nov 13 08:59:51 2005 New Revision: 333060 URL: http://svn.apache.org/viewcvs?rev=333060&view=rev Log: Make ExtendedProperties support List rather than just Vector bug 36812, from Henning P. Schmiedehausen Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/ExtendedProperties.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?rev=333060&r1=333059&r2=333060&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original) +++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Sun Nov 13 08:59:51 2005 @@ -67,6 +67,8 @@
  • CollectionUtils/MapUtils.isEmpty/isNotEmpty - Null-safe checks of collection emptyness [35890]
  • CollectionUtils.sizeIsEmpty - Checks if a collection, array, map, iterator or enumeration is empty
  • CollectionUtils/ListUtils - retainAll/removeAll that don't change original colllection
  • +
  • ExtendedProperties - Accepts List elements (does not enforce Vector) as values [36812]
  • +
  • ExtendedProperties - new Methods getList(String key) and getList(String key, List defaults) [36812]
  • ExtendedProperties - No longer uses an exception in normal processing [30497]
  • BlockingBuffer - now includes stack trace if InterupttedException occurs [33700]
  • BlockingBuffer - new methods that allow get and remove with a timeout [27691]
  • Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/ExtendedProperties.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/ExtendedProperties.java?rev=333060&r1=333059&r2=333060&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/ExtendedProperties.java (original) +++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/ExtendedProperties.java Sun Nov 13 08:59:51 2005 @@ -138,6 +138,7 @@ * @author Mohan Kishore * @author Stephen Colebourne * @author Shinobu Kawai + * @author Henning P. Schmiedehausen */ public class ExtendedProperties extends Hashtable { @@ -691,14 +692,14 @@ if (current instanceof String) { // one object already in map - convert it to a vector - Vector v = new Vector(2); - v.addElement(current); - v.addElement(value); - put(key, v); + List values = new Vector(2); + values.add(current); + values.add(value); + put(key, values); - } else if (current instanceof Vector) { - // already a vector - just add the new token - ((Vector) current).addElement(value); + } else if (current instanceof List) { + // already a list - just add the new token + ((List) current).add(value); } else { // brand new key - store in keysAsListed to retain order @@ -752,11 +753,10 @@ currentOutput.append(escape((String) value)); theWrtr.println(currentOutput.toString()); - } else if (value instanceof Vector) { - Vector values = (Vector) value; - Enumeration valuesEnum = values.elements(); - while (valuesEnum.hasMoreElements()) { - String currentElement = (String) valuesEnum.nextElement(); + } else if (value instanceof List) { + List values = (List) value; + for (Iterator it = values.iterator(); it.hasNext(); ) { + String currentElement = (String) it.next(); StringBuffer currentOutput = new StringBuffer(); currentOutput.append(key); currentOutput.append("="); @@ -931,8 +931,8 @@ } else { return interpolate(defaultValue); } - } else if (value instanceof Vector) { - return interpolate((String) ((Vector) value).get(0)); + } else if (value instanceof List) { + return interpolate((String) ((List) value).get(0)); } else { throw new ClassCastException('\'' + key + "' doesn't map to a String object"); } @@ -945,7 +945,7 @@ * @param key The configuration key. * @return The associated properties if key is found. * @throws ClassCastException is thrown if the key maps to an - * object that is not a String/Vector. + * object that is not a String/List. * @throws IllegalArgumentException if one of the tokens is * malformed (does not contain an equals sign). */ @@ -960,7 +960,7 @@ * @param key The configuration key. * @return The associated properties if key is found. * @throws ClassCastException is thrown if the key maps to an - * object that is not a String/Vector. + * object that is not a String/List. * @throws IllegalArgumentException if one of the tokens is * malformed (does not contain an equals sign). */ @@ -993,19 +993,18 @@ * @param key The configuration key. * @return The associated string array if key is found. * @throws ClassCastException is thrown if the key maps to an - * object that is not a String/Vector. + * object that is not a String/List. */ public String[] getStringArray(String key) { Object value = get(key); - // What's your vector, Victor? - Vector vector; + List values; if (value instanceof String) { - vector = new Vector(1); - vector.addElement(value); + values = new Vector(1); + values.add(value); - } else if (value instanceof Vector) { - vector = (Vector) value; + } else if (value instanceof List) { + values = (List) value; } else if (value == null) { if (defaults != null) { @@ -1014,12 +1013,12 @@ return new String[0]; } } else { - throw new ClassCastException('\'' + key + "' doesn't map to a String/Vector object"); + throw new ClassCastException('\'' + key + "' doesn't map to a String/List object"); } - String[] tokens = new String[vector.size()]; + String[] tokens = new String[values.size()]; for (int i = 0; i < tokens.length; i++) { - tokens[i] = (String) vector.elementAt(i); + tokens[i] = (String) values.get(i); } return tokens; @@ -1039,8 +1038,10 @@ } /** - * Get a Vector of strings associated with the given configuration - * key. + * Get a Vector of strings associated with the given configuration key. + *

    + * The list is a copy of the internal data of this object, and as + * such you may alter it freely. * * @param key The configuration key. * @param defaultValue The default value. @@ -1051,14 +1052,14 @@ public Vector getVector(String key, Vector defaultValue) { Object value = get(key); - if (value instanceof Vector) { - return (Vector) value; + if (value instanceof List) { + return new Vector((List) value); } else if (value instanceof String) { - Vector v = new Vector(1); - v.addElement(value); - put(key, v); - return v; + Vector values = new Vector(1); + values.add(value); + put(key, values); + return values; } else if (value == null) { if (defaults != null) { @@ -1068,6 +1069,56 @@ } } else { throw new ClassCastException('\'' + key + "' doesn't map to a Vector object"); + } + } + + /** + * Get a List of strings associated with the given configuration key. + *

    + * The list is a copy of the internal data of this object, and as + * such you may alter it freely. + * + * @param key The configuration key. + * @return The associated List object. + * @throws ClassCastException is thrown if the key maps to an + * object that is not a List. + */ + public List getList(String key) { + return getList(key, null); + } + + /** + * Get a List of strings associated with the given configuration key. + *

    + * The list is a copy of the internal data of this object, and as + * such you may alter it freely. + * + * @param key The configuration key. + * @param defaultValue The default value. + * @return The associated List. + * @throws ClassCastException is thrown if the key maps to an + * object that is not a List. + */ + public List getList(String key, List defaultValue) { + Object value = get(key); + + if (value instanceof List) { + return new ArrayList((List) value); + + } else if (value instanceof String) { + List values = new ArrayList(1); + values.add(value); + put(key, values); + return values; + + } else if (value == null) { + if (defaults != null) { + return defaults.getList(key, defaultValue); + } else { + return ((defaultValue == null) ? new ArrayList() : defaultValue); + } + } else { + throw new ClassCastException('\'' + key + "' doesn't map to a List object"); } } Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java?rev=333060&r1=333059&r2=333060&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestExtendedProperties.java Sun Nov 13 08:59:51 2005 @@ -33,6 +33,7 @@ * @author Mohan Kishore * @author Stephen Colebourne * @author Shinobu Kawai + * @author Henning P. Schmiedehausen */ public class TestExtendedProperties extends TestCase { @@ -65,14 +66,15 @@ assertEquals("This returns '1'", eprop.getString("number"), "1"); /* - * now add another and get a Vector + * now add another and get a Vector/list */ eprop.addProperty("number", "2"); assertTrue("This returns array", (eprop.getVector("number") instanceof java.util.Vector)); + assertTrue("This returns array", (eprop.getList("number") instanceof java.util.List)); /* * now test dan's new fix where we get the first scalar - * when we access a vector valued + * when we access a vector/list valued * property */ assertTrue("This returns scalar", (eprop.getString("number") instanceof String)); @@ -83,6 +85,7 @@ String prop = "hey, that's a test"; eprop.setProperty("prop.string", prop); assertTrue("This returns vector", (eprop.getVector("prop.string") instanceof java.util.Vector)); + assertTrue("This returns list", (eprop.getList("prop.string") instanceof java.util.List)); String prop2 = "hey\\, that's a test"; eprop.remove("prop.string"); @@ -99,6 +102,7 @@ assertTrue("Returns the full string", subEprop.getString("string").equals(prop)); assertTrue("This returns string for subset", (subEprop.getString("string") instanceof java.lang.String)); assertTrue("This returns array for subset", (subEprop.getVector("string") instanceof java.util.Vector)); + assertTrue("This returns array for subset", (subEprop.getList("string") instanceof java.util.List)); } @@ -133,6 +137,13 @@ "Hello", ep1.getVector("three").get(0)); assertEquals("Commas not interpreted properly", "World", ep1.getVector("three").get(1)); + + assertEquals("Commas not interpreted properly", + 2, ep1.getList("three").size()); + assertEquals("Commas not interpreted properly", + "Hello", ep1.getList("three").get(0)); + assertEquals("Commas not interpreted properly", + "World", ep1.getList("three").get(1)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ep1.save(baos, null); @@ -186,10 +197,16 @@ ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); + assertEquals(3, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); + + assertEquals(3, ep1.getList("one").size()); + assertEquals("a", ep1.getList("one").get(0)); + assertEquals("b", ep1.getList("one").get(1)); + assertEquals("c", ep1.getList("one").get(2)); } public void testMultipleSameKey2() throws Exception { @@ -205,11 +222,18 @@ ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); + assertEquals(4, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals("d", ep1.getVector("one").get(3)); + + assertEquals(4, ep1.getList("one").size()); + assertEquals("a", ep1.getList("one").get(0)); + assertEquals("b", ep1.getList("one").get(1)); + assertEquals("c", ep1.getList("one").get(2)); + assertEquals("d", ep1.getList("one").get(3)); } public void testMultipleSameKey3() throws Exception { @@ -225,10 +249,16 @@ ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); + assertEquals(3, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); + + assertEquals(3, ep1.getList("one").size()); + assertEquals("a", ep1.getList("one").get(0)); + assertEquals("b", ep1.getList("one").get(1)); + assertEquals("c", ep1.getList("one").get(2)); } public void testMultipleSameKeyByCode() throws Exception { @@ -236,22 +266,38 @@ ep1.addProperty("one", "a"); assertEquals(1, ep1.size()); + assertEquals(1, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); + + assertEquals(1, ep1.getList("one").size()); + assertEquals("a", ep1.getList("one").get(0)); ep1.addProperty("one", Boolean.TRUE); assertEquals(1, ep1.size()); + assertEquals(2, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals(Boolean.TRUE, ep1.getVector("one").get(1)); + + assertEquals(2, ep1.getList("one").size()); + assertEquals("a", ep1.getList("one").get(0)); + assertEquals(Boolean.TRUE, ep1.getList("one").get(1)); ep1.addProperty("one", "c,d"); assertEquals(1, ep1.size()); + assertEquals(4, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals(Boolean.TRUE, ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals("d", ep1.getVector("one").get(3)); + + assertEquals(4, ep1.getList("one").size()); + assertEquals("a", ep1.getList("one").get(0)); + assertEquals(Boolean.TRUE, ep1.getList("one").get(1)); + assertEquals("c", ep1.getList("one").get(2)); + assertEquals("d", ep1.getList("one").get(3)); } public void testInheritDefaultProperties() { --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org