📄 tester.java
字号:
package cn.edu.nju.software.ruse;
import invertedList.FileRecord;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import main.RUSE;
/**
* A facade for testing your RUSE. Change the implementation of the
* two methods to adapt your version of RUSE.
*
*/
public class Tester {
public static RUSE engine = new RUSE();
/**
* Entrance to the indexing functionality.
*
* @param dataDir
* the root directory of the files
* @param indexDir
* the directory to place your index data
*/
public static void index(File dataDir, File indexDir) {
engine.indexFile(dataDir, indexDir);
}
/**
* Entrance to the search functionality.
*
* @param indexDir
* the index directory
* @param query
* the query
* @param order
* 0: no order; 1: ordered by file size; 2: ordered by last modified time
* @return a list containing the results that match the query
*/
public static List<Result> search(File indexDir, String query, int order) {
engine.loadIndexFile(indexDir);
List<FileRecord> records = null;
List<Result> result = new ArrayList<Result>();
switch(order){
case 0:
records = engine.getResult(query);
break;
case 1:
records = engine.getResultBySize(query);
break;
case 2:
records = engine.getResultByTime(query);
break;
}
Iterator<FileRecord> iter = records.iterator();
while(iter.hasNext()){
Result currentResult = new Result();
FileRecord currentRecord = iter.next();
currentResult.fileSize = (int)currentRecord.getSize();
currentResult.fileName = currentRecord.getName();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
currentResult.modTime = formatter.format(new Date(currentRecord.getLastModified()));
result.add(currentResult);
}
return result;
}
public static class Result {
public int fileSize;
public String fileName, modTime;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -