@Test public void testCompareToMethod(){ try{ Assert.assertEquals(1, classPair.compareTo(null)); fail("NullPointerException was expected!"); }catch (NullPointerException npe){ } ClassPair classPair2 = new ClassPair(class1,class2,0, 0); Assert.assertTrue( classPair.compareTo(classPair2) > 0); classPair2 = new ClassPair(class1,class2,10, 10); Assert.assertTrue( classPair.compareTo(classPair2) < 0); classPair2 = newClassPair(); Assert.assertTrue( classPair.compareTo(classPair2) == 0); classPair2 = new ClassPair(class1,class2,10, 0); Assert.assertTrue( classPair.compareTo(classPair2) == 0); }
@Override public int compareTo(ClassPair otherPair) { List<Integer> ownObjectives = this.getListOfObjectivesValue(); List<Integer> otherObjectives = otherPair.getListOfObjectivesValue(); int value = 0; for (int i =0 ; i<ownObjectives.size(); i++){ int ownValue = ownObjectives.get(i); int otherValue = otherObjectives.get(i); if(i==0){ value = Integer.compare(ownValue,otherValue); }else{ int tempValue = Integer.compare(ownValue,otherValue); int mult = value * tempValue; if(mult < 0){ return 0; }else if (mult == 0){ if(value == 0){ value = tempValue; } continue; }else{ continue; } } } return value; }
ClassPair implements Comparable<ClassPair> { @Override public int compareTo(ClassPair otherPair) { List<Integer> ownObjectives = this.getListOfObjectivesValue(); List<Integer> otherObjectives = otherPair.getListOfObjectivesValue(); int value = 0; for (int i =0 ; i<ownObjectives.size(); i++){ int ownValue = ownObjectives.get(i); int otherValue = otherObjectives.get(i); if(i==0){ value = Integer.compare(ownValue,otherValue); }else{ int tempValue = Integer.compare(ownValue,otherValue); int mult = value * tempValue; if(mult < 0){ return 0; }else if (mult == 0){ if(value == 0){ value = tempValue; } continue; }else{ continue; } } } return value; } }
ClassPair implements Comparable<ClassPair> { @Override public int compareTo(ClassPair otherPair) { List<Integer> ownObjectives = this.getListOfObjectivesValue(); List<Integer> otherObjectives = otherPair.getListOfObjectivesValue(); int value = 0; for (int i =0 ; i<ownObjectives.size(); i++){ int ownValue = ownObjectives.get(i); int otherValue = otherObjectives.get(i); if(i==0){ value = Integer.compare(ownValue,otherValue); }else{ int tempValue = Integer.compare(ownValue,otherValue); int mult = value * tempValue; if(mult < 0){ return 0; }else if (mult == 0){ if(value == 0){ value = tempValue; } continue; }else{ continue; } } } return value; } ClassPair(String class1, String class2, int score1, int score2); }
ClassPair implements Comparable<ClassPair> { @Override public int compareTo(ClassPair otherPair) { List<Integer> ownObjectives = this.getListOfObjectivesValue(); List<Integer> otherObjectives = otherPair.getListOfObjectivesValue(); int value = 0; for (int i =0 ; i<ownObjectives.size(); i++){ int ownValue = ownObjectives.get(i); int otherValue = otherObjectives.get(i); if(i==0){ value = Integer.compare(ownValue,otherValue); }else{ int tempValue = Integer.compare(ownValue,otherValue); int mult = value * tempValue; if(mult < 0){ return 0; }else if (mult == 0){ if(value == 0){ value = tempValue; } continue; }else{ continue; } } } return value; } ClassPair(String class1, String class2, int score1, int score2); @Override boolean equals(Object obj); @Override int compareTo(ClassPair otherPair); String getClass1(); String getClass2(); int getCallScore1(); int getCallScore2(); int getTotalScore(); int getNumberOfBranchesInClass1(); int getNumberOfBranchesInClass2(); void addTonumberOfBranches(String className, int value); List<Integer> getListOfObjectivesValue(); }
ClassPair implements Comparable<ClassPair> { @Override public int compareTo(ClassPair otherPair) { List<Integer> ownObjectives = this.getListOfObjectivesValue(); List<Integer> otherObjectives = otherPair.getListOfObjectivesValue(); int value = 0; for (int i =0 ; i<ownObjectives.size(); i++){ int ownValue = ownObjectives.get(i); int otherValue = otherObjectives.get(i); if(i==0){ value = Integer.compare(ownValue,otherValue); }else{ int tempValue = Integer.compare(ownValue,otherValue); int mult = value * tempValue; if(mult < 0){ return 0; }else if (mult == 0){ if(value == 0){ value = tempValue; } continue; }else{ continue; } } } return value; } ClassPair(String class1, String class2, int score1, int score2); @Override boolean equals(Object obj); @Override int compareTo(ClassPair otherPair); String getClass1(); String getClass2(); int getCallScore1(); int getCallScore2(); int getTotalScore(); int getNumberOfBranchesInClass1(); int getNumberOfBranchesInClass2(); void addTonumberOfBranches(String className, int value); List<Integer> getListOfObjectivesValue();  }