nodecache.java

来自「openmap java写的开源数字地图程序. 用applet实现,可以像g」· Java 代码 · 共 104 行

JAVA
104
字号
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/graphicLoader/netmap/NodeCache.java,v $// $RCSfile: NodeCache.java,v $// $Revision: 1.2.2.2 $// $Date: 2004/10/14 18:26:50 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.graphicLoader.netmap;import java.util.*;/** * A holder for all the nodes on the map. Cache is smart enough to * modify or add a node based on a description. */public class NodeCache {    private Hashtable nodeTable = null;    NodeCache() {        nodeTable = new Hashtable();    }    NodeCache(int initialCapacity) {        nodeTable = new Hashtable(initialCapacity);    }    public void flush() {        for (Enumeration list = elements(); list.hasMoreElements();)            delete((Node) list.nextElement());    }    public Enumeration elements() {        return nodeTable.elements();    }    public Node add(String label, int index, int shape, int menu, int color) {        Node node = null;        if ((node = get(label)) != null)            return node;        node = new Node(label, index, shape, menu, color);        nodeTable.put(label, (Object) node);        return node;    }    public Node get(int index) {        Enumeration list = nodeTable.elements();        if (list == null)            return null;        while (list.hasMoreElements()) {            Node node = (Node) list.nextElement();            if (node.getIndex() == index) {                return (node);            }        }        return null;    }    public Node get(String label) {        return (Node) nodeTable.get((Object) label);    }    public void del(String label) {        delete(get(label));    }    public void del(int index) {        delete(get(index));    }    public void del(Node node) {        delete(node);    }    // Delete a node from the internal cache    //    private void delete(Node node) {        if (node == null)            return;        nodeTable.remove(node.getLabel());    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?