001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.core;
025:
026: import java.io.*;
027:
028: public final class Identifier implements Externalizable, Comparable {
029: private long m_value = -1;
030: private boolean m_root = false;
031:
032: public Identifier() {
033: }
034:
035: public Identifier(long value) {
036: m_value = value;
037: }
038:
039: public Identifier(long value, boolean root) {
040: m_value = value;
041: m_root = root;
042: }
043:
044: public final long getValue() {
045: return m_value;
046: }
047:
048: public final boolean isRoot() {
049: return m_root;
050: }
051:
052: public final int hashCode() {
053: return (int) m_value;
054: }
055:
056: public final boolean equals(Object obj) {
057: if (this == obj) {
058: return true;
059: } else if (obj instanceof Identifier) {
060: return m_value == ((Identifier) obj).m_value;
061: } else {
062: return false;
063: }
064: }
065:
066: public final int compareTo(Object obj) {
067: if (obj instanceof Identifier) {
068: long diff = getValue() - ((Identifier) obj).getValue();
069:
070: return diff > 0 ? 1 : diff < 0 ? -1 : 0;
071: } else {
072: return -1;
073: }
074: }
075:
076: public final void writeExternal(ObjectOutput out)
077: throws IOException {
078: out.writeLong(m_value);
079: out.writeBoolean(m_root);
080: }
081:
082: public final void readExternal(ObjectInput in) throws IOException,
083: ClassNotFoundException {
084: m_value = in.readLong();
085: m_root = in.readBoolean();
086:
087: MyOodbManager manager = MyOodbManager.getTheManager();
088: if ((manager != null)
089: && (manager.getStoreManager().isDefraggingDatabase() == true)) {
090: java.util.HashMap defragIdMap = manager.getStoreManager()
091: .getDefraggedContainerIdentifierMap();
092:
093: Identifier newObjectId = (Identifier) defragIdMap.get(this );
094: if (newObjectId != null) {
095: m_value = newObjectId.getValue();
096: }
097: }
098: }
099:
100: public String toString() {
101: return String.valueOf(m_value);
102: }
103: }
|