KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joseki > util > cache > CacheTest


1 /*
2  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6
7 /**
8  * @author Andy Seaborne
9  * @version $Id: CacheTest.java,v 1.3 2004/04/30 14:13:13 andy_seaborne Exp $
10  */

11  
12 package org.joseki.util.cache;
13
14 //import org.apache.commons.logging.* ;
15

16 public class CacheTest
17 {
18
19     public static void main(String JavaDoc[] args)
20     {
21         if (System.getProperty("java.util.logging.config.file") == null)
22             System.setProperty("java.util.logging.config.file", "etc/logging.properties");
23
24         Cache c = new Cache(4, new ItemFactoryTest(), new CachePolicyLRU() ) ;
25         
26         for ( int i = 0 ; i < 5 ; i++)
27         {
28             Integer JavaDoc val = new Integer JavaDoc(i) ;
29             String JavaDoc key = val.toString() ;
30             c.put(key, val) ;
31         }
32         
33         
34         get(c, new Integer JavaDoc(1).toString()) ;
35         get(c, new Integer JavaDoc(2).toString()) ;
36         get(c, new Integer JavaDoc(3).toString()) ;
37         get(c, new Integer JavaDoc(9).toString()) ;
38     }
39     
40     static void get(Cache c, Object JavaDoc k)
41     {
42         Object JavaDoc obj = c.get(k) ;
43         System.out.println(k + " => "+obj) ;
44     }
45     
46     
47     static class ItemFactoryTest implements CacheItemFactory
48     {
49         
50         public Object JavaDoc create(Object JavaDoc key)
51         {
52             return key ;
53         }
54
55         public void destroy(Object JavaDoc key, Object JavaDoc obj)
56         {
57         }
58         
59     }
60 }
61
62
63 /*
64  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
65  * All rights reserved.
66  *
67  * Redistribution and use in source and binary forms, with or without
68  * modification, are permitted provided that the following conditions
69  * are met:
70  * 1. Redistributions of source code must retain the above copyright
71  * notice, this list of conditions and the following disclaimer.
72  * 2. Redistributions in binary form must reproduce the above copyright
73  * notice, this list of conditions and the following disclaimer in the
74  * documentation and/or other materials provided with the distribution.
75  * 3. The name of the author may not be used to endorse or promote products
76  * derived from this software without specific prior written permission.
77  *
78  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
79  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
80  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
82  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
83  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
87  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88  */
Popular Tags