1 package org.myoodb.core; 25 26 import java.io.*; 27 28 public final class Identifier implements Externalizable, Comparable 29 { 30 private long m_value = -1; 31 private boolean m_root = false; 32 33 public Identifier() 34 { 35 } 36 37 public Identifier(long value) 38 { 39 m_value = value; 40 } 41 42 public Identifier(long value, boolean root) 43 { 44 m_value = value; 45 m_root = root; 46 } 47 48 public final long getValue() 49 { 50 return m_value; 51 } 52 53 public final boolean isRoot() 54 { 55 return m_root; 56 } 57 58 public final int hashCode() 59 { 60 return (int) m_value; 61 } 62 63 public final boolean equals(Object obj) 64 { 65 if (this == obj) 66 { 67 return true; 68 } 69 else if (obj instanceof Identifier) 70 { 71 return m_value == ((Identifier) obj).m_value; 72 } 73 else 74 { 75 return false; 76 } 77 } 78 79 public final int compareTo(Object obj) 80 { 81 if (obj instanceof Identifier) 82 { 83 long diff = getValue() - ((Identifier) obj).getValue(); 84 85 return diff > 0 ? 1 : diff < 0 ? -1 : 0; 86 } 87 else 88 { 89 return -1; 90 } 91 } 92 93 public final void writeExternal(ObjectOutput out) throws IOException 94 { 95 out.writeLong(m_value); 96 out.writeBoolean(m_root); 97 } 98 99 public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException 100 { 101 m_value = in.readLong(); 102 m_root = in.readBoolean(); 103 104 MyOodbManager manager = MyOodbManager.getTheManager(); 105 if ((manager != null) && (manager.getStoreManager().isDefraggingDatabase() == true)) 106 { 107 java.util.HashMap defragIdMap = manager.getStoreManager().getDefraggedContainerIdentifierMap(); 108 Identifier newObjectId = (Identifier) defragIdMap.get(this); 109 m_value = newObjectId.getValue(); 110 } 111 } 112 113 public String toString() 114 { 115 return String.valueOf(m_value); 116 } 117 } 118 | Popular Tags |