01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
11: //
12: // This program is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // GNU General Public License and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.collectable;
25:
26: public class DigitObjectDbImpl extends CollectableDbImpl implements
27: DigitObject {
28: protected long m_number;
29: protected DigitStore m_digitStore;
30:
31: public DigitObjectDbImpl() {
32: m_number = -1;
33: m_digitStore = null;
34: }
35:
36: public void onDelete() {
37: if (m_digitStore != null) {
38: m_digitStore.removeDigitObject(this );
39: }
40: }
41:
42: public Comparable getKey() {
43: return (Long) getNumber();
44: }
45:
46: // XXX: one should ensure that each digit number is unique ( see DigitStore )
47: public void setNumber(long number) {
48: if ((m_number != -1) && (m_digitStore != null)) {
49: throw new org.myoodb.exception.PermissionException(
50: "Object already in Store");
51: }
52:
53: m_number = number;
54: }
55:
56: public long getNumber() {
57: return m_number;
58: }
59:
60: public void setDigitStore(DigitStore digitStore) {
61: m_digitStore = digitStore;
62: }
63:
64: public DigitStore getDigitStore() {
65: return m_digitStore;
66: }
67:
68: public int hashCode() {
69: return (int) m_number;
70: }
71:
72: public boolean equals(Object obj) {
73: if (this == obj) {
74: return true;
75: } else if (obj instanceof Long) {
76: return getNumber() == ((Long) obj).longValue();
77: } else if (obj instanceof DigitObject) {
78: return getNumber() == (((DigitObject) obj).getNumber());
79: } else {
80: return false;
81: }
82: }
83:
84: public int compareTo(Object obj) {
85: if (obj instanceof Long) {
86: return ((Long) getNumber()).compareTo((Long) obj);
87: } else if (obj instanceof DigitObject) {
88: long diff = getNumber() - ((DigitObject) obj).getNumber();
89: return diff > 0 ? 1 : diff < 0 ? -1 : 0;
90: } else {
91: return -1;
92: }
93: }
94:
95: public String toString() {
96: return "DigitObject: " + getNumber();
97: }
98: }
|