Skip to content

Commit

Permalink
Tabulation Equality Definition Improvements
Browse files Browse the repository at this point in the history
- Update School equality and hash code (include level)
- Update Student equality and hash code (remove scores)
- Add error logging upon duplicate student insertion
  • Loading branch information
sushain97 committed Mar 10, 2014
1 parent c898981 commit 251ebf8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/contestTabulation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ private static void updateDatabase(Level level, SpreadsheetEntry spreadsheet, Se
}
}

school.addStudent(student);
if (!school.addStudent(student)) {
System.err.println("!!! Duplicate student detected !!! " + student);
}
}
catch (Exception e) {
e.printStackTrace();
Expand Down
14 changes: 9 additions & 5 deletions src/contestTabulation/School.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ protected void addAnonScores(Test test, ArrayList<Score> scores) {
}
}

protected void addStudent(Student student) {
students.add(Objects.requireNonNull(student));
protected boolean addStudent(Student student) {
return students.add(Objects.requireNonNull(student));
}

private HashMap<Student, Score> calculateScore(final Subject subject) {
Expand Down Expand Up @@ -190,13 +190,16 @@ public boolean equals(Object obj) {
return false;
}
School other = (School) obj;
if (level != other.level) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
else if (!name.equals(other.name)) {
return false;
}
}
else if (!name.equals(other.name)) {
return false;
}
return true;
}
Expand Down Expand Up @@ -255,6 +258,7 @@ public int getTotalScore() {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (level == null ? 0 : level.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
return result;
}
Expand Down
11 changes: 1 addition & 10 deletions src/contestTabulation/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int compare(Student s1, Student s2) {
@Persistent private int grade;
@Persistent private String name;
@Persistent private School school;
@Persistent(serialized = "true", defaultFetchGroup = "true") @Unowned private Map<Subject, Score> scores = new HashMap<Subject, Score>();
@Persistent(serialized = "true") @Unowned private Map<Subject, Score> scores = new HashMap<Subject, Score>();

@PrimaryKey private Key key;

Expand Down Expand Up @@ -106,14 +106,6 @@ else if (!name.equals(other.name)) {
else if (!school.equals(other.school)) {
return false;
}
if (scores == null) {
if (other.scores != null) {
return false;
}
}
else if (!scores.equals(other.scores)) {
return false;
}
return true;
}

Expand Down Expand Up @@ -157,7 +149,6 @@ public int hashCode() {
result = prime * result + grade;
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + (school == null ? 0 : school.hashCode());
result = prime * result + (scores == null ? 0 : scores.hashCode());
return result;
}

Expand Down
Binary file modified war/WEB-INF/classes/contestTabulation/Main.class
Binary file not shown.
Binary file modified war/WEB-INF/classes/contestTabulation/School.class
Binary file not shown.
Binary file modified war/WEB-INF/classes/contestTabulation/Student.class
Binary file not shown.

0 comments on commit 251ebf8

Please sign in to comment.