~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to xsd2cppsax/src/de/netallied/xsd2cppsax/statemachine/StateMachineRootNode.java

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *   Copyright © 2008-2012 NetAllied Systems GmbH, Ravensburg, Germany. 
 
3
 *       
 
4
 *   Licensed under the MIT Open Source License, 
 
5
 *   for details please see LICENSE file or the website
 
6
 *   http://www.opensource.org/licenses/mit-license.php
 
7
*/
 
8
package de.netallied.xsd2cppsax.statemachine;
 
9
 
 
10
import java.util.ArrayList;
 
11
import java.util.List;
 
12
import java.util.SortedMap;
 
13
import java.util.SortedSet;
 
14
import java.util.TreeMap;
 
15
import java.util.TreeSet;
 
16
 
 
17
/**
 
18
 * Specialized node which allows querying of nodes by name.
 
19
 * 
 
20
 */
 
21
public class StateMachineRootNode extends StateMachineNode {
 
22
 
 
23
    /** Contains all nodes of this StateMachine. */
 
24
    private SortedMap<String, List<StateMachineNode>> nodes = new TreeMap<String, List<StateMachineNode>>();
 
25
 
 
26
    /**
 
27
     * Constructor.
 
28
     */
 
29
    public StateMachineRootNode(String name) {
 
30
        super(name);
 
31
        registerNode(name, this);
 
32
    }
 
33
 
 
34
    /**
 
35
     * Finds nodes with given name in this state machine.
 
36
     * 
 
37
     * @param name
 
38
     *            Name to find nodes with.
 
39
     * @return Nodes with given name.
 
40
     */
 
41
    public List<StateMachineNode> findNodes(String name) {
 
42
        return nodes.get(name);
 
43
    }
 
44
 
 
45
    /**
 
46
     * @return All node names in this state machine.
 
47
     */
 
48
    protected SortedSet<String> getNodeNames() {
 
49
        SortedSet<String> sortedNames = new TreeSet<String>();
 
50
        sortedNames.addAll(nodes.keySet());
 
51
        return sortedNames;
 
52
    }
 
53
 
 
54
    /**
 
55
     * Registers a new node. To be called when a node is added to this state
 
56
     * machine.
 
57
     * 
 
58
     * @param name
 
59
     *            Name of the node.
 
60
     * @param node
 
61
     *            The node itself.
 
62
     */
 
63
    protected void registerNode(String name, StateMachineNode node) {
 
64
        List<StateMachineNode> nodesList = nodes.get(name);
 
65
        if (nodesList == null) {
 
66
            nodes.put(name, new ArrayList<StateMachineNode>());
 
67
            nodesList = nodes.get(name);
 
68
        }
 
69
        nodesList.add(node);
 
70
    }
 
71
}