KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > profileservice > spi > ProfileKey


1 package org.jboss.profileservice.spi;
2
3 import java.io.Serializable JavaDoc;
4
5 /**
6  * The key for a Profile. It consists fo the domain, server and name.
7  *
8  * @author Scott.Stark@jboss.org
9  * @version $Revision$
10  */

11 public class ProfileKey
12    implements Comparable JavaDoc, Serializable JavaDoc
13 {
14    private static final long serialVersionUID = 1;
15    /** The DEFAULT value for domain, server, name */
16    public static final String JavaDoc DEFAULT = "default";
17
18    /** The profile domain/cluster */
19    private String JavaDoc domain;
20    /** The server/node */
21    private String JavaDoc server;
22    /** The profile name */
23    private String JavaDoc name;
24
25    /**
26     * Calls this this(DEFAULT, DEFAULT, name)
27     * @param name - the profile name
28     */

29    public ProfileKey(String JavaDoc name)
30    {
31       this(DEFAULT, DEFAULT, name);
32    }
33
34    /**
35     * Build a profile key from the domain, server and name. If any parameter
36     * is null it defaulted to "default".
37     *
38     * @param domain - the admin domain
39     * @param server - the server instance name
40     * @param name - the profile name
41     */

42    public ProfileKey(String JavaDoc domain, String JavaDoc server, String JavaDoc name)
43    {
44       if( domain == null )
45          domain = DEFAULT;
46       this.domain = domain;
47       if( server == null )
48          server = DEFAULT;
49       this.server = server;
50       if( name == null )
51          name = DEFAULT;
52       this.name = name;
53    }
54
55    /**
56     * Compare based on domain, then server and finally name.
57     *
58     * @param o - the ProfileKey instance to compare to
59     * @return < 0, 0, > 0 based on whether this is less than, equal to
60     * or greater than o.
61     */

62    public int compareTo(Object JavaDoc o)
63    {
64       ProfileKey pk = (ProfileKey) o;
65       int compareTo = domain.compareTo(pk.domain);
66       if( compareTo == 0 )
67       {
68          compareTo = server.compareTo(pk.server);
69          if( compareTo == 0 )
70          {
71             compareTo = name.compareTo(pk.name);
72          }
73       }
74       return compareTo;
75    }
76    public boolean equals(Object JavaDoc o)
77    {
78       return compareTo(o) == 0;
79    }
80    public int hashCode()
81    {
82       int hash = domain.hashCode() + server.hashCode() + name.hashCode();
83       return hash;
84    }
85 }
86
Popular Tags