001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Core License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: ObjectID.java,v 1.3 2002/06/08 00:49:38 mediumnet Exp $
008:
009: package org.ozoneDB.core;
010:
011: import java.io.*;
012:
013: import org.ozoneDB.DxLib.DxCompatible;
014: import org.ozoneDB.DxLib.DxObject;
015:
016: public class ObjectID extends DxObject implements Externalizable,
017: Comparable {
018:
019: final static long serialVersionUID = 2;
020: final static byte subSerialVersionUID = 1;
021:
022: private long value = -1;
023:
024: public ObjectID() {
025: }
026:
027: /**
028: * Constructor from a string representation aka a handle.
029: *
030: */
031: public ObjectID(String handle) {
032: value = Long.parseLong(handle);
033: }
034:
035: public ObjectID(long v) {
036: value = v;
037: }
038:
039: public final long value() {
040: return value;
041: }
042:
043: public final int hashCode() {
044: //wenn diese 32 bits keinen unterschied mehr bringen,
045: //wird mit equals() weiter verglichen
046: return (int) value;
047: }
048:
049: public final boolean equals(Object obj) {
050: if (this == obj) {
051: return true;
052: }
053: if (obj != null && obj instanceof ObjectID) {
054: return value == ((ObjectID) obj).value;
055: }
056: return false;
057: }
058:
059: public final boolean isLess(DxCompatible obj) {
060: if (obj instanceof ObjectID) {
061: return value < ((ObjectID) obj).value;
062: }
063: return false;
064: }
065:
066: public int compareTo(Object o) {
067: return compareTo((ObjectID) o);
068: }
069:
070: /**
071: Compares this ObjectID to the given ObjectID. This is useful for ozone objects which
072: need a sort order but may not be equals. (E.g. for use in a {@link java.util.SortedSet}.)
073:
074: @return
075: !=0 for ObjectIDs which are not equal
076: 0 for ObjectIDs which are equal
077: */
078: public int comparTo(ObjectID o) {
079: long diff = value() - o.value();
080:
081: return diff > 0 ? 1 : diff < 0 ? -1 : 0;
082: }
083:
084: public Object clone() {
085: return new ObjectID(value);
086: }
087:
088: public final void writeExternal(ObjectOutput out)
089: throws IOException {
090: // env.logWriter.newEntry ("write: " + getClass().toString() + " " + value, LogWriter.DEBUG);
091: out.writeByte(subSerialVersionUID);
092: out.writeLong(value);
093: }
094:
095: public final void readExternal(ObjectInput in) throws IOException,
096: ClassNotFoundException {
097: byte streamVersionUID = in.readByte();
098: value = in.readLong();
099: // env.logWriter.newEntry ("read: " + getClass().toString() + " " + value, LogWriter.DEBUG);
100: }
101:
102: /**
103: * The value of the ObjectID as String. Do not change this, the name
104: * of the cluster files depend on it.
105: */
106: public String toString() {
107: return String.valueOf(value);
108: }
109: }
|