fenfire-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ff-cvs] fenfire/org/fenfire/swamp FlushableCachedNodeFu...


From: Matti Katila
Subject: [ff-cvs] fenfire/org/fenfire/swamp FlushableCachedNodeFu...
Date: Sat, 16 Aug 2003 12:01:49 -0400

CVSROOT:        /cvsroot/fenfire
Module name:    fenfire
Branch:         
Changes by:     Matti Katila <address@hidden>   03/08/16 12:01:49

Modified files:
        org/fenfire/swamp: FlushableCachedNodeFunction.java 

Log message:
        documentation and different flush sets

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/swamp/FlushableCachedNodeFunction.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: fenfire/org/fenfire/swamp/FlushableCachedNodeFunction.java
diff -u fenfire/org/fenfire/swamp/FlushableCachedNodeFunction.java:1.1 
fenfire/org/fenfire/swamp/FlushableCachedNodeFunction.java:1.2
--- fenfire/org/fenfire/swamp/FlushableCachedNodeFunction.java:1.1      Thu Jul 
17 12:28:19 2003
+++ fenfire/org/fenfire/swamp/FlushableCachedNodeFunction.java  Sat Aug 16 
12:01:49 2003
@@ -4,38 +4,82 @@
 import java.util.*;
 import org.fenfire.*;
 import org.fenfire.util.*;
+import org.nongnu.libvob.util.CachingMap;
 
+/** CachedNodeFunction is good in caching 
+ * but sometimes it's must to flush the data and 
+ * this class does flushing and caching.
+ * <p>
+ * Different flush sets can also be flushed.
+ */
+public class FlushableCachedNodeFunction extends CachedNodeFunction {
+
+
+    static private HashMap funcsMap = new HashMap();
+    static private void add(Object set, Object func) {
+       if (funcsMap.get(set) == null)
+           funcsMap.put(set, new ArrayList());
+       List l = (List)funcsMap.get(set);
+       l.add(func);
+    }
 
-public class FlushableCachedNodeFunction implements NodeFunction {
+    /** Flush all different sets.
+     */
+    static public void flushAll() {
+       for (Iterator it = funcsMap.keySet().iterator(); it.hasNext(); ) {
+           Object set = it.next();
+           flush(set);
+       }
+    }
 
-    static private ArrayList funcs = new ArrayList();
+    /** Flush the default set.
+     */
     static public void flush() {
-        for (int i=0; i<funcs.size(); i++) {
+       flush(DEFAULT);
+    }
+
+    /** Flush the set which is given.
+     * Throws an error if set doesn't exist.
+     */
+    static public void flush(Object set) {
+       if (funcsMap.get(set) == null)
+           throw new Error("No flush set found: '"+set+"'");
+
+       List l = (List)funcsMap.get(set);
+        for (int i=0; i<l.size(); i++) {
             FlushableCachedNodeFunction one = 
-                (FlushableCachedNodeFunction)funcs.get(i);
+                (FlushableCachedNodeFunction)l.get(i);
             one.flushItAndSmile();
         }
     }
 
 
+    static private final Object DEFAULT = new Object();
+
     private final int n;
-    private final Fen fen;
-    private final NodeFunction f;
-    private CachedNodeFunction cache = null;
 
+    /** Constructor for default set.
+     */
     public FlushableCachedNodeFunction(int n, Fen fen, NodeFunction f) {
-        this.n = n; this.fen = fen; this.f = f;
-        this.flushItAndSmile();
-        funcs.add(this);
+       this(n,fen,f, DEFAULT);
+    }
+
+    /** Constructor for different sets.
+     * @param set The set to be flushed when flushing.
+     */
+    public FlushableCachedNodeFunction(int n, Fen fen, NodeFunction f, Object 
set) {
+       super(n, fen.graph, f);
+       this.n = n;
+        this.add(set, this);
     }
         
     private void flushItAndSmile() {
-        cache = new CachedNodeFunction(n, fen.constgraph, f);
+        super.cache = new CachingMap(n);
     }
 
 
     public Object f(ConstGraph g, Object node) {
-        return cache.f(g, node);
+        return super.f(g, node);
     }
 
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]