01: /*
02: * Copyright (C) Chaperon. All rights reserved.
03: * -------------------------------------------------------------------------
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08:
09: package net.sourceforge.chaperon.process.extended;
10:
11: import net.sourceforge.chaperon.model.extended.Pattern;
12:
13: /**
14: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
15: * @version CVS $Id: ReduceAction.java,v 1.1 2004/01/04 16:49:12 benedikta Exp $
16: */
17: public class ReduceAction {
18: public final String symbol;
19: public final Pattern pattern;
20: public final int length;
21:
22: public ReduceAction(String symbol, int length) {
23: if (symbol == null)
24: throw new IllegalArgumentException("Symbol is null");
25:
26: if ((length != 0) && (length != 2))
27: throw new IllegalArgumentException(
28: "Only reduce lengths 0 and 2 are allowed");
29:
30: this .symbol = symbol;
31: this .pattern = null;
32: this .length = length;
33: }
34:
35: public ReduceAction(Pattern pattern, int length) {
36: if (pattern == null)
37: throw new IllegalArgumentException("Pattern is null");
38:
39: if ((length != 0) && (length != 2))
40: throw new IllegalArgumentException(
41: "Only reduce lengths 0 and 2 are allowed");
42:
43: this .symbol = null;
44: this .pattern = pattern;
45: this .length = length;
46: }
47:
48: public boolean equals(Object o) {
49: if (o instanceof ReduceAction) {
50: ReduceAction reduceAction = (ReduceAction) o;
51:
52: if (symbol != null)
53: return (reduceAction.symbol != null)
54: && (symbol.equals(reduceAction.symbol))
55: && (length == reduceAction.length);
56:
57: return (pattern == reduceAction.pattern)
58: && (length == reduceAction.length);
59: }
60:
61: return false;
62: }
63:
64: public String toString() {
65: return "reduce "
66: + ((symbol != null) ? (symbol + "(" + length + ")")
67: : (pattern + "(" + length + ")"));
68: }
69: }
|