KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > process > extended > ReduceAction


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 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 {
19   public final String JavaDoc symbol;
20   public final Pattern pattern;
21   public final int length;
22
23   public ReduceAction(String JavaDoc symbol, int length)
24   {
25     if (symbol==null)
26       throw new IllegalArgumentException JavaDoc("Symbol is null");
27
28     if ((length!=0) && (length!=2))
29       throw new IllegalArgumentException JavaDoc("Only reduce lengths 0 and 2 are allowed");
30
31     this.symbol = symbol;
32     this.pattern = null;
33     this.length = length;
34   }
35
36   public ReduceAction(Pattern pattern, int length)
37   {
38     if (pattern==null)
39       throw new IllegalArgumentException JavaDoc("Pattern is null");
40
41     if ((length!=0) && (length!=2))
42       throw new IllegalArgumentException JavaDoc("Only reduce lengths 0 and 2 are allowed");
43
44     this.symbol = null;
45     this.pattern = pattern;
46     this.length = length;
47   }
48
49   public boolean equals(Object JavaDoc o)
50   {
51     if (o instanceof ReduceAction)
52     {
53       ReduceAction reduceAction = (ReduceAction)o;
54
55       if (symbol!=null)
56         return (reduceAction.symbol!=null) && (symbol.equals(reduceAction.symbol)) &&
57                (length==reduceAction.length);
58
59       return (pattern==reduceAction.pattern) && (length==reduceAction.length);
60     }
61
62     return false;
63   }
64
65   public String JavaDoc toString()
66   {
67     return "reduce "+((symbol!=null) ? (symbol+"("+length+")") : (pattern+"("+length+")"));
68   }
69 }
70
Popular Tags