PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | ||
· Estimate | · 估计这个任务需要多少时间 | 15 | 20 |
Development | 开发 | ||
· Analysis | · 需求分析 (包括学习新技术) | 60 | 90 |
· Design Spec | · 生成设计文档 | 20 | 30 |
· Design Review | · 设计复审 | 30 | 60 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 5 | 5 |
· Design | · 具体设计 | 30 | 30 |
· Coding | · 具体编码 | 180 | 350 |
· Code Review | · 代码复审 | 30 | 40 |
· Test | · 测试(自我测试,修改代码,提交修改) | 30 | 90 |
Reporting | 报告 | ||
· Test Repor | · 测试报告 | 30 | 50 |
· Size Measurement | · 计算工作量 | 20 | 30 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 30 | 60 |
合计 | 480 | 855 |
刚拿到题目的第一反应是利用正则表达式进行词频统计。 通过正则表达式进行匹配,同时正则表达式匹配空白行,正则表达式匹配ASCII字符。
整个过程的思路是这样子:
CalMost: 对词频进行排序,返回最多的前10个
CharsCount: 完成对字符个数的统计
LinesCount: 完成对行数的统计
WordsCount: 对单词个数进行统计,同时生成Map
/**
* @param map the HashMap contain words and amount
* @return the top 10 amount of the words and amount in list
*/
public List<Map.Entry<String, Integer>> mostWords(HashMap<String, Integer> map)
利用VisualVM进行性能分析,以下是执行100000次的结果
可以看出主要耗时还是载输出到文件这里。后续再想办法看看有没有优化的空间。最近时间不够用了
/**
* @param map the HashMap contain words and amount
* @return the top 10 amount of the words and amount in list
*/
public List<Map.Entry<String, Integer>> mostWords(HashMap<String, Integer> map) {
// convert HashMap to list
List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
// sort by value then by key
list.sort(new MapComparator());
return list.size() < 10 ? list.subList(0, list.size()) : list.subList(0, 10);
}
/**
* This class define how to compare the element in list
*/
private class MapComparator implements Comparator<Map.Entry<String, Integer>> {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o1.getValue().compareTo(o2.getValue()) != 0 ? o2.getValue().compareTo(o1.getValue()) : o1.getKey().compareTo(o2.getKey());
}
}
/**
* @param content the input
*/
public WordsCount(String content) {
String[] temp = content.split("\\s+");
String countRegex = "^[a-zA-Z]{4,}.*";
for (String i : temp) {
if (i.matches(countRegex)) {
sum++;
String lowCase = i.toLowerCase();
if (!map.containsKey(lowCase)) {
map.put(lowCase, 1);
} else {
int num = map.get(lowCase);
map.put(lowCase, num + 1);
}
}
}
}
覆盖率应该算还行吧,每个方法都有覆盖到。
LinesCount中有个catch中的没有覆盖到。
这次看了一些测试相关的东西,之前自己写东西都没有用过单元测试,或者就自己直接print出来,测试几个是否跟自己的预期符合。没有过写单元测试的经历。
通过这次,了解了单元测试的有点,当项目较大时,通过测试更能提前发现问题。
完成作业所花的时间跟自己的预期差距也是比较大的。一开始觉得自己一直都陆陆续续有在写Android,做这个应该不会很花时间。后面才发现...Android...Java差别还是有的,主要原因还是自己对Java的掌握还是不够深。接下来以还是要花些时间加深对Java的掌握。
本次作业完成的质量,个人并不是很满意,因为手头上同时还有不少代码要写希望赶紧写完,好累好累,所以时间精力并没有充分投入,希望下一次作业能让自己比较满意。
原文:https://www.cnblogs.com/darkexisted/p/9631732.html