01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * Portions Copyrighted 2007 Sun Microsystems, Inc.
16: */
17: package org.netbeans.modules.languages;
18:
19: import java.util.List;
20:
21: /**
22: *
23: * @author hanz
24: */
25: public class Rule {
26:
27: private String nt;
28: private List right;
29:
30: private Rule() {
31: }
32:
33: public static Rule create(String nt, List right) {
34: Rule r = new Rule();
35: r.nt = nt;
36: r.right = right;
37: return r;
38: }
39:
40: public String getNT() {
41: return nt;
42: }
43:
44: public List getRight() {
45: return right;
46: }
47:
48: private String toString = null;
49:
50: @Override
51: public String toString() {
52: if (toString == null) {
53: StringBuilder sb = new StringBuilder();
54: sb.append("Rule ").append(nt).append(" = ");
55: int i = 0, k = right.size();
56: if (i < k)
57: sb.append(right.get(i++));
58: while (i < k)
59: sb.append(' ').append(right.get(i++));
60: toString = sb.toString();
61: }
62: return toString;
63: }
64: }
|