Synthia
Generic and flexible data structure generator
Node.java
Go to the documentation of this file.
1 /*
2  Synthia, a data structure generator
3  Copyright (C) 2019-2021 Laboratoire d'informatique formelle
4  Université du Québec à Chicoutimi, Canada
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 package ca.uqac.lif.synthia.tree;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 /**
25  * Simple implementation of a labeled nodel
26  * @author Sylvain Hallé
27  *
28  * @param <T> The type of the node's label
29  * @ingroup API
30  */
31 public class Node<T>
32 {
33  /**
34  * The node's label.
35  */
36  protected T m_label;
37 
38  /**
39  * The children of this node.
40  */
41  protected List<Node<T>> m_children;
42 
43  /**
44  * Creates a new node with given label.
45  * @param label The label
46  */
47  public Node(T label)
48  {
49  super();
50  m_label = label;
51  m_children = new ArrayList<Node<T>>();
52  }
53 
54  /**
55  * Adds a child to this node.
56  * @param c The child to add
57  * @return This node
58  */
60  {
61  m_children.add(c);
62  return this;
63  }
64 
65  /**
66  * Gets the children of this node.
67  * @return The children
68  */
69  public List<Node<T>> getChildren()
70  {
71  return m_children;
72  }
73 
74  /**
75  * Gets the label associated to this node.
76  * @return The label
77  */
78  public T getLabel()
79  {
80  return m_label;
81  }
82 
83  @Override
84  public String toString()
85  {
86  return m_label.toString();
87  }
88 }
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.Node.Node
Node(T label)
Creates a new node with given label.
Definition: Node.java:47
ca.uqac.lif.synthia.tree.Node.toString
String toString()
Definition: Node.java:84
ca.uqac.lif.synthia.tree.Node.getLabel
T getLabel()
Gets the label associated to this node.
Definition: Node.java:78
ca.uqac.lif.synthia.tree.Node.getChildren
List< Node< T > > getChildren()
Gets the children of this node.
Definition: Node.java:69
ca.uqac.lif.synthia.tree.Node.m_children
List< Node< T > > m_children
The children of this node.
Definition: Node.java:41
ca.uqac.lif.synthia.tree.Node
Simple implementation of a labeled nodel.
Definition: Node.java:31
ca.uqac.lif.synthia.tree.Node.m_label
T m_label
The node's label.
Definition: Node.java:36