Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/modama/gui/tools/Cache.java


1   /**
2    Modama project, Institute for Polymer Research Dresden
3    Copyright (C) 2003 P. Fritsche, A. Uhlig
4    http://www.modama.org
5    info@modama.org
6   
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10   (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received a copy of the GNU General Public License
18   along with this program; if not, write to the Free Software
19   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  
21   file created: May 11, 2003
22   
23   */
24  package org.modama.gui.tools;
25  
26  import java.util.HashMap;
27  
28  /**
29   * This class encapsulate a cache stragety.
30   * currently it just a lookup-table-cache (call get(key) and you get the object from the hashmap if its
31   * already exists. if not create(key) is called)
32   */
33  public abstract class Cache
34  {
35      HashMap cache = new HashMap();
36  
37      /**
38       * get the object. if key does not exists it will be created with create(key)
39       * @param key
40       * @return
41       */
42      public Object get( Object key )
43      {
44          if( cache.containsKey( key )) return cache.get( key );
45          Object v = create( key );
46          cache.put( key, v);
47          return v;
48      }
49  
50      /**
51       * put code to create an object related to key here
52       * @param key
53       * @return
54       */
55      public abstract Object create( Object key );
56  }