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.collectable;
025:
026: public class TreeMapDbImpl extends CollectableDbImpl implements TreeMap {
027: private java.util.TreeMap m_treeMap;
028:
029: public TreeMapDbImpl() {
030: m_treeMap = new java.util.TreeMap();
031: }
032:
033: public void fixUpReference(long fixUpTime) {
034: if (referenceHasBeenFixedUp(fixUpTime) == true) {
035: return;
036: }
037:
038: super .fixUpReference(fixUpTime);
039:
040: synchronized (m_treeMap) {
041: CollectableDbImpl.fixUpReference(m_treeMap, fixUpTime);
042: }
043: }
044:
045: public TreeMapDbImpl(java.util.Comparator cmp) {
046: m_treeMap = new java.util.TreeMap(cmp);
047: }
048:
049: public Object put(Object key, Object value) {
050: Object retval = null;
051:
052: synchronized (m_treeMap) {
053: retval = m_treeMap.put(key, value);
054: }
055:
056: return retval;
057: }
058:
059: public void putAll(java.util.Map map) {
060: synchronized (m_treeMap) {
061: m_treeMap.putAll(map);
062: }
063: }
064:
065: public Object get(Object key) {
066: Object retval = null;
067:
068: synchronized (m_treeMap) {
069: retval = m_treeMap.get(key);
070: }
071:
072: return retval;
073: }
074:
075: public Object remove(Object key) {
076: Object retval = null;
077:
078: synchronized (m_treeMap) {
079: retval = m_treeMap.remove(key);
080: }
081:
082: return retval;
083: }
084:
085: public Object firstKey() {
086: Object retval = null;
087:
088: synchronized (m_treeMap) {
089: retval = m_treeMap.firstKey();
090: }
091:
092: return retval;
093: }
094:
095: public Object lastKey() {
096: Object retval = null;
097:
098: synchronized (m_treeMap) {
099: retval = m_treeMap.lastKey();
100: }
101:
102: return retval;
103: }
104:
105: public void clear() {
106: synchronized (m_treeMap) {
107: m_treeMap.clear();
108: }
109: }
110:
111: public int size() {
112: int retval = -1;
113:
114: synchronized (m_treeMap) {
115: retval = m_treeMap.size();
116: }
117:
118: return retval;
119: }
120:
121: public String toString() {
122: String retval = null;
123:
124: synchronized (m_treeMap) {
125: retval = m_treeMap.toString();
126: }
127:
128: return retval;
129: }
130:
131: public boolean equals(Object obj) {
132: boolean retval = false;
133:
134: synchronized (m_treeMap) {
135: retval = m_treeMap.equals(obj);
136: }
137:
138: return retval;
139: }
140:
141: public java.util.TreeSet keySet() {
142: java.util.TreeSet retval = null;
143:
144: synchronized (m_treeMap) {
145: retval = new java.util.TreeSet(m_treeMap.keySet());
146: }
147:
148: return retval;
149: }
150:
151: public java.util.TreeSet entrySet() {
152: java.util.TreeSet retval = null;
153:
154: synchronized (m_treeMap) {
155: retval = new java.util.TreeSet(m_treeMap.entrySet());
156: }
157:
158: return retval;
159: }
160:
161: public java.util.Collection values() {
162: java.util.Collection retval = null;
163:
164: synchronized (m_treeMap) {
165: retval = m_treeMap.values();
166: }
167:
168: return retval;
169: }
170:
171: public java.util.TreeMap collection() {
172: return m_treeMap;
173: }
174:
175: public java.util.ArrayList toArrayList() {
176: java.util.ArrayList retval = null;
177:
178: synchronized (m_treeMap) {
179: retval = new java.util.ArrayList(m_treeMap.values());
180: }
181:
182: return retval;
183: }
184:
185: public Iterator iterator() {
186: return (Iterator) getDatabase().createObject(
187: IteratorDbImpl.class.getName(), "java.util.Collection",
188: new Object[] { m_treeMap });
189: }
190:
191: public java.util.SortedMap headMap(Object toElement) {
192: synchronized (m_treeMap) {
193: return m_treeMap.headMap(toElement);
194: }
195: }
196:
197: public java.util.SortedMap subMap(Object fromElement,
198: Object toElement) {
199: synchronized (m_treeMap) {
200: return m_treeMap.subMap(fromElement, toElement);
201: }
202: }
203:
204: public java.util.SortedMap tailMap(Object fromElement) {
205: synchronized (m_treeMap) {
206: return m_treeMap.tailMap(fromElement);
207: }
208: }
209: }
|