KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > WrappableMap


1 /*
2   Copyright (C) 2001-2002 Laurent Martelli.
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui;
19
20 import java.util.Map JavaDoc;
21 import gnu.regexp.*;
22
23 /**
24  * This class is a mere wrapper which delegates all methods to a real
25  * Map. It allows you to have wrappable maps.
26  */

27
28 public class WrappableMap
29 {
30    private Map JavaDoc delegate;
31
32    protected Map JavaDoc getDelegate() {
33       return delegate;
34    }
35
36    public WrappableMap(Map JavaDoc delegate) {
37       this.delegate = delegate;
38    }
39    
40    /**
41     * Calls put on delegate for every key already in delegate which
42     * matches key. For instance, call with <code>put("gui.*",0)</code>
43     * will turn off all gui traces.
44     * @param key regexp key
45     * @param value trace level
46     */

47
48    public void put ( String JavaDoc key, Integer JavaDoc value )
49       throws REException
50    {
51       Object JavaDoc keys[] = delegate.keySet().toArray();
52       RE re = new RE(key);
53       for (int i=0; i<keys.length;i++) {
54          String JavaDoc cur_key = (String JavaDoc)keys[i];
55          if (re.isMatch(cur_key))
56             delegate.put(cur_key, value);
57       }
58    }
59    
60    public void clear ( ) {
61       delegate.clear();
62    }
63    
64    public Object JavaDoc remove ( String JavaDoc key ) {
65       return delegate.remove(key);
66    }
67  
68    static public String JavaDoc[] getCategories(WrappableMap wmap ) {
69       java.util.Set JavaDoc keys = wmap.getDelegate().keySet();
70       String JavaDoc[] result = new String JavaDoc[keys.size()];
71       java.util.Iterator JavaDoc i = keys.iterator();
72       int j=0;
73       while (i.hasNext()) {
74          result[j++] = (String JavaDoc)i.next();
75       }
76       return result;
77    }
78
79    static public Integer JavaDoc[] getLevels(WrappableMap wmap) {
80       return new Integer JavaDoc[] {new Integer JavaDoc(0),new Integer JavaDoc(1),
81                             new Integer JavaDoc(2),new Integer JavaDoc(3)};
82    }
83 }
84
Popular Tags