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.model.symbol;
10:
11: import java.io.Serializable;
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 {
20: /** Name of the symbol */
21: String name = null;
22:
23: /**
24: * Create a symbol.
25: *
26: * @param name Name of symbol.
27: */
28: public Symbol(String name) {
29: if ((name == null) || (name.length() == 0))
30: throw new IllegalArgumentException(
31: "Name for symbol is invalid");
32:
33: this .name = name;
34: }
35:
36: /**
37: * Returns the name of this symbol
38: *
39: * @return Name of this symbol.
40: */
41: public String getName() {
42: return name;
43: }
44:
45: /**
46: * Returns the string representation of this symbol.
47: *
48: * @return String representation of this symbol.
49: */
50: public String toString() {
51: return name;
52: }
53:
54: /**
55: * Returns a hash code value for the symbol.
56: *
57: * @return Hash code value for the symbol.
58: */
59: public int hashCode() {
60: return name.hashCode();
61: }
62:
63: /**
64: * Compares the symbol with another symbol.
65: *
66: * @param o Another object
67: *
68: * @return True, if the symbols are equal.
69: */
70: public boolean equals(Object o) {
71: if ((o != null) && (o instanceof Symbol)) {
72: Symbol symbol = (Symbol) o;
73:
74: return symbol.name.equals(name);
75: }
76:
77: return false;
78: }
79: }
|