View Javadoc

1   /*
2    *  XNap Commons
3    *
4    *  Copyright (C) 2005  Steffen Pingel
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.xnap.commons.pkg;
21  
22  public abstract class AbstractToken implements Comparable
23  {
24  
25  	String token;
26  
27  	public AbstractToken(AbstractToken[] depends, String separator)
28  	{
29  		// build canonical form
30  		StringBuffer sb = new StringBuffer();
31  		for (int i = 0; i < depends.length; i++) {
32  			sb.append(depends[i].token);
33  			if (i < depends.length - 1) {
34  				sb.append(separator);
35  			}
36  		}
37  
38  		this.token = sb.toString();
39  	}
40  
41  	public AbstractToken(String token)
42  	{
43  		this.token = token;
44  	}
45  
46  	public AbstractToken()
47  	{
48  	}
49  
50  	public int compareTo(Object o) 
51  	{
52  		AbstractToken t = (AbstractToken)o;
53  		return token.compareTo(t.token);
54  	}
55  
56  	public boolean equals(Object o) 
57  	{
58  		if (o instanceof AbstractToken) {
59  			return ((AbstractToken)o).token.equals(token);
60  		}
61  		return false;
62  	}
63  
64  	public int hashCode()
65  	{
66  		return token.hashCode();
67  	}
68  
69  	public String toString()
70  	{
71  		return token;
72  	}
73  
74  }
75