/[svn]/jsampler/trunk/src/org/jsampler/LscpNode.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/LscpNode.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1143 - (show annotations) (download)
Mon Apr 2 21:18:31 2007 UTC (17 years ago) by iliev
File size: 5550 byte(s)
* upgrading to version 0.4a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
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> with
66 * the specified children which are not end of a command.
67 * @param name The name of the node.
68 * @param children The children nodes of this node.
69 */
70 public
71 LscpNode(String name, LscpNode[] children) {
72 this(name, children, false);
73 }
74
75 /**
76 * Creates a new instance of <code>LscpNode</code>.
77 * @param name The name of the node.
78 * @param children The children nodes of this node.
79 * @param endOfACommand Determines whether this node can be an end of a command.
80 */
81 public
82 LscpNode(String name, LscpNode[] children, boolean endOfACommand) {
83 this(name, children, endOfACommand, true);
84 }
85
86 /**
87 * Creates a new instance of <code>LscpNode</code>.
88 * @param name The name of the node.
89 * @param children The children nodes of this node.
90 * @param endOfACommand Determines whether this node can be an end of a command.
91 * @param hasParameters When the node is an end of a command,
92 * determines whether the command has one or more parameters.
93 * @see #isEndOfACommand
94 */
95 public
96 LscpNode(String name, LscpNode[] children, boolean endOfACommand, boolean hasParameters) {
97 this.name = name;
98 this.children = children;
99 this.endOfACommand = endOfACommand;
100 this.hasParameters = hasParameters;
101 }
102
103 /**
104 * Creates a new instance of <code>LscpNode</code> with the specified
105 * child wich is not an end of a command.
106 * @param name The name of the node.
107 * @param child The child node of this node.
108 */
109 public
110 LscpNode(String name, LscpNode child) {
111 this(name, child, false);
112 }
113
114 /**
115 * Creates a new instance of <code>LscpNode</code>.
116 * @param name The name of the node.
117 * @param child The child node of this node.
118 * @param endOfACommand Determines whether this node can be an end of a command.
119 */
120 public
121 LscpNode(String name, LscpNode child, boolean endOfACommand) {
122 this(name, child, endOfACommand, true);
123 }
124
125 /**
126 * Creates a new instance of <code>LscpNode</code>.
127 * @param name The name of the node.
128 * @param child The child node of this node.
129 * @param endOfACommand Determines whether this node can be an end of a command.
130 * @param hasParameters When the node is an end of a command,
131 * determines whether the command has one or more parameters.
132 */
133 public
134 LscpNode(String name, LscpNode child, boolean endOfACommand, boolean hasParameters) {
135 this(name, new LscpNode[1], endOfACommand, hasParameters);
136 children[0] = child;
137 }
138
139 /**
140 * Gets the name of this node.
141 * @return The name of this node.
142 */
143 public String
144 getName() { return name; }
145
146 /**
147 * Gets the children nodes of this node.
148 * @return The children nodes of this node.
149 */
150 public LscpNode[]
151 getChildren() { return children; }
152
153 /**
154 * Sets the children nodes of this node.
155 * @param children The new children nodes of this node.
156 */
157 public void
158 setChildren(LscpNode[] children) { this.children = children; }
159
160 /**
161 * Determines whether this node is last keyword of a command.
162 * Note that this method doesn't determine whether this node is a leaf
163 * (example: <code>RESET</code> and <code>RESET CHANNEL</code> commands).
164 * @return <code>true</code> if this node can be an end of a command,
165 * <code>false</code> otherwise.
166 */
167 public boolean
168 isEndOfACommand() { return endOfACommand || getChildren().length == 0; }
169
170 /**
171 * Determines whether the command represented by this path has one or more parameters.
172 * Do <b>not</b> trust this method when this node is not an end of a command.
173 * @see #isEndOfACommand
174 */
175 public boolean
176 hasParameters() { return hasParameters; }
177 }

  ViewVC Help
Powered by ViewVC