KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > ObjectID


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 public class ObjectID implements Insertable {
14
15     private static final int Size = 8;
16     private static final int ObjectNumberOffset = 0;
17     private long objectNumber;
18
19     public ObjectID(byte[] b) throws IndexedStoreException {
20         if (b.length != Size) {
21             throw new IndexedStoreException(IndexedStoreException.ObjectIDInvalid);
22         }
23         Buffer buf = new Buffer(b);
24         objectNumber = buf.getLong(ObjectNumberOffset, 8);
25     }
26
27     public ObjectID(long objectNumber) {
28         this.objectNumber = objectNumber;
29     }
30
31     public boolean equals(Object JavaDoc anObject) {
32         if (!(anObject instanceof ObjectID))
33             return false;
34         ObjectID id = (ObjectID) anObject;
35         if (this.objectNumber != id.objectNumber)
36             return false;
37         return true;
38     }
39
40     public int hashCode() {
41         return (int) objectNumber;
42     }
43
44     public byte[] toByteArray() {
45         Buffer buf = new Buffer(Size);
46         buf.put(ObjectNumberOffset, 8, objectNumber);
47         return buf.get();
48     }
49 }
50
Popular Tags