summaryrefslogtreecommitdiff
blob: 6f9083d2f2a1e65e789dbafa6fdd40115291c4b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;

public class Node
{
   private static final Map<String, Node> NODE_FROM_STRING;
   private final Collection<Node> next_nodes;

   private final String name;

   static
   {
      NODE_FROM_STRING = new HashMap<String, Node>();
   }

   private Node (final String name)
   {
      this.name = name;
      next_nodes = new ArrayList<Node>();
   }

   public Collection<Node> next_nodes ()
   {
      return next_nodes;
   }

   @Override
   public String toString ()
   {
      return name;
   }

   public static Node get_node (final String s)
   {
      return NODE_FROM_STRING.get(s);
   }

   public static boolean handle_add_node (final String a)
   {
      if (!NODE_FROM_STRING.containsKey(a))
      {
         NODE_FROM_STRING.put(a, new Node(a));
      }

      return true;
   }

   public static boolean handle_connect_to (final String a, final String b)
   {
      final Node n_a, n_b;

      n_a = NODE_FROM_STRING.get(a);
      n_b = NODE_FROM_STRING.get(b);

      n_a.next_nodes.add(n_b);

      return true;
   }
}