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 AbcObjectDbImpl extends CollectableDbImpl implements
27: AbcObject {
28: protected String m_string;
29: protected AbcStore m_abcStore;
30:
31: public AbcObjectDbImpl() {
32: m_string = null;
33: m_abcStore = null;
34: }
35:
36: public void onDelete() {
37: if (m_abcStore != null) {
38: m_abcStore.removeAbcObject(this );
39: }
40: }
41:
42: public Comparable getKey() {
43: return getString();
44: }
45:
46: // XXX: one should ensure that each abc string is unique ( see AbcStore )
47: public void setString(String string) {
48: if (m_abcStore != null) {
49: throw new org.myoodb.exception.PermissionException(
50: "Object already in Store");
51: }
52:
53: m_string = string;
54: }
55:
56: public String getString() {
57: return m_string;
58: }
59:
60: public void setAbcStore(AbcStore abcStore) {
61: m_abcStore = abcStore;
62: }
63:
64: public AbcStore getAbcStore() {
65: return m_abcStore;
66: }
67:
68: public int hashCode() {
69: return m_string.hashCode();
70: }
71:
72: public boolean equals(Object obj) {
73: if (this == obj) {
74: return true;
75: } else if (obj instanceof String) {
76: return getString().equals((String) obj);
77: } else if (obj instanceof AbcObject) {
78: return getString().equals(((AbcObject) obj).getString());
79: } else {
80: return false;
81: }
82: }
83:
84: public int compareTo(Object obj) {
85: if (obj instanceof String) {
86: return getString().compareTo((String) obj);
87: } else if (obj instanceof AbcObject) {
88: return getString().compareTo(((AbcObject) obj).getString());
89: } else {
90: return -1;
91: }
92: }
93:
94: public String toString() {
95: return "AbcObject: " + getString();
96: }
97: }
|