📄 catalog.java
字号:
package net.tinyos.tinydb;import java.io.*;import java.util.*;/** Catalog manages a list of attributes that are available to TinyDB queries. Currently this class just reads attributes from a text file, but future versions should support dynamically building attribute lists from nearby motes. @author Sam Madden*/public class Catalog { /** A static variable containing the current (global) catalog */ public static Catalog curCatalog; private String fileName; /** Constructor : create an empty catalog */ public Catalog() { attrs = new Vector(); fileName = null; } /** Read a catalog from the specified file */ public Catalog(String catalogFile) { this(); fileName = catalogFile; try { BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(new File(catalogFile)))); String line; while ((line = r.readLine()) != null) { if (line.trim().charAt(0) != '#' && line.trim().length() > 0) addAttr(new QueryField(line, QueryField.INTTWO)); } r.close(); } catch (IOException e) { System.out.println("Couldn't open catalog file : " + catalogFile); } } public int numAttrs() { return attrs.size(); } public QueryField getAttr(int idx) { return (QueryField)attrs.elementAt(idx); } public QueryField getAttr(String name) { Enumeration e = attrs.elements(); while (e.hasMoreElements()) { QueryField qf = (QueryField)e.nextElement(); if (qf.getName().equalsIgnoreCase(name)) return qf; } return null; } public void addAttr(QueryField f, boolean log) { attrs.addElement(f); if (fileName != null && log) { try { FileWriter fw = new FileWriter(fileName, true); fw.write(f.getName() + "\n"); fw.close(); } catch (IOException e) { } } Enumeration e = listeners.elements(); while (e.hasMoreElements()) { CatalogListener cl = (CatalogListener)e.nextElement(); cl.addedAttr(f); } } public void addAttr(QueryField f) { addAttr(f,false); } public void addListener(CatalogListener cl) { listeners.addElement(cl); } public static void main(String[] argv) { Catalog c = new Catalog("catalog"); QueryField f = new QueryField("test",(byte)0); c.addAttr(f,true); } private Vector attrs; private Vector listeners = new Vector();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -