~dhis2-devs-core/dhis2/trunk

« back to all changes in this revision

Viewing changes to dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java

  • Committer: Morten Olav Hansen
  • Date: 2014-06-05 09:09:03 UTC
  • Revision ID: mortenoh@gmail.com-20140605090903-0drx3ecpe99edjus
revert to using list instead of map for children list

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29
29
 */
30
30
 
 
31
import com.google.common.collect.ImmutableList;
31
32
import com.google.common.collect.Lists;
32
 
import com.google.common.collect.Maps;
33
 
import org.hisp.dhis.node.exception.DuplicateNodeException;
34
33
import org.hisp.dhis.node.exception.InvalidTypeException;
35
34
 
36
35
import java.util.List;
37
 
import java.util.Map;
38
36
 
39
37
/**
40
38
 * @author Morten Olav Hansen <mortenoh@gmail.com>
49
47
 
50
48
    private String comment;
51
49
 
52
 
    private Map<String, Node> children = Maps.newHashMap();
 
50
    private List<Node> children = Lists.newArrayList();
53
51
 
54
52
    protected AbstractNode( String name, NodeType nodeType )
55
53
    {
75
73
    }
76
74
 
77
75
    @Override
 
76
    public boolean is( NodeType type )
 
77
    {
 
78
        return type.equals( nodeType );
 
79
    }
 
80
 
 
81
    @Override
 
82
    public boolean isSimple()
 
83
    {
 
84
        return is( NodeType.SIMPLE );
 
85
    }
 
86
 
 
87
    @Override
 
88
    public boolean isComplex()
 
89
    {
 
90
        return is( NodeType.COMPLEX );
 
91
    }
 
92
 
 
93
    @Override
 
94
    public boolean isCollection()
 
95
    {
 
96
        return is( NodeType.COLLECTION );
 
97
    }
 
98
 
 
99
    @Override
78
100
    public String getNamespace()
79
101
    {
80
102
        return namespace;
104
126
            return null;
105
127
        }
106
128
 
107
 
        if ( children.containsKey( child.getName() ) )
108
 
        {
109
 
            throw new DuplicateNodeException();
110
 
        }
111
 
 
112
 
        children.put( child.getName(), child );
 
129
        children.add( child );
113
130
        return child;
114
131
    }
115
132
 
123
140
    }
124
141
 
125
142
    @Override
126
 
    public Node getChild( String name )
127
 
    {
128
 
        if ( children.containsKey( name ) )
129
 
        {
130
 
            return children.get( name );
131
 
        }
132
 
 
133
 
        return null;
134
 
    }
135
 
 
136
 
    @Override
137
143
    public List<Node> getChildren()
138
144
    {
139
 
        return Lists.newArrayList( children.values() );
 
145
        return ImmutableList.copyOf( children );
140
146
    }
141
147
 
142
148
    @Override