KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > ext > Db4oUUID


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.ext;
22
23 import com.db4o.foundation.*;
24
25
26 /**
27  * a unique universal identify for an object. <br><br>The db4o UUID consists of
28  * two parts:<br> - an indexed long for fast access,<br> - the signature of the
29  * {@link com.db4o.ObjectContainer ObjectContainer} the object was created with.
30  * <br><br>Db4oUUIDs are valid representations of objects over multiple
31  * ObjectContainers
32  */

33 public class Db4oUUID {
34
35     private final long longPart;
36     private final byte[] signaturePart;
37
38     /**
39      * constructs a Db4oUUID from a long part and a signature part
40      *
41      * @param longPart_ the long part
42      * @param signaturePart_ the signature part
43      */

44     public Db4oUUID(long longPart_, byte[] signaturePart_) {
45         longPart = longPart_;
46         signaturePart = signaturePart_;
47     }
48
49     /**
50      * returns the long part of this UUID. <br><br>To uniquely identify an object
51      * universally, db4o uses an indexed long and a reference to the
52      * Db4oDatabase object it was created on.
53      *
54      * @return the long part of this UUID.
55      */

56     public long getLongPart() {
57         return longPart;
58     }
59
60
61     /**
62      * returns the signature part of this UUID. <br><br> <br><br>To uniquely
63      * identify an object universally, db4o uses an indexed long and a reference to
64      * the Db4oDatabase singleton object of the {@link
65      * com.db4o.ObjectContainer ObjectContainer} it was created on. This method
66      * returns the signature of the Db4oDatabase object of the ObjectContainer: the
67      * signature of the origin ObjectContainer.
68      *
69      * @return the signature of the Db4oDatabase for this UUID.
70      */

71     public byte[] getSignaturePart() {
72         return signaturePart;
73     }
74
75     public boolean equals(Object JavaDoc o) {
76         if (this == o) return true;
77         if (o == null || getClass() != o.getClass()) return false;
78
79         final Db4oUUID other = (Db4oUUID) o;
80
81         if (longPart != other.longPart) return false;
82         if (signaturePart == null) {
83             return other.signaturePart == null;
84         }
85         if (signaturePart.length != other.signaturePart.length) {
86             return false;
87         }
88         for (int i = 0; i < signaturePart.length; i++) {
89             if (signaturePart[i] != other.signaturePart[i]) {
90                 return false;
91             }
92         }
93         return true;
94     }
95
96     public int hashCode() {
97         return (int) (longPart ^ (longPart >>> 32));
98     }
99
100     public String JavaDoc toString() {
101         if(! Debug4.prettyToStrings){
102             return super.toString();
103         }
104         
105         String JavaDoc sig = "";
106         for (int i = 0; i < signaturePart.length; i++) {
107             sig += signaturePart[i] + " ";
108         }
109         
110         return "long " + longPart + " , signature " + sig;
111     }
112
113 }
114
Popular Tags