Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 84251 invoked from network); 6 Feb 2008 21:32:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Feb 2008 21:32:35 -0000 Received: (qmail 60528 invoked by uid 500); 6 Feb 2008 21:32:25 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 60440 invoked by uid 500); 6 Feb 2008 21:32:25 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 60431 invoked by uid 99); 6 Feb 2008 21:32:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 13:32:25 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 21:32:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2D0401A983A; Wed, 6 Feb 2008 13:32:07 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r619161 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/tree/ test/java/org/apache/commons/configuration2/ Date: Wed, 06 Feb 2008 21:32:06 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080206213207.2D0401A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Wed Feb 6 13:32:05 2008 New Revision: 619161 URL: http://svn.apache.org/viewvc?rev=619161&view=rev Log: Removed dependency to commons-collections from HierarchicalConfiguration; Java 1.5-related changes; removed deprectated methods Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ConfigurationNode.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java?rev=619161&r1=619160&r2=619161&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java Wed Feb 6 13:32:05 2008 @@ -20,14 +20,14 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.Stack; -import org.apache.commons.collections.set.ListOrderedSet; -import org.apache.commons.collections.iterators.SingletonIterator; import org.apache.commons.configuration2.event.ConfigurationEvent; import org.apache.commons.configuration2.event.ConfigurationListener; import org.apache.commons.configuration2.tree.ConfigurationNode; @@ -324,7 +324,7 @@ */ public Object getProperty(String key) { - List nodes = fetchNodeList(key); + List nodes = fetchNodeList(key); if (nodes.size() == 0) { @@ -332,10 +332,9 @@ } else { - List list = new ArrayList(); - for (Iterator it = nodes.iterator(); it.hasNext();) + List list = new ArrayList(); + for (ConfigurationNode node : nodes) { - ConfigurationNode node = (ConfigurationNode) it.next(); if (node.getValue() != null) { list.add(node.getValue()); @@ -389,7 +388,7 @@ * @param nodes a collection with the Node objects to be * added */ - public void addNodes(String key, Collection nodes) + public void addNodes(String key, Collection nodes) { if (nodes == null || nodes.isEmpty()) { @@ -398,11 +397,11 @@ fireEvent(EVENT_ADD_NODES, key, nodes, true); ConfigurationNode parent; - List target = fetchNodeList(key); + List target = fetchNodeList(key); if (target.size() == 1) { // existing unique key - parent = (ConfigurationNode) target.get(0); + parent = target.get(0); } else { @@ -427,9 +426,8 @@ } }; - for (Iterator it = nodes.iterator(); it.hasNext();) + for (ConfigurationNode child : nodes) { - ConfigurationNode child = (ConfigurationNode) it.next(); if (child.isAttribute()) { parent.addAttribute(child); @@ -472,9 +470,10 @@ * @param prefix the prefix of the keys for the subset * @return a new configuration object representing the selected subset */ + @SuppressWarnings("serial") public Configuration subset(String prefix) { - Collection nodes = fetchNodeList(prefix); + Collection nodes = fetchNodeList(prefix); if (nodes.isEmpty()) { return new HierarchicalConfiguration(); @@ -494,9 +493,8 @@ // Initialize the new root node Object value = null; int valueCount = 0; - for (Iterator it = nodes.iterator(); it.hasNext();) + for (ConfigurationNode nd : nodes) { - ConfigurationNode nd = (ConfigurationNode) it.next(); if (nd.getValue() != null) { value = nd.getValue(); @@ -504,16 +502,13 @@ } nd.visit(visitor); - for (Iterator it2 = visitor.getClone().getChildren().iterator(); it2 - .hasNext();) + for (ConfigurationNode child : visitor.getClone().getChildren()) { - result.getRootNode().addChild((ConfigurationNode) it2.next()); + result.getRootNode().addChild(child); } - for (Iterator it2 = visitor.getClone().getAttributes().iterator(); it2 - .hasNext();) + for (ConfigurationNode attr : visitor.getClone().getAttributes()) { - result.getRootNode().addAttribute( - (ConfigurationNode) it2.next()); + result.getRootNode().addAttribute(attr); } } @@ -575,22 +570,21 @@ public SubnodeConfiguration configurationAt(String key, boolean supportUpdates) { - List nodes = fetchNodeList(key); + List nodes = fetchNodeList(key); if (nodes.size() != 1) { throw new IllegalArgumentException( "Passed in key must select exactly one node: " + key); } - return supportUpdates ? createSubnodeConfiguration( - (ConfigurationNode) nodes.get(0), key) - : createSubnodeConfiguration((ConfigurationNode) nodes.get(0)); + return supportUpdates ? createSubnodeConfiguration(nodes.get(0), key) + : createSubnodeConfiguration(nodes.get(0)); } /** * Returns a hierarchical subnode configuration for the node specified by * the given key. This is a short form for configurationAt(key, * false). - * + * * @param key the key that selects the sub tree * @return a hierarchical configuration that contains this sub tree * @see SubnodeConfiguration @@ -628,13 +622,13 @@ * configuration represents one of the nodes selected by the passed in key * @since 1.3 */ - public List configurationsAt(String key) + public List configurationsAt(String key) { - List nodes = fetchNodeList(key); - List configs = new ArrayList(nodes.size()); - for (Iterator it = nodes.iterator(); it.hasNext();) + List nodes = fetchNodeList(key); + List configs = new ArrayList(nodes.size()); + for (ConfigurationNode node : nodes) { - configs.add(createSubnodeConfiguration((ConfigurationNode) it.next())); + configs.add(createSubnodeConfiguration(node)); } return configs; } @@ -732,20 +726,20 @@ fireEvent(EVENT_SET_PROPERTY, key, value, true); // Update the existing nodes for this property - Iterator itNodes = fetchNodeList(key).iterator(); - Iterator itValues; + Iterator itNodes = fetchNodeList(key).iterator(); + Iterator itValues; if (!isDelimiterParsingDisabled()) { itValues = PropertyConverter.toIterator(value, getListDelimiter()); } else { - itValues = new SingletonIterator(value); + itValues = Collections.singleton(value).iterator(); } while (itNodes.hasNext() && itValues.hasNext()) { - ((ConfigurationNode) itNodes.next()).setValue(itValues.next()); + itNodes.next().setValue(itValues.next()); } // Add additional nodes if necessary @@ -757,7 +751,7 @@ // Remove remaining nodes while (itNodes.hasNext()) { - clearNode((ConfigurationNode) itNodes.next()); + clearNode(itNodes.next()); } fireEvent(EVENT_SET_PROPERTY, key, value, false); @@ -774,11 +768,11 @@ public void clearTree(String key) { fireEvent(EVENT_CLEAR_TREE, key, null, true); - List nodes = fetchNodeList(key); + List nodes = fetchNodeList(key); - for (Iterator it = nodes.iterator(); it.hasNext();) + for (ConfigurationNode node : nodes) { - removeNode((ConfigurationNode) it.next()); + removeNode(node); } fireEvent(EVENT_CLEAR_TREE, key, nodes, false); } @@ -793,11 +787,11 @@ public void clearProperty(String key) { fireEvent(EVENT_CLEAR_PROPERTY, key, null, true); - List nodes = fetchNodeList(key); + List nodes = fetchNodeList(key); - for (Iterator it = nodes.iterator(); it.hasNext();) + for (ConfigurationNode node : nodes) { - clearNode((ConfigurationNode) it.next()); + clearNode(node); } fireEvent(EVENT_CLEAR_PROPERTY, key, null, false); @@ -810,7 +804,7 @@ * * @return an iterator with the defined keys in this configuration */ - public Iterator getKeys() + public Iterator getKeys() { DefinedKeysVisitor visitor = new DefinedKeysVisitor(); getRootNode().visit(visitor); @@ -826,21 +820,21 @@ * @param prefix the prefix of the keys to start with * @return an iterator with the found keys */ - public Iterator getKeys(String prefix) + @Override + public Iterator getKeys(String prefix) { DefinedKeysVisitor visitor = new DefinedKeysVisitor(prefix); - List nodes = fetchNodeList(prefix); + List nodes = fetchNodeList(prefix); - for (Iterator itNodes = nodes.iterator(); itNodes.hasNext();) + for (ConfigurationNode node : nodes) { - ConfigurationNode node = (ConfigurationNode) itNodes.next(); - for (Iterator it = node.getChildren().iterator(); it.hasNext();) + for (ConfigurationNode child : node.getChildren()) { - ((ConfigurationNode) it.next()).visit(visitor); + child.visit(visitor); } - for (Iterator it = node.getAttributes().iterator(); it.hasNext();) + for (ConfigurationNode attr : node.getAttributes()) { - ((ConfigurationNode) it.next()).visit(visitor); + attr.visit(visitor); } } @@ -920,43 +914,12 @@ * @param key the key * @return a list with all affected nodes (never null ) */ - protected List fetchNodeList(String key) + protected List fetchNodeList(String key) { return getExpressionEngine().query(getRootNode(), key); } /** - * Recursive helper method for fetching a property. This method processes - * all facets of a configuration key, traverses the tree of properties and - * fetches the the nodes of all matching properties. - * - * @param keyPart the configuration key iterator - * @param node the actual node - * @param nodes here the found nodes are stored - * @deprecated Property keys are now evaluated by the expression engine - * associated with the configuration; this method will no longer be called. - * If you want to modify the way properties are looked up, consider - * implementing you own ExpressionEngine implementation. - */ - protected void findPropertyNodes(ConfigurationKey.KeyIterator keyPart, - Node node, Collection nodes) - { - } - - /** - * Checks if the specified node is defined. - * - * @param node the node to be checked - * @return a flag if this node is defined - * @deprecated Use the method {@link #nodeDefined(ConfigurationNode)} - * instead. - */ - protected boolean nodeDefined(Node node) - { - return nodeDefined((ConfigurationNode) node); - } - - /** * Checks if the specified node is defined. * * @param node the node to be checked @@ -1211,13 +1174,13 @@ { this(src.getName(), src.getValue()); setReference(src.getReference()); - for (Iterator it = src.getChildren().iterator(); it.hasNext();) + for (ConfigurationNode child : src.getChildren()) { - addChild((ConfigurationNode) it.next()); + addChild(child); } - for (Iterator it = src.getAttributes().iterator(); it.hasNext();) + for (ConfigurationNode attr : src.getAttributes()) { - addAttribute((ConfigurationNode) it.next()); + addAttribute(attr); } } @@ -1318,12 +1281,12 @@ visitor.visitBeforeChildren(this, key); - for (Iterator it = getChildren().iterator(); it.hasNext() + for (Iterator it = getChildren().iterator(); it.hasNext() && !visitor.terminate();) { ((Node) it.next()).visit(visitor, key); } - for (Iterator it = getAttributes().iterator(); it.hasNext() + for (Iterator it = getAttributes().iterator(); it.hasNext() && !visitor.terminate();) { ((Node) it.next()).visit(visitor, key); @@ -1437,18 +1400,18 @@ class DefinedKeysVisitor extends ConfigurationNodeVisitorAdapter { /** Stores the list to be filled. */ - private Set keyList; + private Set keyList; /** A stack with the keys of the already processed nodes. */ - private Stack parentKeys; + private Stack parentKeys; /** * Default constructor. */ public DefinedKeysVisitor() { - keyList = new ListOrderedSet(); - parentKeys = new Stack(); + keyList = new LinkedHashSet(); + parentKeys = new Stack(); } /** @@ -1468,7 +1431,7 @@ * * @return the list with the defined keys */ - public Set getKeyList() + public Set getKeyList() { return keyList; } @@ -1510,7 +1473,7 @@ static class CloneVisitor extends ConfigurationNodeVisitorAdapter { /** A stack with the actual object to be copied. */ - private Stack copyStack; + private Stack copyStack; /** Stores the result of the clone process. */ private ConfigurationNode result; @@ -1520,7 +1483,7 @@ */ public CloneVisitor() { - copyStack = new Stack(); + copyStack = new Stack(); } /** @@ -1530,7 +1493,7 @@ */ public void visitAfterChildren(ConfigurationNode node) { - ConfigurationNode copy = (ConfigurationNode) copyStack.pop(); + ConfigurationNode copy = copyStack.pop(); if (copyStack.isEmpty()) { result = copy; @@ -1551,11 +1514,11 @@ { if (node.isAttribute()) { - ((ConfigurationNode) copyStack.peek()).addAttribute(copy); + copyStack.peek().addAttribute(copy); } else { - ((ConfigurationNode) copyStack.peek()).addChild(copy); + copyStack.peek().addChild(copy); } } @@ -1599,9 +1562,9 @@ */ public void visitBeforeChildren(Node node, ConfigurationKey key) { - Collection subNodes = new LinkedList(node.getChildren()); + Collection subNodes = new LinkedList(node.getChildren()); subNodes.addAll(node.getAttributes()); - Iterator children = subNodes.iterator(); + Iterator children = subNodes.iterator(); Node sibling1 = null; Node nd = null; @@ -1617,7 +1580,7 @@ if (nd.getReference() == null) { // find all following new nodes - List newNodes = new LinkedList(); + List newNodes = new LinkedList(); newNodes.add(nd); while (children.hasNext()) { @@ -1634,9 +1597,8 @@ // Insert all new nodes Node sibling2 = (nd.getReference() == null) ? null : nd; - for (Iterator it = newNodes.iterator(); it.hasNext();) + for (Node insertNode : newNodes) { - Node insertNode = (Node) it.next(); if (insertNode.getReference() == null) { Object ref = insert(insertNode, node, sibling1, sibling2); Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ConfigurationNode.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ConfigurationNode.java?rev=619161&r1=619160&r2=619161&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ConfigurationNode.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/ConfigurationNode.java Wed Feb 6 13:32:05 2008 @@ -106,7 +106,7 @@ * * @return a list with the children of this node (never null) */ - List getChildren(); + List getChildren(); /** * Returns the number of this node's children. @@ -121,7 +121,7 @@ * @param name the name of the searched children * @return a list with all child nodes with this name (never null) */ - List getChildren(String name); + List getChildren(String name); /** * Returns the number of children with the given name. @@ -180,7 +180,7 @@ * * @return a list with the attributes */ - List getAttributes(); + List getAttributes(); /** * Returns the number of attributes of this node. @@ -196,7 +196,7 @@ * @param name the name of the attribute * @return the attribute nodes with this name (never null) */ - List getAttributes(String name); + List getAttributes(String name); /** * Returns the number of attributes with the given name. Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java?rev=619161&r1=619160&r2=619161&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java Wed Feb 6 13:32:05 2008 @@ -30,6 +30,7 @@ import org.apache.commons.configuration2.HierarchicalConfiguration.Node; import org.apache.commons.configuration2.event.ConfigurationEvent; import org.apache.commons.configuration2.event.ConfigurationListener; +import org.apache.commons.configuration2.tree.ConfigurationNode; import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.apache.commons.configuration2.tree.DefaultExpressionEngine; import org.apache.commons.configuration2.tree.ExpressionEngine; @@ -664,7 +665,7 @@ { HierarchicalConfiguration configDest = new HierarchicalConfiguration(); configDest.addProperty("test", "TEST"); - Collection nodes = config.getRootNode().getChildren(); + Collection nodes = config.getRootNode().getChildren(); assertEquals("Wrong number of children", 1, nodes.size()); configDest.addNodes("newNodes", nodes); for (int i = 0; i < tables.length; i++)