1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005, 2006 Grigor Kirilov Iliev |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler; |
24 |
|
25 |
/** |
26 |
* |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class LscpNode { |
30 |
private String name; |
31 |
private LscpNode[] children; |
32 |
private boolean endOfACommand; |
33 |
private boolean hasParameters; |
34 |
|
35 |
/** |
36 |
* Creates a new instance of <code>LscpNode</code>. |
37 |
* @param name The name of the node. |
38 |
*/ |
39 |
public |
40 |
LscpNode(String name) { this(name, new LscpNode[0]); } |
41 |
|
42 |
/** |
43 |
* Creates a new instance of <code>LscpNode</code>. |
44 |
* @param name The name of the node. |
45 |
* @param endOfACommand Determines whether this node can be an end of a command. |
46 |
*/ |
47 |
public |
48 |
LscpNode(String name, boolean endOfACommand) { |
49 |
this(name, new LscpNode[0], endOfACommand); |
50 |
} |
51 |
|
52 |
/** |
53 |
* Creates a new instance of <code>LscpNode</code>. |
54 |
* @param name The name of the node. |
55 |
* @param endOfACommand Determines whether this node can be an end of a command. |
56 |
* @param hasParameters When the node is an end of a command, |
57 |
* determines whether the command has one or more parameters. |
58 |
*/ |
59 |
public |
60 |
LscpNode(String name, boolean endOfACommand, boolean hasParameters) { |
61 |
this(name, new LscpNode[0], endOfACommand, hasParameters); |
62 |
} |
63 |
|
64 |
/** |
65 |
* Creates a new instance of <code>LscpNode</code>. |
66 |
* @param name The name of the node. |
67 |
* @param children The children nodes of this node. |
68 |
*/ |
69 |
public |
70 |
LscpNode(String name, LscpNode[] children) { |
71 |
this(name, children, false); |
72 |
} |
73 |
|
74 |
/** |
75 |
* Creates a new instance of <code>LscpNode</code>. |
76 |
* @param name The name of the node. |
77 |
* @param children The children nodes of this node. |
78 |
* @param endOfACommand Determines whether this node can be an end of a command. |
79 |
*/ |
80 |
public |
81 |
LscpNode(String name, LscpNode[] children, boolean endOfACommand) { |
82 |
this(name, children, endOfACommand, true); |
83 |
} |
84 |
|
85 |
/** |
86 |
* Creates a new instance of <code>LscpNode</code>. |
87 |
* @param name The name of the node. |
88 |
* @param children The children nodes of this node. |
89 |
* @param endOfACommand Determines whether this node can be an end of a command. |
90 |
* @param hasParameters When the node is an end of a command, |
91 |
* determines whether the command has one or more parameters. |
92 |
*/ |
93 |
public |
94 |
LscpNode(String name, LscpNode[] children, boolean endOfACommand, boolean hasParameters) { |
95 |
this.name = name; |
96 |
this.children = children; |
97 |
this.endOfACommand = endOfACommand; |
98 |
this.hasParameters = hasParameters; |
99 |
} |
100 |
|
101 |
/** |
102 |
* Creates a new instance of <code>LscpNode</code>. |
103 |
* @param name The name of the node. |
104 |
* @param child The child node of this node. |
105 |
*/ |
106 |
public |
107 |
LscpNode(String name, LscpNode child) { |
108 |
this(name, child, false); |
109 |
} |
110 |
|
111 |
/** |
112 |
* Creates a new instance of <code>LscpNode</code>. |
113 |
* @param name The name of the node. |
114 |
* @param child The child node of this node. |
115 |
* @param endOfACommand Determines whether this node can be an end of a command. |
116 |
*/ |
117 |
public |
118 |
LscpNode(String name, LscpNode child, boolean endOfACommand) { |
119 |
this(name, child, endOfACommand, true); |
120 |
} |
121 |
|
122 |
/** |
123 |
* Creates a new instance of <code>LscpNode</code>. |
124 |
* @param name The name of the node. |
125 |
* @param child The child node of this node. |
126 |
* @param endOfACommand Determines whether this node can be an end of a command. |
127 |
* @param hasParameters When the node is an end of a command, |
128 |
* determines whether the command has one or more parameters. |
129 |
*/ |
130 |
public |
131 |
LscpNode(String name, LscpNode child, boolean endOfACommand, boolean hasParameters) { |
132 |
this(name, new LscpNode[1], endOfACommand, hasParameters); |
133 |
children[0] = child; |
134 |
} |
135 |
|
136 |
/** |
137 |
* Gets the name of this node. |
138 |
* @return The name of this node. |
139 |
*/ |
140 |
public String |
141 |
getName() { return name; } |
142 |
|
143 |
/** |
144 |
* Gets the children nodes of this node. |
145 |
* @return The children nodes of this node. |
146 |
*/ |
147 |
public LscpNode[] |
148 |
getChildren() { return children; } |
149 |
|
150 |
/** |
151 |
* Sets the children nodes of this node. |
152 |
* @param children The new children nodes of this node. |
153 |
*/ |
154 |
public void |
155 |
setChildren(LscpNode[] children) { this.children = children; } |
156 |
|
157 |
/** |
158 |
* Determines whether this node is last keyword of a command. |
159 |
* Note that this method doesn't determine whether this node is a leaf |
160 |
* (example: <code>RESET</code> and <code>RESET CHANNEL</code> commands). |
161 |
* @return <code>true</code> if this node can be an end of a command, |
162 |
* <code>false</code> otherwise. |
163 |
*/ |
164 |
public boolean |
165 |
isEndOfACommand() { return endOfACommand || getChildren().length == 0; } |
166 |
|
167 |
/** |
168 |
* Determines whether the command represented by this path has one or more parameters. |
169 |
* Do <b>not</b> trust this method when this node is not an end of a command. |
170 |
* @see #isEndOfACommand |
171 |
*/ |
172 |
public boolean |
173 |
hasParameters() { return hasParameters; } |
174 |
} |