------------------------------------------------------------ revno: 15559 committer: Morten Olav Hansen <[email protected]> branch nick: dhis2 timestamp: Thu 2014-06-05 11:09:03 +0200 message: revert to using list instead of map for children list modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java 2014-06-04 18:33:34 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java 2014-06-05 09:09:03 +0000 @@ -28,13 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.hisp.dhis.node.exception.DuplicateNodeException; import org.hisp.dhis.node.exception.InvalidTypeException; import java.util.List; -import java.util.Map; /** * @author Morten Olav Hansen <[email protected]> @@ -49,7 +47,7 @@ private String comment; - private Map<String, Node> children = Maps.newHashMap(); + private List<Node> children = Lists.newArrayList(); protected AbstractNode( String name, NodeType nodeType ) { @@ -75,6 +73,30 @@ } @Override + public boolean is( NodeType type ) + { + return type.equals( nodeType ); + } + + @Override + public boolean isSimple() + { + return is( NodeType.SIMPLE ); + } + + @Override + public boolean isComplex() + { + return is( NodeType.COMPLEX ); + } + + @Override + public boolean isCollection() + { + return is( NodeType.COLLECTION ); + } + + @Override public String getNamespace() { return namespace; @@ -104,12 +126,7 @@ return null; } - if ( children.containsKey( child.getName() ) ) - { - throw new DuplicateNodeException(); - } - - children.put( child.getName(), child ); + children.add( child ); return child; } @@ -123,20 +140,9 @@ } @Override - public Node getChild( String name ) - { - if ( children.containsKey( name ) ) - { - return children.get( name ); - } - - return null; - } - - @Override public List<Node> getChildren() { - return Lists.newArrayList( children.values() ); + return ImmutableList.copyOf( children ); } @Override === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java 2014-06-04 18:33:34 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java 2014-06-05 09:09:03 +0000 @@ -51,6 +51,37 @@ NodeType getType(); /** + * @param type Type to check for + * @return True if node is of this type + */ + boolean is( NodeType type ); + + /** + * Helper that checks if node is of simple type, useful to checking if + * you are allowed to add children to this node. + * + * @return true if type is simple + * @see org.hisp.dhis.node.NodeType + */ + boolean isSimple(); + + /** + * Helper that checks if node is of complex type. + * + * @return true if type is complex + * @see org.hisp.dhis.node.NodeType + */ + boolean isComplex(); + + /** + * Helper that checks if node is of collection type. + * + * @return true if type is collection + * @see org.hisp.dhis.node.NodeType + */ + boolean isCollection(); + + /** * Namespace for this node. Not all serializers support this, and its up to the * NodeSerializer implementation to decide what to do with this. * @@ -84,14 +115,6 @@ <T extends Node> void addChildren( Iterable<T> children ); /** - * Returns child with name, or null if it doesn't exist. - * - * @param name Name to search for - * @return A node with that name if it exists, or null - */ - Node getChild( String name ); - - /** * Get all child notes associated with this node. Please note that the returned list is a copy * of the internal list, and changes to the list will not be reflected in the node. *
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

