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

📄 operator_filesize.java

📁 java实现的全文搜索引擎
💻 JAVA
字号:
/**
 * 
 */
package cn.edu.nju.software.ruse;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author spring
 * 
 */

public class Operator_FileSize extends Operator {

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.edu.nju.software.ruse.Operator#getPRI()
	 */
	public Operator_FileSize() {
		desription = "FILESIZE";
		PRI = PRI_FILESIZE;
	}

	public int getPRI() {
		return PRI;
	}

	public HashSet<File> getFileSet(String expre, Index index) {
		//System.err.println("@Operator_FileSize Starting to getFileSet from the index!");
		expre = expre.trim();
		HashMap<Long, HashSet<File>> fileSizeIndex = index.getFileSizeIndex();
		if (expre.charAt(0) != '[' && expre.charAt(0) != '{') {
			/**
			 * case1: fileSize: 520
			 */
			Long l = Long.parseLong(expre);
			if (fileSizeIndex.containsKey(l)) {
				return fileSizeIndex.get(l);
			} else {
				return new HashSet<File>();
			}
		} else {
			/**
			 * case2: fileSize:[] OR modTime:{} OR modTime:[} OR modTime:{]
			 */
			Pattern p = Pattern.compile("\\d+");
			Matcher m = p.matcher(expre);
			ArrayList<Long> fileSize = new ArrayList<Long>();
			HashSet<File> temp = new HashSet<File>();

			int i = -1;
			while (m.find()) {
				i++;
				fileSize.add(i, Long.parseLong(m.group()));
			}

			/**
			 * case2.1: fileSize:[A]
			 */
			if (fileSize.size() == 1) {
				Long l = fileSize.get(0);
				if (fileSizeIndex.containsKey(l)) {
					return fileSizeIndex.get(l);
				} else {
					return new HashSet<File>();
				}
			} else {
				if (expre.charAt(0) == '['
						&& expre.charAt(expre.length() - 1) == ']') {
					Iterator<Long> it = fileSizeIndex.keySet().iterator();
					while (it.hasNext()) {
						Long sizeFromIndex = it.next();
						if (sizeFromIndex.compareTo(fileSize.get(0)) >= 0
								&& sizeFromIndex.compareTo(fileSize.get(1)) <= 0) {
							temp.addAll(fileSizeIndex.get(sizeFromIndex));
						}
					}
					return temp;
				}
				if (expre.charAt(0) == '{'
						&& expre.charAt(expre.length() - 1) == ']') {
					Iterator<Long> it = fileSizeIndex.keySet().iterator();
					while (it.hasNext()) {
						Long sizeFromIndex = it.next();
						if (sizeFromIndex.compareTo(fileSize.get(0)) > 0
								&& sizeFromIndex.compareTo(fileSize.get(1)) <= 0) {
							temp.addAll(fileSizeIndex.get(sizeFromIndex));
						}
					}
					return temp;
				}

				if (expre.charAt(0) == '['
						&& expre.charAt(expre.length() - 1) == '}') {
					Iterator<Long> it = fileSizeIndex.keySet().iterator();
					while (it.hasNext()) {
						Long sizeFromIndex = it.next();
						if (sizeFromIndex.compareTo(fileSize.get(0)) >= 0
								&& sizeFromIndex.compareTo(fileSize.get(1)) < 0) {
							temp.addAll(fileSizeIndex.get(sizeFromIndex));
						}
					}
					return temp;
				} else {
					Iterator<Long> it = fileSizeIndex.keySet().iterator();
					while (it.hasNext()) {
						Long sizeFromIndex = it.next();
						if (sizeFromIndex.compareTo(fileSize.get(0)) > 0
								&& sizeFromIndex.compareTo(fileSize.get(1)) < 0) {
							temp.addAll(fileSizeIndex.get(sizeFromIndex));
						}
					}
					return temp;
				}
			}
		}
	}

}

⌨️ 快捷键说明

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