alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * ActionsCache.java
 *
 * Created on November 14, 2002, 3:31 PM
 */

package org.netbeans.test.editor.app.gui.tree;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import org.netbeans.test.editor.app.gui.actions.TreeNewType;
import org.netbeans.test.editor.app.gui.actions.TreeNodeAction;

/**
 *
 * @author  eh103527
 */
public class ActionsCache {
    
    HashMap actions;
    
    private static ActionsCache instance;
    
    /** Creates a new instance of ActionsCache */
    private ActionsCache() {
        actions=new HashMap();
    }
    
    public static ActionsCache getDefault() {
        if (instance == null) {
            instance=new ActionsCache();
        }
        return instance;
    }
    
    public void addNodeActions(Class node,Vector acts) {
        actions.put(node, acts);
    }
    
    public void addNodeAction(Class node,TreeNodeAction action) {
        if (actions.get(node) != null) {
            ((Vector)(actions.get(node))).add(action);
        } else {
            Vector v=new Vector();
            addNodeActions(node,v);
            v.add(action);
        }
    }
    
    public Vector getActions(Class node) {
        return (Vector)(actions.get(node));
    }
    
    public TreeNodeAction getAction(Class node, Class action) {
        Vector v=(Vector)(actions.get(node));
        Object o;
        for (Iterator it=v.iterator();it.hasNext();) {
            o=it.next();
            if (o.getClass().equals(action)) {
                return (TreeNodeAction)o;
            }
        }
        return null;
    }    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.