📄 dictionaryfactory.java
字号:
package entity;
import java.io.IOException;
import operation.LineAnalysis;
import file.ReadFile;
//字典工厂
public class DictionaryFactory {
public DictionaryFactory() {
}
// 判断是否字母
private boolean isChar(char c) {
int temp = (int) c; // 把char转为ASCII码
if (temp < 97) { // 少于'a'的字符加32 以便与小写字母对比
temp = temp + 32;
}
if (temp >= 97 && temp <= 122) { // 判断是否大写字母
return true;
} else {
return false;
}
}
// 根据给定的路径创建字典 文件读失败抛出IOException
// pathname 字典文件的路径
public Dictionary createDictionary(String pathname) throws IOException {
ReadFile readFile = new ReadFile(pathname); // 读文件类
String s;
s = readFile.read();
if (!isChar(s.charAt(s.length() - 1))) { // 当最后字符不为字母时转换为空格
s = s.substring(0, s.length() - 2) + ' ';
}
LineAnalysis lineAnalysis = new LineAnalysis(s); // 把读出内容给LineAnalysis分析
Dictionary dictionary = new Dictionary(lineAnalysis.getLines(),
lineAnalysis.getLineAmount()); // 分析后的行建立字典
return dictionary;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -