?? 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轉(zhuǎn)為ASCII碼
if (temp < 97) { // 少于'a'的字符加32 以便與小寫字母對比
temp = temp + 32;
}
if (temp >= 97 && temp <= 122) { // 判斷是否大寫字母
return true;
} else {
return false;
}
}
// 根據(jù)給定的路徑創(chuàng)建字典 文件讀失敗拋出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))) { // 當最后字符不為字母時轉(zhuǎn)換為空格
s = s.substring(0, s.length() - 2) + ' ';
}
LineAnalysis lineAnalysis = new LineAnalysis(s); // 把讀出內(nèi)容給LineAnalysis分析
Dictionary dictionary = new Dictionary(lineAnalysis.getLines(),
lineAnalysis.getLineAmount()); // 分析后的行建立字典
return dictionary;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -