Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 42139 invoked from network); 18 Feb 2002 21:06:29 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 18 Feb 2002 21:06:29 -0000 Received: (qmail 11552 invoked by uid 97); 18 Feb 2002 21:06:31 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 11536 invoked by uid 97); 18 Feb 2002 21:06:31 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 11525 invoked from network); 18 Feb 2002 21:06:30 -0000 Message-Id: <5.1.0.14.0.20020218135725.00ae7828@interobjective.com> X-Sender: james@interobjective.com@interobjective.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Mon, 18 Feb 2002 14:06:48 -0700 To: "Jakarta Commons Developers List" From: James House Subject: Re: Collections 1.1? In-Reply-To: <003401c1b8bd$342bcce0$8905050a@eb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - thunder2.cwihosting.com X-AntiAbuse: Original Domain - jakarta.apache.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [0 0] X-AntiAbuse: Sender Address Domain - interobjective.com X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N > Does anyone have other >work they would like to include in this release? (I know Michael has some >pending patches, if anyone is feeling ambitious.) > >- Morgan I've got a "DirtyFlagMap" that may be of interest. It's a Map that wraps another Map, and adds a "dirty" flag - so you can tell if the Map has been modified since the flag was last cleared. This is very useful for environments where you pass a Map to a component (such as a plug-in) and you need to be able to tell if it was modified. Here's the very simple implementation, in case anyone's interested, and/or you think it good for inclusion in Collections 1.1 James ============================ import java.util.Map; import java.util.Set; import java.util.Collection; import java.util.HashMap; /** *

An implementation of Map that wraps another Map * and flags itself 'dirty' when it is modified.

* * @author James House */ public class DirtyFlagMap implements Map { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Data Members. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ private boolean dirty = false; private Map map; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Constructors. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /** *

Create a DirtyFlagMap that 'wraps' the given Map.

*/ public DirtyFlagMap(Map mapToWrap) { if(mapToWrap == null) throw new IllegalArgumentException("mapToWrap cannot be null!"); map = mapToWrap; } /** *

Create a DirtyFlagMap that 'wraps' a HashMap.

* * @see java.util.HashMap */ public DirtyFlagMap() { map = new HashMap(); } /** *

Create a DirtyFlagMap that 'wraps' a HashMap that has * the given initial capacity.

* * @see java.util.HashMap */ public DirtyFlagMap(int initialCapacity) { map = new HashMap(initialCapacity); } /** *

Create a DirtyFlagMap that 'wraps' a HashMap that has * the given initial capacity and load factor.

* * @see java.util.HashMap */ public DirtyFlagMap(int initialCapacity, float loadFactor) { map = new HashMap(initialCapacity, loadFactor); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Interface. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /** *

Clear the 'dirty' flag (set dirty flag to false).

*/ public void clearDirtyFlag() { dirty = false; } /** *

Determine whether the Map is flagged dirty.

*/ public boolean isDirty() { return dirty; } public Map getWrappedMap() { return map; } public void clear() { dirty = true; map.clear(); } public boolean containsKey(Object key) { return map.containsKey(key); } public boolean containsValue(Object val) { return map.containsValue(val); } public Set entrySet() { return map.entrySet(); } public boolean equals(Object obj) { if(obj == null || !(obj instanceof DirtyFlagMap)) return false; return map.equals(((DirtyFlagMap)obj).getWrappedMap()); } public Object get(Object key) { return map.get(key); } public boolean isEmpty() { return map.isEmpty(); } public Set keySet() { return map.keySet(); } public Object put(Object key, Object val) { dirty = true; return map.put(key, val); } public void putAll(Map t) { if(!t.isEmpty()) dirty = true; map.putAll(t); } public Object remove(Object key) { Object obj = map.remove(key); if(obj != null) dirty = true; return obj; } public int size() { return map.size(); } public Collection values() { return map.values(); } } ============================ -- To unsubscribe, e-mail: For additional commands, e-mail: