Synthia
Generic and flexible data structure generator
GraphPicker.java
Go to the documentation of this file.
1 package ca.uqac.lif.synthia.tree;
2 
3 import java.util.HashSet;
4 import java.util.Set;
5 
6 import ca.uqac.lif.synthia.Picker;
7 
8 public abstract class GraphPicker<T> implements Picker<Node<T>>
9 {
11 
13 
14  protected Set<Node<T>> m_nodes;
15 
16  public GraphPicker(Picker<Node<T>> node_picker, Picker<Integer> size)
17  {
18  super();
19  m_nodePicker = node_picker;
20  m_size = size;
21  m_nodes = new HashSet<Node<T>>();
22  }
23 
24  /**
25  * Connects two nodes in a graph.
26  * @param n1 The first node
27  * @param n2 The second node
28  */
29  protected void connect(Node<T> n1, Node<T> n2)
30  {
31  n1.addChild(n2);
32  n2.addChild(n1);
33  }
34 
35  /**
36  * Gets the set of nodes in the last graph generated.
37  * @return The set of nodes
38  */
39  public Set<Node<T>> getNodes()
40  {
41  Set<Node<T>> nodes = new HashSet<Node<T>>(m_nodes.size());
42  nodes.addAll(m_nodes);
43  return nodes;
44  }
45 
46  /**
47  * Gets the maximum out degree in a set of nodes in the last graph generated.
48  * @return The maximum out degree
49  */
50  public int getMaxDegree()
51  {
52  int max = 0;
53  for (Node<?> n : m_nodes)
54  {
55  max = Math.max(max, n.getChildren().size());
56  }
57  return max;
58  }
59 
60  @Override
61  public void reset()
62  {
64  m_nodes.clear();
65  }
66 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.tree.GraphPicker.getNodes
Set< Node< T > > getNodes()
Gets the set of nodes in the last graph generated.
Definition: GraphPicker.java:39
ca.uqac.lif.synthia.tree.Node.addChild
Node< T > addChild(Node< T > c)
Adds a child to this node.
Definition: Node.java:59
ca.uqac.lif.synthia.tree.GraphPicker
Definition: GraphPicker.java:8
ca.uqac.lif.synthia.tree.GraphPicker.m_nodePicker
Picker< Node< T > > m_nodePicker
Definition: GraphPicker.java:10
ca.uqac
ca.uqac.lif.synthia.tree.GraphPicker.m_nodes
Set< Node< T > > m_nodes
Definition: GraphPicker.java:14
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif
ca.uqac.lif.synthia.tree.GraphPicker.connect
void connect(Node< T > n1, Node< T > n2)
Connects two nodes in a graph.
Definition: GraphPicker.java:29
ca.uqac.lif.synthia.tree.GraphPicker.reset
void reset()
Puts the picker back into its initial state.
Definition: GraphPicker.java:61
ca
ca.uqac.lif.synthia.tree.GraphPicker.getMaxDegree
int getMaxDegree()
Gets the maximum out degree in a set of nodes in the last graph generated.
Definition: GraphPicker.java:50
ca.uqac.lif.synthia.tree.Node
Simple implementation of a labeled nodel.
Definition: Node.java:31
ca.uqac.lif.synthia.tree.GraphPicker.GraphPicker
GraphPicker(Picker< Node< T >> node_picker, Picker< Integer > size)
Definition: GraphPicker.java:16
ca.uqac.lif.synthia.tree.GraphPicker.m_size
Picker< Integer > m_size
Definition: GraphPicker.java:12
ca.uqac.lif.synthia.Picker.reset
void reset()
Puts the picker back into its initial state.