OO第三单元总结
Posted 列车员
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OO第三单元总结相关的知识,希望对你有一定的参考价值。
OO第三单元总结
小说两嘴
本单元作业的主要内容是根据给定的JML去实现类及其方法,在规格已经确定的情况下,架构就已经不是那么重要的了,本单元的主要难度在于正确的理解JML的意思,以及在同样的规格之下,写出性能更高的代码。
容器选择
本单元的JML规格中,经常出现了“ID”这个字眼,而且在ID相同的时候,往往我们会抛出各种“EqualID”的异常。所以我们可以感觉到,由ID到对象的关系,在本次作业中,是一一对应的,所以从我的角度来看,这次作业中,涉及到储存对象的容器,HashMap往往都是更好的选择。
但是由于在NetWork的sendMessage方法中,出现了“插到尾部”的需求,所以在实现Person类的时候,我还使用了一个LinkedList,来维护一个队列。
第一次作业
为了简化UML图,让视图看起来更加清晰,本单元总结中UML图中将不包含异常类。
UML图
复杂度分析
方法 | CogC | ev(G) | iv(G) | v(G) |
---|---|---|---|---|
com.oocourse.spec1.Union.Union() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.Union.tryMerge(int,int) | 1.0 | 1.0 | 1.0 | 2.0 |
com.oocourse.spec1.Union.insert(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.Union.getUnionCount() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.Union.findFa(int) | 6.0 | 5.0 | 3.0 | 5.0 |
com.oocourse.spec1.MyPerson.queryValue(Person) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec1.MyPerson.MyPerson(int,String,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyPerson.isLinked(Person) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec1.MyPerson.getName() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyPerson.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyPerson.getAge() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyPerson.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec1.MyPerson.compareTo(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyPerson.addRelation(Person,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyNetwork.queryValue(int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec1.MyNetwork.queryPeopleSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyNetwork.queryNameRank(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec1.MyNetwork.queryBlockSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyNetwork.MyNetwork() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyNetwork.isCircle(int,int) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec1.MyNetwork.getPerson(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyNetwork.contains(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.MyNetwork.compareName(int,int) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec1.MyNetwork.addRelation(int,int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec1.MyNetwork.addPerson(Person) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec1.Main.main(String[]) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.DTreeNode.queryNameBefore(String) | 7.0 | 3.0 | 5.0 | 6.0 |
com.oocourse.spec1.DTreeNode.getNodeCount() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.DTreeNode.DTreeNode() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec1.DTreeNode.addName(String) | 3.0 | 1.0 | 3.0 | 3.0 |
Total | 38.0 | 54.0 | 40.0 | 60.0 |
Average | 1.2666666666666666 | 1.8 | 1.3333333333333333 | 2.0 |
可以看到,在基于规格实现的情况下,类的复杂度都得到了较好的控制。
对于本次作业的"queryNameBefore"方法,为了优化时间复杂度,我写了一棵字典树来对姓名进行维护,在已有的数据限制下,字典树的深度将很小,私以为在本次作业的前提下,字典树是一种比平衡树更优的实现方法。需要注意的是使用字典树来进行查询,应当小心“子串”,没有被统计到的情况。
对于本次作业的“isCircle”方法,我维护了一个并查集,来检测两个Person之间是否连通,并采用路径压缩和按秩合并的优化,控制了这一方法的时间复杂度。同时为了防止递归访问爆栈,我对findFa这一方法进行了非递归改造,这可能也是其圈复杂度上升的一个原因,但我认为这样的改造是河狸的。
BUG
本次作业互测中,仍然使用O(n)算法去查询完成名字查询的同学,都被扬了。
第二次作业
UML图
复杂度分析
方法 | CogC | ev(G) | iv(G) | v(G) |
---|---|---|---|---|
com.oocourse.spec2.Union.Union() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.Union.tryMerge(int,int) | 1.0 | 1.0 | 1.0 | 2.0 |
com.oocourse.spec2.Union.insert(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.Union.getUnionCount() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.Union.findFa(int) | 6.0 | 5.0 | 3.0 | 5.0 |
com.oocourse.spec2.MyPerson.rmNowGroup(Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.receiveMes(Message) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.queryValue(Person) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec2.MyPerson.MyPerson(int,String,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.isLinked(Person) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec2.MyPerson.inGroup(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.getSocialValue() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.getReceivedMessages() | 4.0 | 2.0 | 3.0 | 3.0 |
com.oocourse.spec2.MyPerson.getName() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.getMessages() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.getAge() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec2.MyPerson.compareTo(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.addSocialValue(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.addRelation(Person,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyPerson.addRelAllSameGroup(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec2.MyPerson.addNowGroup(Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.sendMessage(int) | 7.0 | 4.0 | 7.0 | 8.0 |
com.oocourse.spec2.MyNetwork.queryValue(int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec2.MyNetwork.querySocialValue(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryReceivedMessages(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryPeopleSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.queryNameRank(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryGroupValueSum(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryGroupSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.queryGroupPeopleSum(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryGroupAgeVar(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryGroupAgeMean(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyNetwork.queryBlockSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.MyNetwork() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.isCircle(int,int) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec2.MyNetwork.getPerson(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.getMessage(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.getGroup(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.delFromGroup(int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec2.MyNetwork.containsMessage(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.contains(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyNetwork.compareName(int,int) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec2.MyNetwork.addToGroup(int,int) | 4.0 | 5.0 | 1.0 | 5.0 |
com.oocourse.spec2.MyNetwork.addRelation(int,int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec2.MyNetwork.addPerson(Person) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec2.MyNetwork.addMessage(Message) | 3.0 | 3.0 | 4.0 | 4.0 |
com.oocourse.spec2.MyNetwork.addGroup(Group) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec2.MyMessage.MyMessage(int,int,Person,Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.MyMessage(int,int,Person,Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.getType() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.getSocialValue() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.getPerson2() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.getPerson1() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.getGroup() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyMessage.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec2.MyGroup.updateValSum(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec2.MyGroup.updatePowerSum(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.updateAgeVar() | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyGroup.updateAgeMean(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.MyGroup(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.hasPerson(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.getValueSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.getSize() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.getAgeVar() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.getAgeMean() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec2.MyGroup.deupdateValSum(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec2.MyGroup.deupdatePowerSum(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.deupdateAgeMean(Person) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec2.MyGroup.delPerson(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.allPerAddSocVal(int) | 1.0 | 1.0 | 2.0 | 2.0 |
com.oocourse.spec2.MyGroup.addPerson(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.MyGroup.addGroRelation(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.Main.main(String[]) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.DTreeNode.queryNameBefore(String) | 7.0 | 3.0 | 5.0 | 6.0 |
com.oocourse.spec2.DTreeNode.getNodeCount() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.DTreeNode.DTreeNode() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec2.DTreeNode.addName(String) | 3.0 | 1.0 | 3.0 | 3.0 |
Total | 87.0 | 134.0 | 111.0 | 153.0 |
Average | 1.0609756097560976 | 1.6341463414634145 | 1.353658536585366 | 1.8658536585365855 |
本次作业新增了Group类和Message类,对于Group类,我们可能会经常的去查询它的一些属性,所以我使用了缓存的机制,在Group类中维护了几个和这些属性有关的变量,在每次新加入人或者关系的时候更新,每次查询的时候直接返回结果果,而不是每次额外再进行一次运算。
BUG
由于漏看了规格中对于组人数上限的限制,我误入C房,翻看同学代码,发现仍有同学使用O(n^2)的算法去计算组内边权合,都给扬了。
第三次作业
UML图
复杂度分析
方法 | CogC | ev(G) | iv(G) | v(G) |
---|---|---|---|---|
com.oocourse.spec3.DjPath.dj(HashMap<Integer, Person>,Person,Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DjPath.init(HashMap<Integer, Person>) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec3.DjPath.PerWrap.compareTo(Object) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DjPath.PerWrap.equals(Object) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec3.DjPath.PerWrap.getDis() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DjPath.PerWrap.getPerson() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DjPath.PerWrap.hashCode() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DjPath.PerWrap.PerWrap(Person,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DjPath.print() | 2.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec3.DjPath.process() | 5.0 | 4.0 | 3.0 | 4.0 |
com.oocourse.spec3.DjPath.update(PerWrap) | 4.0 | 1.0 | 4.0 | 4.0 |
com.oocourse.spec3.DTreeNode.addName(String) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec3.DTreeNode.DTreeNode() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DTreeNode.getNodeCount() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.DTreeNode.queryNameBefore(String) | 7.0 | 3.0 | 5.0 | 6.0 |
com.oocourse.spec3.Main.main(String[]) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyEmojiMessage.getEmojiId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyEmojiMessage.MyEmojiMessage(int,int,Person,Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyEmojiMessage.MyEmojiMessage(int,int,Person,Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.addGroRelation(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.addPerson(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.allPerAddSocVal(int) | 1.0 | 1.0 | 2.0 | 2.0 |
com.oocourse.spec3.MyGroup.delPerson(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.deupdateAgeMean(Person) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyGroup.deupdatePowerSum(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.deupdateValSum(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec3.MyGroup.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec3.MyGroup.getAgeMean() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.getAgeVar() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.getSize() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.getValueSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.giveMoneyG(Person,int) | 1.0 | 1.0 | 2.0 | 2.0 |
com.oocourse.spec3.MyGroup.hasPerson(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.MyGroup(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.updateAgeMean(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.updateAgeVar() | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyGroup.updatePowerSum(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyGroup.updateValSum(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec3.MyMessage.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec3.MyMessage.getGroup() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.getPerson1() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.getPerson2() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.getSocialValue() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.getType() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.MyMessage(int,int,Person,Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyMessage.MyMessage(int,int,Person,Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.addGroup(Group) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec3.MyNetwork.addMessage(Message) | 5.0 | 4.0 | 6.0 | 6.0 |
com.oocourse.spec3.MyNetwork.addPerson(Person) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec3.MyNetwork.addRelation(int,int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec3.MyNetwork.addToGroup(int,int) | 4.0 | 5.0 | 1.0 | 5.0 |
com.oocourse.spec3.MyNetwork.compareName(int,int) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec3.MyNetwork.contains(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.containsEmojiId(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.containsMessage(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.deleteColdEmoji(int) | 13.0 | 1.0 | 7.0 | 7.0 |
com.oocourse.spec3.MyNetwork.delFromGroup(int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec3.MyNetwork.getGroup(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.getMessage(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.getPerson(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.isCircle(int,int) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec3.MyNetwork.MyNetwork() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.queryBlockSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.queryGroupAgeMean(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryGroupAgeVar(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryGroupPeopleSum(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryGroupSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.queryGroupValueSum(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryMoney(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryNameRank(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryPeopleSum() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNetwork.queryPopularity(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryReceivedMessages(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.querySocialValue(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNetwork.queryValue(int,int) | 3.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec3.MyNetwork.sendIndirectMessage(int) | 7.0 | 3.0 | 5.0 | 8.0 |
com.oocourse.spec3.MyNetwork.sendMessage(int) | 15.0 | 4.0 | 11.0 | 12.0 |
com.oocourse.spec3.MyNetwork.storeEmojiId(int) | 1.0 | 2.0 | 1.0 | 2.0 |
com.oocourse.spec3.MyNoticeMessage.getString() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNoticeMessage.MyNoticeMessage(int,String,Person,Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyNoticeMessage.MyNoticeMessage(int,String,Person,Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.addMoney(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.addNowGroup(Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.addRelAllSameGroup(Person) | 3.0 | 1.0 | 3.0 | 3.0 |
com.oocourse.spec3.MyPerson.addRelation(Person,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.addSocialValue(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.compareTo(Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.equals(Object) | 4.0 | 4.0 | 1.0 | 4.0 |
com.oocourse.spec3.MyPerson.getAge() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.getId() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.getMessages() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.getMoney() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.getName() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.getPerLinkItr() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.getReceivedMessages() | 4.0 | 2.0 | 3.0 | 3.0 |
com.oocourse.spec3.MyPerson.getSocialValue() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.inGroup(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.isLinked(Person) | 2.0 | 3.0 | 1.0 | 3.0 |
com.oocourse.spec3.MyPerson.MyPerson(int,String,int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.queryValue(Person) | 2.0 | 2.0 | 2.0 | 2.0 |
com.oocourse.spec3.MyPerson.receiveMes(Message) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyPerson.rmNowGroup(Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyRedEnvelopeMessage.getMoney() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyRedEnvelopeMessage.MyRedEnvelopeMessage(int,int,Person,Group) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.MyRedEnvelopeMessage.MyRedEnvelopeMessage(int,int,Person,Person) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.Union.findFa(int) | 6.0 | 5.0 | 3.0 | 5.0 |
com.oocourse.spec3.Union.getUnionCount() | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.Union.insert(int) | 0.0 | 1.0 | 1.0 | 1.0 |
com.oocourse.spec3.Union.tryMerge(int,int) | 1.0 | 1.0 | 1.0 | 2.0 |
com.oocourse.spec3.Union.Union() | 0.0 | 1.0 | 1.0 | 1.0 |
Total | 137.0 | 175.0 | 167.0 | 218.0 |
Average | 1.2232142857142858 | 1.5625 | 1.4910714285714286 | 1.9464285714285714 |
可以看到,方法的复杂度,基本与规格描述的复杂程度成正比,sendMessage现在要进行对应的消息类的判断,所以一定需要增加分支复杂度。
对于这个问题,我们可能可以采用多态的方式来进行解决,在MyMessage父类中增加send方法,并将Network中的元素传入来供Message进行操作,并在各个新的消息类中,重写这个方法,去执行对应的操作。但我认为这样对Message类暴露了Network的细节,所以没有采用这种方法。
对于本次作业中,查询人到人的最短路的时候,我使用的是堆优化的迪杰特斯拉算法(荣老师语:) ),将查询一次的复杂度,控制在了O(nlogn),让代码总体有一定的效率。
剩下的内容相比第二次作业就没有太大的变化了。
BUG
这次房间里的人各个都是人才,说话又好听,就是一个bug都没有(
最后的想法
这个单元主要的任务是培养同学们的“规格化”的编程能力,通过阅读规格,实现规格的过程,尝试去感受优秀的架构的模样,但是比较可惜的是,实际使用过程中,我们更多的看到的是JML写法的臃肿,它确实做到了严谨,但是如果作为信息传达的手段,面对更加复杂的需求和功能,就略微显得有些低效了。可能我们更需要的是培养如何去进行这样规格化的,健壮的编程,而不是去拘泥于JML的编写。不过JML作为传达这种思想的媒介,我认为它已经合格了。
以上是关于OO第三单元总结的主要内容,如果未能解决你的问题,请参考以下文章