01: package org.ofbiz.rules.parse.tokens;
02:
03: import java.util.*;
04: import org.ofbiz.rules.parse.*;
05:
06: /**
07: * <p><b>Title:</b> Quoted String
08: * <p><b>Description:</b> None
09: * <p>Copyright (c) 1999 Steven J. Metsker.
10: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
11: *
12: * <p>Permission is hereby granted, free of charge, to any person obtaining a
13: * copy of this software and associated documentation files (the "Software"),
14: * to deal in the Software without restriction, including without limitation
15: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16: * and/or sell copies of the Software, and to permit persons to whom the
17: * Software is furnished to do so, subject to the following conditions:
18: *
19: * <p>The above copyright notice and this permission notice shall be included
20: * in all copies or substantial portions of the Software.
21: *
22: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
27: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
28: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29: *
30: * <br>
31: * A QuotedString matches a quoted string, like "this one"
32: * from a token assembly.
33: *
34: * @author Steven J. Metsker
35: * @version 1.0
36: */
37: public class QuotedString extends Terminal {
38:
39: /**
40: * Returns true if an assembly's next element is a quoted
41: * string.
42: *
43: * @param object an element from a assembly
44: *
45: * @return true, if a assembly's next element is a quoted
46: * string, like "chubby cherubim".
47: */
48: protected boolean qualifies(Object o) {
49: Token t = (Token) o;
50:
51: return t.isQuotedString();
52: }
53:
54: /**
55: * Create a set with one random quoted string (with 2 to
56: * 6 characters).
57: */
58: public List randomExpansion(int maxDepth, int depth) {
59: int n = (int) (5.0 * Math.random());
60:
61: char[] letters = new char[n + 2];
62:
63: letters[0] = '"';
64: letters[n + 1] = '"';
65:
66: for (int i = 0; i < n; i++) {
67: int c = (int) (26.0 * Math.random()) + 'a';
68:
69: letters[i + 1] = (char) c;
70: }
71:
72: List v = new ArrayList();
73:
74: v.add(new String(letters));
75: return v;
76: }
77:
78: /**
79: * Returns a textual description of this parser.
80: *
81: * @param vector a list of parsers already printed in
82: * this description
83: *
84: * @return string a textual description of this parser
85: *
86: * @see Parser#toString()
87: */
88: public String unvisitedString(List visited) {
89: return "QuotedString";
90: }
91: }
|