KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java_cup > internal > production_part


1 package com.sun.java_cup.internal;
2
3 /** This class represents one part (either a symbol or an action) of a
4  * production. In this base class it contains only an optional label
5  * string that the user can use to refer to the part within actions.<p>
6  *
7  * This is an abstract class.
8  *
9  * @see com.sun.java_cup.internal.production
10  * @version last updated: 11/25/95
11  * @author Scott Hudson
12  */

13 public abstract class production_part {
14
15   /*-----------------------------------------------------------*/
16   /*--- Constructor(s) ----------------------------------------*/
17   /*-----------------------------------------------------------*/
18        
19   /** Simple constructor. */
20   public production_part(String JavaDoc lab)
21     {
22       _label = lab;
23     }
24
25   /*-----------------------------------------------------------*/
26   /*--- (Access to) Instance Variables ------------------------*/
27   /*-----------------------------------------------------------*/
28        
29   /** Optional label for referring to the part within an action (null for
30    * no label).
31    */

32   protected String JavaDoc _label;
33
34   /** Optional label for referring to the part within an action (null for
35    * no label).
36    */

37   public String JavaDoc label() {return _label;}
38
39   /*-----------------------------------------------------------*/
40   /*--- General Methods ---------------------------------------*/
41   /*-----------------------------------------------------------*/
42        
43   /** Indicate if this is an action (rather than a symbol). Here in the
44    * base class, we don't this know yet, so its an abstract method.
45    */

46   public abstract boolean is_action();
47
48   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
49
50   /** Equality comparison. */
51   public boolean equals(production_part other)
52     {
53       if (other == null) return false;
54
55       /* compare the labels */
56       if (label() != null)
57     return label().equals(other.label());
58       else
59     return other.label() == null;
60     }
61
62   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
63
64   /** Generic equality comparison. */
65   public boolean equals(Object JavaDoc other)
66     {
67       if (!(other instanceof production_part))
68         return false;
69       else
70     return equals((production_part)other);
71     }
72
73   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
74
75   /** Produce a hash code. */
76   public int hashCode()
77     {
78       return label()==null ? 0 : label().hashCode();
79     }
80
81   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
82
83   /** Convert to a string. */
84   public String JavaDoc toString()
85     {
86       if (label() != null)
87     return label() + ":";
88       else
89     return " ";
90     }
91
92   /*-----------------------------------------------------------*/
93
94 }
95
Popular Tags