📄 cmdlineoutput.java
字号:
package net.tinyos.tinydb;import net.tinyos.tinydb.parser.*;import java.util.*;/** CmdLineOutput runs queries and displays results on the command line. @author Sam Madden (madden@cs.berkeley.edu)*/public class CmdLineOutput implements ResultListener { /** Constructor -- runs the specified query using the provided network interface. @param nw A network interface for talking with the basestation / parsing results. @param queryString the query to run. */ public CmdLineOutput(TinyDBNetwork nw, String queryString) { try { //parse the query TinyDBQuery q = SensorQueryer.translateQuery(queryString, (byte)1); Vector headings = q.getColumnHeadings(); //fetch the names of the fields in the result this.q = q; TinyDBMain.notifyAddedQuery(q); // add query to list of known queries nw.addResultListener(this, true, 1); // set ourselves up to receives results for query id 1 System.out.print("|"); for (int i = 0; i < headings.size(); i++) { System.out.print("\t" + headings.elementAt(i) + "\t|"); } System.out.println("\n-----------------------------------------------------"); nw.sendQuery(q); //inject the query } catch (ParseException e) { System.err.println("Invalid query : " + queryString + "(" + e + ")"); } catch (java.io.IOException e) { System.err.println("Network error: " + e); } } /** ResultListener method that is called whenever a query result arrives for us This method just prints each result out on the command line. @param qr A query result that just arrived */ public void addResult(QueryResult qr) { Vector v = qr.resultVector(); for (int i = 0; i < v.size(); i++) { System.out.print("\t" + v.elementAt(i) + "\t|"); } System.out.println(); } private TinyDBQuery q;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -