KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > model > symbol > Symbol


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.symbol;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * This class represent a symbol
15  *
16  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
17  * @version CVS $Id: Symbol.java,v 1.5 2003/12/09 19:55:53 benedikta Exp $
18  */

19 public abstract class Symbol implements Serializable JavaDoc
20 {
21   /** Name of the symbol */
22   String JavaDoc name = null;
23
24   /**
25    * Create a symbol.
26    *
27    * @param name Name of symbol.
28    */

29   public Symbol(String JavaDoc name)
30   {
31     if ((name==null) || (name.length()==0))
32       throw new IllegalArgumentException JavaDoc("Name for symbol is invalid");
33
34     this.name = name;
35   }
36
37   /**
38    * Returns the name of this symbol
39    *
40    * @return Name of this symbol.
41    */

42   public String JavaDoc getName()
43   {
44     return name;
45   }
46
47   /**
48    * Returns the string representation of this symbol.
49    *
50    * @return String representation of this symbol.
51    */

52   public String JavaDoc toString()
53   {
54     return name;
55   }
56
57   /**
58    * Returns a hash code value for the symbol.
59    *
60    * @return Hash code value for the symbol.
61    */

62   public int hashCode()
63   {
64     return name.hashCode();
65   }
66
67   /**
68    * Compares the symbol with another symbol.
69    *
70    * @param o Another object
71    *
72    * @return True, if the symbols are equal.
73    */

74   public boolean equals(Object JavaDoc o)
75   {
76     if ((o!=null) && (o instanceof Symbol))
77     {
78       Symbol symbol = (Symbol)o;
79
80       return symbol.name.equals(name);
81     }
82
83     return false;
84   }
85 }
86
Popular Tags