KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > SyncItemKey


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19
20 package sync4j.framework.engine;
21
22 /**
23  * This class represents a unique identifier of a <i>SyncItem</i> item in a repository.
24  *
25  * @author Stefano Fornari @ Funambol
26  *
27  * @version $Id: SyncItemKey.java,v 1.9 2005/03/02 20:57:37 harrie Exp $
28  */

29 public class SyncItemKey implements java.io.Serializable JavaDoc {
30     
31     // -------------------------------------------------------------- Properties
32

33     /**
34      * The key value
35      */

36     private Object JavaDoc keyValue = null;
37     public Object JavaDoc getKeyValue(){
38         return keyValue;
39     }
40     
41     /**
42      * @param keyValue the key - NOT NULL (assert checked)
43      */

44     public void setKeyValue(Object JavaDoc keyValue){
45         assert (keyValue != null);
46         this.keyValue = keyValue;
47     }
48     
49     // ------------------------------------------------------------ Constructors
50

51     /**
52      * @param keyValue the key - NOT NULL (assert checked)
53      */

54     public SyncItemKey(Object JavaDoc keyValue) {
55         assert (keyValue != null);
56         this.keyValue = keyValue;
57     }
58     
59     // ---------------------------------------------------------- Public Methods
60

61     /**
62      * @return this key's value as a String object (calling toString() on the
63      * value object)
64      */

65     public String JavaDoc getKeyAsString() {
66         return keyValue.toString();
67     }
68     
69     /**
70      * Two keys are equal if their keyValues are equal.
71      * The keys are objects but they have to be considered as String object
72      * to be compared.
73      *
74      * @param o the object this instance must be compared to.
75      *
76      * @return the given object is equal to this object
77      */

78     public boolean equals(Object JavaDoc o) {
79         if (!(o instanceof SyncItemKey)) return false;
80         
81         return ((SyncItemKey)o).getKeyAsString().equals(getKeyAsString());
82     }
83     
84     /**
85      * Returns the hash code of this object
86      *
87      * @return the hash code of this object
88      */

89     public int hashCode() {
90         return getKeyAsString().hashCode();
91     }
92     
93     /**
94      * @return a string representation for debugging purposes of this <i>SyncItemKey</i>.
95      */

96     public String JavaDoc toString() {
97         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
98         
99         sb.append( " { keyValue: " );
100         sb.append( getKeyAsString() );
101         sb.append( " } " );
102         
103         return sb.toString();
104     }
105 }
Popular Tags