Fixed bug in team generation code.
This commit is contained in:
parent
a2797e54a6
commit
926c28fd9a
|
@ -60,6 +60,7 @@ public class Main {
|
|||
private static void initializeTestingData() {
|
||||
try {
|
||||
List<StudentTeam> teams = TeamGenerator.generateFromCSV("/home/andrew/Documents/School/ta/GithubInitializer/sampleAOOP.csv", 2);
|
||||
System.out.println(teams);
|
||||
DbHelper.saveStudentTeams(teams);
|
||||
managementView.updateModels();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package nl.andrewlalis.model;
|
||||
|
||||
import nl.andrewlalis.util.Pair;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -20,7 +22,7 @@ public class Student extends Person {
|
|||
/**
|
||||
* A list of partners that the student has said that they would like to be partners with.
|
||||
*/
|
||||
@ManyToMany
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(
|
||||
name = "student_preferred_partners",
|
||||
joinColumns = { @JoinColumn(name = "student_id")},
|
||||
|
@ -95,4 +97,20 @@ public class Student extends Person {
|
|||
public StudentTeam getAssignedTeam() {
|
||||
return this.team;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, String>> getDetailPairs() {
|
||||
List<Pair<String, String>> pairs = super.getDetailPairs();
|
||||
String teamNumber = "None";
|
||||
if (this.getAssignedTeam() != null) {
|
||||
teamNumber = String.valueOf(this.getAssignedTeam().getNumber());
|
||||
}
|
||||
pairs.add(new Pair<>("Team Number", teamNumber));
|
||||
|
||||
for (int i = 0; i < this.preferredPartners.size(); i++) {
|
||||
pairs.add(new Pair<>("Preferred partner " + (i + 1), this.preferredPartners.get(i).getDetailName()));
|
||||
}
|
||||
|
||||
return pairs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class StudentTeam extends Team {
|
|||
// If the student doesn't have an preferred partners, then assume that this is valid.
|
||||
if (!studentA.getPreferredPartners().isEmpty()) {
|
||||
for (Student studentB : this.getStudents()) {
|
||||
if (!studentA.equals(studentB) && !studentA.getPreferredPartners().contains(studentB.getNumber())) {
|
||||
if (!studentA.equals(studentB) && !studentA.getPreferredPartners().contains(studentB)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,10 @@ public class StudentTableModel extends AbstractTableModel {
|
|||
* @return The student object at the specified row, or null if none is found.
|
||||
*/
|
||||
public Student getStudentAt(int row) {
|
||||
return this.studentsList.get(row);
|
||||
if (row >= 0 && row < this.studentsList.size()) {
|
||||
return this.studentsList.get(row);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package nl.andrewlalis.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.*;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
/**
|
||||
* Responsible for creating logs to standard output and writing to files.
|
||||
|
@ -25,7 +28,7 @@ public class Logging {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.setLevel(Level.ALL);
|
||||
logger.setLevel(Level.FINEST);
|
||||
Logger.getLogger("").setLevel(Level.OFF);
|
||||
|
||||
}
|
||||
|
|
|
@ -91,12 +91,14 @@ public class TeamGenerator {
|
|||
for (StudentTeam team : studentTeams) {
|
||||
if (newTeam.hasSameMembers(team)) {
|
||||
matchFound = true;
|
||||
logger.finest("A team was found with the same members: " + team.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matchFound) {
|
||||
// Once we know this team is completely valid, we remove all the students in it from the list of singles.
|
||||
newTeam.setNumber(teamCount++);
|
||||
studentTeams.add(newTeam);
|
||||
singleStudents.removeAll(Arrays.asList(newTeam.getStudents()));
|
||||
assignStudentsToTeam(newTeam);
|
||||
logger.fine("Created team:\n" + newTeam);
|
||||
|
|
Loading…
Reference in New Issue