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> Num
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 Num matches a number from a token assembly.
32: *
33: * @author Steven J. Metsker
34: * @version 1.0
35: */
36: public class Num extends Terminal {
37:
38: /**
39: * Returns true if an assembly's next element is a number.
40: *
41: * @param object an element from an assembly
42: *
43: * @return true, if an assembly's next element is a number as
44: * recognized the tokenizer
45: */
46: protected boolean qualifies(Object o) {
47: Token t = (Token) o;
48:
49: return t.isNumber();
50: }
51:
52: /**
53: * Create a set with one random number (between 0 and
54: * 100).
55: */
56: public List randomExpansion(int maxDepth, int depth) {
57: double d = Math.floor(1000.0 * Math.random()) / 10;
58: List v = new ArrayList();
59:
60: v.add(Double.toString(d));
61: return v;
62: }
63:
64: /**
65: * Returns a textual description of this parser.
66: *
67: * @param vector a list of parsers already printed in
68: * this description
69: *
70: * @return string a textual description of this parser
71: *
72: * @see Parser#toString()
73: */
74: public String unvisitedString(List visited) {
75: return "Num";
76: }
77: }
|