KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > LogicalOid


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.impl;
25
26 import java.io.Serializable JavaDoc;
27
28 /**
29  * Identity class of all persistent instances in Jalisto.
30  * It's a wrapper around a long value.
31  */

32 public class LogicalOid implements Serializable JavaDoc, Comparable JavaDoc {
33     public LogicalOid(long floidAsLong) {
34         this.floidAsLong = floidAsLong;
35     }
36
37     public LogicalOid(String JavaDoc floidAsString) {
38         int index = floidAsString.indexOf(".");
39         int clid = Integer.parseInt(floidAsString.substring(0, index));
40         long instanceNumber = Long.parseLong(floidAsString.substring(index + 1));
41         this.floidAsLong = clid * classMulti + instanceNumber;
42     }
43
44     public LogicalOid getClone() {
45         return new LogicalOid(floidAsLong);
46     }
47
48     public long getFloidAsLong() {
49         return floidAsLong;
50     }
51
52     public String JavaDoc getFloidAsString() {
53         return Long.toString(floidAsLong);
54     }
55
56     public short getClid() {
57         return (short) (floidAsLong / classMulti);
58     }
59
60     public long getInstanceNumber() {
61         return floidAsLong % classMulti;
62     }
63
64     public int compareTo(Object JavaDoc o) {
65         LogicalOid candidate = (LogicalOid) o;
66
67         if (this.floidAsLong < candidate.floidAsLong) {
68             return -1;
69         } else if (this.floidAsLong > candidate.floidAsLong) {
70             return 1;
71         } else {
72             return 0;
73         }
74     }
75
76     public boolean equals(Object JavaDoc obj) {
77         try {
78             return ((LogicalOid) obj).floidAsLong == this.floidAsLong;
79         } catch (ClassCastException JavaDoc e) {
80         }
81         return false;
82     }
83
84     public int hashCode() {
85         return (int) (floidAsLong ^ (floidAsLong >>> 32));
86     }
87
88     public String JavaDoc toString() {
89         return getClid() + "." + getInstanceNumber();
90     }
91
92     private long floidAsLong;
93
94     static final long serialVersionUID = -7589377069041161459L;
95     public static final long classMulti = 1000000000000000L;
96 }
97
Popular Tags