View Javadoc

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