KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > util > WeakCacheWildcardMap


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.notification.util;
23
24 import java.util.Map JavaDoc;
25 import java.util.WeakHashMap JavaDoc;
26
27 /**
28  * @author Alphonse Bendt
29  * @version $Id: WeakCacheWildcardMap.java,v 1.1 2005/02/14 00:13:05 alphonse.bendt Exp $
30  */

31 public class WeakCacheWildcardMap implements WildcardMap
32 {
33     private final WildcardMap delegate_;
34     private final Map JavaDoc cache_ = new WeakHashMap JavaDoc();
35     
36     public WeakCacheWildcardMap(WildcardMap delegate)
37     {
38         delegate_ = delegate;
39     }
40     
41     public WeakCacheWildcardMap()
42     {
43         this(new DefaultWildcardMap());
44     }
45     
46     public void clear()
47     {
48         delegate_.clear();
49         cache_.clear();
50     }
51     
52     public Object JavaDoc getNoExpansion(Object JavaDoc key)
53     {
54         return delegate_.getNoExpansion(key);
55     }
56     
57     public Object JavaDoc[] getWithExpansion(Object JavaDoc key)
58     {
59         Object JavaDoc[] result = (Object JavaDoc[]) cache_.get(key.toString());
60         
61         if (result != null)
62         {
63             return result;
64         }
65         
66         result = delegate_.getWithExpansion(key);
67         cache_.put(key.toString(), result);
68         
69         return result;
70     }
71     
72     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value)
73     {
74         cache_.remove(key.toString());
75         
76         return delegate_.put(key, value);
77     }
78     
79     public Object JavaDoc remove(Object JavaDoc key)
80     {
81         cache_.remove(key.toString());
82         
83         return delegate_.remove(key);
84     }
85 }
Popular Tags