1 /*
2 wsmo4j - a WSMO API and Reference Implementation
3 Copyright (c) 2004-2005, OntoText Lab. / SIRMA
4 This library is free software; you can redistribute it and/or modify it under
5 the terms of the GNU Lesser General Public License as published by the Free
6 Software Foundation; either version 2.1 of the License, or (at your option)
7 any later version.
8 This library is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12 You should have received a copy of the GNU Lesser General Public License along
13 with this library; if not, write to the Free Software Foundation, Inc.,
14 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16
17 package org.deri.wsmo4j.logicalexpression.terms;
18
19
20 /**
21 * <p>Title: WSMO4J</p>
22 * <p>Description: WSMO API and a Reference Implementation</p>
23 * <p>Copyright: Copyright (c) 2004-2005</p>
24 * <p>Company: OntoText Lab. / SIRMA </p>
25 * @author not attributable
26 * @version 1.0
27 *
28 */
29
30 import java.io.*;
31
32 import org.omwg.logicalexpression.terms.*;
33
34
35 /**
36 * An interface representing an anonymous numbered identifier
37 *
38 * @author not attributable
39 * @version $Revision: 1030 $ $Date: 2005-09-21 11:15:39 +0300 (Wed, 21 Sep 2005) $
40 * @since 0.4.0
41 */
42 public class NumberedAnonymousIDImpl
43 implements Serializable, NumberedAnonymousID {
44
45 private static final long serialVersionUID = 3118168739751464544L;
46
47 private byte id;
48
49 public NumberedAnonymousIDImpl(byte id) {
50 this.id = id;
51 }
52
53 public String toString() {
54 return new StringBuffer("_#").append(this.id).toString();
55 }
56
57 public byte getNumber() {
58 return this.id;
59 }
60
61 public void accept(Visitor v) {
62 v.visitNumberedID(this);
63 }
64
65 /**
66 * <p>
67 * The <code>equals</code> method implements an equivalence relation
68 * on non-null object references. Numbered Anonymous IDs are equal when they
69 * have the same number within
70 * the same scope, this method only checks the former.
71 * </p>
72 * <p>
73 * It is generally necessary to override the <code>hashCode</code> method whenever this method
74 * is overridden.
75 * </p>
76 * @param o Object of Type Numbered Anonymous ID
77 * @return <code>true</code> if this Numbered Anonymous ID's number is the same as the obj
78 * argument's number; <code>false</code> otherwise.
79 * @see java.lang.Object#equals(java.lang.Object)
80 * @see java.lang.Object#hashCode()
81 */
82 public boolean equals(Object o) {
83 if (o instanceof NumberedAnonymousID &&
84 ((NumberedAnonymousID)o).getNumber() == getNumber()) {
85 return true;
86 }
87 return false;
88 }
89
90 /**
91 * <p>
92 * If two objects are equal according to the <code>equals(Object)</code> method, then calling
93 * the <code>hashCode</code> method on each of the two objects must produce the same integer
94 * result. However, it is not required that if two objects are unequal according to
95 * the <code>equals(Object)</code> method, then calling the <code>hashCode</code> method on each of the two
96 * objects must produce distinct integer results.
97 * </p>
98 * <p>
99 * This method should be overriden, when the <code>equals(Object)</code> method is overriden.
100 * </p>
101 * @return number of the Numbered Anonymous ID
102 * @see java.lang.Object#hashCode()
103 * @see java.lang.Object#equals(Object)
104 * @see com.ontotext.wsmo4j.common.NumberedIDImpl#getNumber()
105 */
106 public int hashCode() {
107 return getNumber();
108 }
109
110 }
111 /*
112 * $Log$
113 * Revision 1.4 2005/09/21 08:15:39 holgerlausen
114 * fixing java doc, removing asString()
115 *
116 * Revision 1.3 2005/09/09 15:51:42 marin_dimitrov
117 * formatting
118 *
119 * Revision 1.2 2005/09/09 06:31:07 holgerlausen
120 * added serializeID
121 *
122 * Revision 1.1 2005/09/02 13:32:45 ohamano
123 * move logicalexpression packages from ext to core
124 * move tests from logicalexpression.test to test module
125 *
126 * Revision 1.1 2005/09/02 09:43:27 ohamano
127 * integrate wsmo-api and le-api on api and reference implementation level; full parser, serializer and validator integration will be next step
128 *
129 * Revision 1.2 2005/06/22 14:20:15 alex_simov
130 * Copyright header added/updated
131 *
132 * Revision 1.1 2005/06/01 12:00:32 marin_dimitrov
133 * v0.4.0
134 *
135 * Revision 1.4 2005/05/30 15:06:38 alex
136 * toString() delegates to asString()
137 *
138 * Revision 1.3 2005/05/19 14:21:57 marin
139 * fix
140 *
141 * Revision 1.2 2005/05/19 13:48:03 marin
142 * fixed (_# prefix)
143 *
144 * Revision 1.1 2005/05/19 12:50:11 marin
145 * created
146 *
147 *
148 */