001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: ChangeNotifyMapWrapper.java,v 1.3 2004/07/06 15:08:44 jesper Exp $
023: package net.infonode.util.collection.notifymap;
024:
025: import net.infonode.util.ValueChange;
026: import net.infonode.util.collection.map.MapAdapter;
027: import net.infonode.util.collection.map.base.ConstMapIterator;
028: import net.infonode.util.collection.map.base.Map;
029: import net.infonode.util.collection.map.base.MapIterator;
030:
031: public class ChangeNotifyMapWrapper extends AbstractChangeNotifyMap {
032: private class Iterator implements MapIterator {
033: private MapIterator iterator;
034:
035: public Iterator(MapIterator iterator) {
036: this .iterator = iterator;
037: }
038:
039: public void remove() {
040: iterator.remove();
041: fireEntryRemoved(iterator.getKey(), iterator.getValue());
042: }
043:
044: public Object getKey() {
045: return iterator.getKey();
046: }
047:
048: public Object getValue() {
049: return iterator.getValue();
050: }
051:
052: public void next() {
053: iterator.next();
054: }
055:
056: public boolean atEntry() {
057: return iterator.atEntry();
058: }
059: }
060:
061: private Map map;
062:
063: public ChangeNotifyMapWrapper(Map map) {
064: this .map = map;
065: }
066:
067: public Map getMap() {
068: return map;
069: }
070:
071: public Object get(Object key) {
072: return map.get(key);
073: }
074:
075: public boolean containsKey(Object key) {
076: return map.containsKey(key);
077: }
078:
079: public boolean containsValue(Object value) {
080: return map.containsValue(value);
081: }
082:
083: public boolean isEmpty() {
084: return map.isEmpty();
085: }
086:
087: public Object put(Object key, Object value) {
088: Object oldValue = map.put(key, value);
089: fireEntryChanged(key, oldValue, value);
090: return oldValue;
091: }
092:
093: public Object remove(Object key) {
094: Object oldValue = map.remove(key);
095: fireEntryRemoved(key, oldValue);
096: return oldValue;
097: }
098:
099: public void clear() {
100: MapAdapter changeMap = new MapAdapter();
101:
102: for (ConstMapIterator iterator = map.constIterator(); iterator
103: .atEntry(); iterator.next()) {
104: changeMap.put(iterator.getKey(), new ValueChange(iterator
105: .getValue(), null));
106: }
107:
108: map.clear();
109: fireEntriesChanged(changeMap);
110: }
111:
112: public MapIterator iterator() {
113: return new Iterator(map.iterator());
114: }
115: }
|