Java实现wc基本和拓展功能
Github地址 https://github.com/wean2016/wc
遇到的困难及解决方法
- 困难描述 : 没做过这种命令行带参数的程序,不知道怎么处理参数
- 做过哪些尝试 : 问宿友
- 是否解决 : 是
- 有何收获 : 宿友真厉害
关键代码or设计说明
贴出你认为的关键代码或者设计图,并进行解释
【注意】不得贴项目无关代码,一经发现,算抄袭。
private static Map<String, String> getTexts(File file, Pattern pattern) {
Map<String, String> texts = new HashMap<>();
if (file.isDirectory()){
texts = Arrays.stream(file.list())
.filter(s -> !new File(file.getAbsolutePath() + "\\" + s).isDirectory())
.filter(s -> pattern.matcher(s).matches())
.collect(toMap(s -> file.getAbsolutePath() + "\\" + s, s -> {
String text = ReadToString.readToString(file.getAbsolutePath() + "\\" + s);
return text == null ? "" : text;
}));
Arrays.stream(file.list())
.filter(s -> new File(file.getAbsolutePath() + "\\" + s).isDirectory())
.map(s -> new File(file.getAbsolutePath() + "\\" + s))
.map(file1 -> getTexts(file1, pattern))
.forEach(texts::putAll);
}
return texts;
}
- 递归获取指定文件夹下所有文件的内容 (-s 功能)
texts.forEach((name, text) -> {
System.out.println(name);
Arrays.asList(args).subList(0, args.length-1).parallelStream().forEach(s -> {
switch (s){
case "-c" : Count.count(text); break;
case "-w" : Word.word(text); break;
case "-l" : Line.line(text); break;
case "-a" : Complex.complex(text); break;
default: break;
}
});
});
-
处理各个文件,并行处理各个参数(忽略最后一个参数, 即忽略文件名)
PSP
- 实现之前先在PSP中预估时间
- 实施后各个环节实际花费多少时间也请做记录
- 表中有一项: Estimate 指的“预估”这个活动,“预估时间”也是一项任务。
- 例如:我估计自己需要花30分钟来估算出整个项目需要多少时间完成,结果我花了20分钟估算出整个项目需要6个小时完成。Estimate这一项应该在“预估耗时”填写30分钟,实际耗时填写“20”分钟。
- 一级和二级活动的包含关系:
- Planning 这个一级活动包含了1个二级活动(Estimate)
- Development 这个一级活动包含了8个二级活动
- Reporting 这个一级活动包含了3个二级活动
- 大家在记录时间的时候, 只用记录二级活动, 然后把总数加了, 就是相应的一级活动的时间
- 这个时间的长短并不会对分数有直接影响,这是为了大家自己总结。
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
Planning |
计划 |
5 |
5 |
· Estimate |
· 估计这个任务需要多少时间 |
5 |
5 |
Development |
开发 |
365 |
120 |
· Analysis |
· 需求分析 (包括学习新技术) |
120 |
10 |
· Design Spec |
· 生成设计文档 |
5 |
0 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
10 |
0 |
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
5 |
0 |
· Design |
· 具体设计 |
5 |
0 |
· Coding |
· 具体编码 |
250 |
90 |
· Code Review |
· 代码复审 |
10 |
10 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
60 |
20 |
Reporting |
报告 |
30 |
|
· Test Report |
· 测试报告 |
15 |
10 |
· Size Measurement |
· 计算工作量 |
5 |
5 |
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
10 |
15 |
合计 |
405 |
155 |
记录自己的学习进度条(每周追加)
第N周 | 新增代码(行) | 累计代码(行) | 本周学习耗时(小时) | 累计学习耗时(小时) | 重要成长 |
---|---|---|---|---|---|
1 | 250 | 250 | 1 | 1 | 了解了软件的构建过程 |
测试结果
参数
结果