parent
1990441707
commit
0cf189d904
Binary file not shown.
@ -1,21 +1,23 @@
|
||||
public class LanguageSwitch {
|
||||
//等级转中文输出
|
||||
public static String levelToChinese(Login.Level l) {
|
||||
return switch (l) {
|
||||
case PRIMARY -> "小学";
|
||||
case MIDDLE -> "初中";
|
||||
case HIGH -> "高中";
|
||||
//default -> "未知";
|
||||
};
|
||||
}
|
||||
//等级中文输入转level
|
||||
public static Login.Level chineseToLevel(String s) {
|
||||
s = s.trim();//去除前后空格
|
||||
return switch (s) {
|
||||
case "小学" -> Login.Level.PRIMARY;
|
||||
case "初中" -> Login.Level.MIDDLE;
|
||||
case "高中" -> Login.Level.HIGH;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
//等级转中文输出
|
||||
public static String levelToChinese(Login.Level l) {
|
||||
return switch (l) {
|
||||
case PRIMARY -> "小学";
|
||||
case MIDDLE -> "初中";
|
||||
case HIGH -> "高中";
|
||||
//default -> "未知";
|
||||
};
|
||||
}
|
||||
|
||||
//等级中文输入转level
|
||||
public static Login.Level chineseToLevel(String s) {
|
||||
s = s.trim();//去除前后空格
|
||||
return switch (s) {
|
||||
case "小学" -> Login.Level.PRIMARY;
|
||||
case "初中" -> Login.Level.MIDDLE;
|
||||
case "高中" -> Login.Level.HIGH;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,49 +1,68 @@
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LoadFile {
|
||||
// 读取该用户文件夹下已有题目的所有题目文本
|
||||
public static List<String> loadExistingQuestions(String username) {
|
||||
List<String> all = new ArrayList<>();
|
||||
Path userDir = Paths.get("data", username);
|
||||
if (!Files.exists(userDir)) return all;
|
||||
try {
|
||||
DirectoryStream<Path> ds = Files.newDirectoryStream(userDir, "*.txt");
|
||||
for (Path p : ds) {
|
||||
List<String> lines = Files.readAllLines(p, StandardCharsets.UTF_8);
|
||||
// 将文件中按题号拆分题目
|
||||
StringBuilder cur = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
//识别题号
|
||||
if (line.matches("^\\s*\\d+\\..*")) {
|
||||
// 新题开始 保存旧题
|
||||
if (!cur.isEmpty()) {
|
||||
all.add(cur.toString().trim());
|
||||
}
|
||||
cur.setLength(0);
|
||||
//去题号
|
||||
cur.append(line.replaceFirst("^\\s*\\d+\\.", "").trim());
|
||||
} else {
|
||||
// 继续当前题(空行也可能出现)
|
||||
if (line.trim().isEmpty()) {
|
||||
if (!cur.isEmpty()) {
|
||||
all.add(cur.toString().trim());
|
||||
cur.setLength(0);
|
||||
}
|
||||
} else {
|
||||
if (!cur.isEmpty()) cur.append(" ");
|
||||
cur.append(line.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cur.isEmpty()) all.add(cur.toString().trim());
|
||||
|
||||
/**
|
||||
* 读取该用户文件夹下已有题目的所有题目文本。
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 已存在的所有题目列表
|
||||
*/
|
||||
// 读取该用户文件夹下已有题目的所有题目文本
|
||||
public static List<String> loadExistingQuestions(String username) {
|
||||
List<String> all = new ArrayList<>();
|
||||
Path userDir = Paths.get("data", username);
|
||||
if (!Files.exists(userDir)) {
|
||||
return all;
|
||||
}
|
||||
try {
|
||||
DirectoryStream<Path> ds = Files.newDirectoryStream(userDir, "*.txt");
|
||||
for (Path p : ds) {
|
||||
List<String> lines = Files.readAllLines(p, StandardCharsets.UTF_8);
|
||||
// 将文件中按题号拆分题目
|
||||
StringBuilder cur = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
//识别题号
|
||||
if (line.matches("^\\s*\\d+\\..*")) {
|
||||
// 新题开始 保存旧题
|
||||
if (!cur.isEmpty()) {
|
||||
all.add(cur.toString().trim());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore, return what we have
|
||||
cur.setLength(0);
|
||||
//去题号
|
||||
cur.append(line.replaceFirst("^\\s*\\d+\\.", "").trim());
|
||||
} else {
|
||||
// 继续当前题(空行也可能出现)
|
||||
if (line.trim().isEmpty()) {
|
||||
if (!cur.isEmpty()) {
|
||||
all.add(cur.toString().trim());
|
||||
cur.setLength(0);
|
||||
}
|
||||
} else {
|
||||
if (!cur.isEmpty()) {
|
||||
cur.append(" ");
|
||||
}
|
||||
cur.append(line.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cur.isEmpty()) {
|
||||
all.add(cur.toString().trim());
|
||||
}
|
||||
// 转链式 去空格 去空字符串 去重 转回list
|
||||
return all.stream().map(String::trim).filter(s->!s.isEmpty()).distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("读取题目文件失败:" + e.getMessage());
|
||||
}
|
||||
// 转链式 去空格 去空字符串 去重 转回list
|
||||
return all.stream().map(String::trim).filter(s -> !s.isEmpty()).distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue