KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > model > grammar > Associativity


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.model.grammar;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * This class represents a associativity for a terminal of production.
15  *
16  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
17  * @version CVS $Id: Associativity.java,v 1.3 2003/12/09 19:55:52 benedikta Exp $
18  */

19 public class Associativity implements Serializable JavaDoc
20 {
21   /** Left associativity */
22   public static final Associativity LEFT = new Associativity("left");
23
24   /** Right associativity */
25   public static final Associativity RIGHT = new Associativity("right");
26
27   /** Non associativity */
28   public static final Associativity NONASSOC = new Associativity("nonassoc");
29   private String JavaDoc value = null;
30
31   /**
32    * Create a new associativity object.
33    *
34    * @param value left | right | nonassoc are allowed
35    */

36   public Associativity(String JavaDoc value)
37   {
38     if ((value.equals("left")) || (value.equals("right")) || (value.equals("nonassoc")))
39       this.value = value;
40     else
41       throw new IllegalArgumentException JavaDoc("Type not recognized");
42   }
43
44   /**
45    * Compare with another object.
46    *
47    * @param o Other object
48    *
49    * @return True, if the associative object has the same associativity
50    */

51   public boolean equals(Object JavaDoc o)
52   {
53     if (o==this)
54       return true;
55
56     if (o instanceof Associativity)
57     {
58       Associativity assoc = (Associativity)o;
59
60       return (assoc.value.equals(value));
61     }
62
63     return false;
64   }
65
66   /**
67    * Returns the String representation of this associativity
68    *
69    * @return String representation.
70    */

71   public String JavaDoc toString()
72   {
73     return value;
74   }
75 }
76
Popular Tags