⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 todisplay.java

📁 CD Manager光盘资料管家婆源代码
💻 JAVA
字号:
package com.galaxyworkstation.model;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TermQuery;

/**
 * 该类模拟了Document对象的显示
 * @author 李奕
 * @version 1.0
 */
public class ToDisplay {

	/**
	 * 默认构造函数
	 */
	public ToDisplay() {}
	
	/**
	 * 得到给定光盘的根目录集合
	 * @param cd 给定的光盘对象
	 * @return 给定光盘的根目录集合
	 */
	public ArrayList<Document> getCDRoots(final CD cd){
		ArrayList<Document> roots = new ArrayList<Document>();
		if(IndexFactory.getCDIndexReader() == null)
			return roots;
		
		IndexSearcher searcher = IndexFactory.getCDIndexSearcher();  
		BooleanQuery query = new BooleanQuery();
	    query.add(new TermQuery(new Term("rootID", cd.getID())), BooleanClause.Occur.MUST );
	    query.add(new TermQuery(new Term("parentID", "0")), BooleanClause.Occur.MUST);
	    Hits hits;
		try {
			hits = searcher. search (query);
			for(int i=0; i<hits.length(); ++i){
				roots.add(hits.doc(i));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return roots;
	}
	
	/**
	 * 得到给定文档的子文档的集合
	 * @param doc 给定的文档对象
	 * @return 给定文档的子文档的集合
	 */
	public ArrayList<Document> getChildren(final Document doc){
		ArrayList<Document> children = new ArrayList<Document>();
		if(IndexFactory.getCDIndexReader() == null)
			return children;
			
		IndexSearcher searcher = IndexFactory.getCDIndexSearcher(); 
		BooleanQuery query = new BooleanQuery();
	    query.add(new TermQuery(new Term("rootID", doc.get("rootID"))), BooleanClause.Occur.MUST );
	    query.add(new TermQuery(new Term("parentID", doc.get("ID"))), BooleanClause.Occur.MUST);
	    Hits hits;
		try {
			hits = searcher. search (query);
			for(int i=0; i<hits.length(); ++i){
				children.add(hits.doc(i));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return children;
	}
	
	/**
	 * 得到给定文档的兄弟文档的集合
	 * @param doc 给定的文档对象
	 * @return 给定文档的兄弟文档的集合
	 */
	public ArrayList<Document> getBrothers(final Document doc){
		ArrayList<Document> brothers = new ArrayList<Document>();
		if(IndexFactory.getCDIndexReader() == null)
			return brothers;
		
		IndexSearcher searcher = IndexFactory.getCDIndexSearcher();  
		BooleanQuery query = new BooleanQuery();
	    query.add(new TermQuery(new Term("rootID", doc.get("rootID"))), BooleanClause.Occur.MUST );
	    query.add(new TermQuery(new Term("parentID", doc.get("parentID"))), BooleanClause.Occur.MUST);
	    Hits hits;
		try {
			hits = searcher. search (query);
			for(int i=0; i<hits.length(); ++i){
				brothers.add(hits.doc(i));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return brothers;
	}
	
	
	/**
	 * 得到给定文档的长辈文档的集合
	 * @param doc 给定的文档对象
	 * @return 给定文档的长辈文档的集合
	 */
	public ArrayList<Document> getSeniors(final Document doc){
		ArrayList<Document> seniors = new ArrayList<Document>();
		if(IndexFactory.getCDIndexReader() == null)
			return seniors;
		
		IndexSearcher searcher = IndexFactory.getCDIndexSearcher();  
		BooleanQuery query = new BooleanQuery();
	    query.add(new TermQuery(new Term("rootID", doc.get("rootID"))), BooleanClause.Occur.MUST );
	    query.add(new TermQuery(new Term("ID", doc.get("parentID"))), BooleanClause.Occur.MUST);
	    Hits hits;
		try {
			hits = searcher. search (query);
			if (hits.length() == 0)
				return seniors;
			return getBrothers(hits.doc(0));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return seniors;
	}
	
	/**
	 * 得到某个只含文件夹类型(不含文件类型)的文档集合
	 * @param docList 该数据为含有文件和文件夹的源文档集合
	 * @return 只含文件夹类型的文档集合
	 */
	public ArrayList<Document> withoutFile(final ArrayList<Document> docList){
		ArrayList<Document> newList = new ArrayList<Document>();
		Document current = null;
		for(int i=0; i<docList.size(); ++i){
			current = docList.get(i);
			if(current.get("isLeaf").equals("f"))
				newList.add(current);
		}
		return newList;
	}
}

⌨️ 快捷键说明

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