Added java docs and changed a complicated return statement.

This commit is contained in:
Tom Vahlman 2012-02-11 13:37:32 +01:00
parent c6131c50bd
commit 1a7f831858

@ -29,7 +29,7 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
List<Match> matchList = new ArrayList<Match>();
this.weights = weights;
List<String> availableProjectClasses = getAvailableProjectClass(unmatchedProjectIdeas, supervisorAvailability);
HashMap<String, List<ProjectIdea>> sortedProjectIdeas = getSortedProjectIdeas(availableProjectClasses, unmatchedProjectIdeas);
@ -52,18 +52,15 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
matchList.addAll(matchProjectIdeas(projectIdeaList, availabilityList));
}
}
unmatchedProjectIdeas = getUnmatchedProjectIdeas(matchList, unmatchedProjectIdeas);
Result result = new Result(matchList, unmatchedProjectIdeas);
return result;
return new Result(matchList, unmatchedProjectIdeas);
}
/**
* Take all ProjectIdeas and remove those who have been matched
* @param matchList
* @param unmatchedProjectIdeas
* @return
* @param matchList the list
* @param unmatchedProjectIdeas unmatched ideas
* @return List<ProjectIdea>
*/
private List<ProjectIdea> getUnmatchedProjectIdeas(List<Match> matchList,
List<ProjectIdea> unmatchedProjectIdeas) {
@ -81,14 +78,14 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
}
/**
* Matches project ideas with supervisors and return the best match.
* @param projectIdeaList
* @param availabilityList
* @return
* Matches project ideas with supervisors (based on availability) and returns the best match.
* @param projectIdeaList project ideas that should be matched
* @param availabilityList supervisors that should be matched
* @return List<Match> the best matches are returned
*/
private List<Match> matchProjectIdeas(List<ProjectIdea> projectIdeaList, List<Availability> availabilityList) {
List<Match> matchList = new ArrayList<Match>();
Iterator<ProjectIdea> projectIdeaIterator = projectIdeaList.iterator();
while (projectIdeaIterator.hasNext()) {
ProjectIdea projectIdea = projectIdeaIterator.next();
@ -113,22 +110,22 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
match.setSupervisor(availability.getSupervisor());
match.setProjectIdea(projectIdea);
matchPair = new Pair(match, new Availability(null, 1L, 1, new ProjectClass()));
matchPair = getBestMatch(matchPair, availability);
}
if (matchPair != null && matchPair.getMatch().getPoints() != -1) {
matchList.add(matchPair.getMatch());
projectIdeaIterator.remove();
}
}
return matchList;
}
/**
matchList.add(matchPair.getMatch());
projectIdeaIterator.remove();
}
}
return matchList;
}
/**
* Return the best match, the old one or the new one with supervisor
* @param oldMatchPair
* @param availability
* @param oldMatchPair the match pair
* @param availability the availability
* @return Pair
*/
private Pair getBestMatch(Pair oldMatchPair, Availability availability) {
@ -166,9 +163,9 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
/**
* Returns if it is possible for the supervisor to work with this project idea based on
* language and if the idea has previously been rejected by the supervisor
* @param projectIdea
* @param supervisor
* @return
* @param projectIdea the project idea
* @param supervisor the supervisor
* @return boolean
*/
private boolean isPossibleSupervisor(ProjectIdea projectIdea, Employee supervisor) {
return isCompatibleLanguage(projectIdea, supervisor) && isNotRejectedBySupervisor(projectIdea, supervisor);
@ -176,9 +173,9 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
/**
* Has the project idea been rejected by the supervisor before
* @param projectIdea
* @param supervisor
* @return
* @param projectIdea the project idea
* @param supervisor the supervisor
* @return boolean
*/
private boolean isNotRejectedBySupervisor(ProjectIdea projectIdea, Employee supervisor) {
for (Match oldMatch : projectIdea.getMatchHistory()) {
@ -194,9 +191,9 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
/**
* Has the supervisor the capability to work with the specified language
* @param projectIdea
* @param supervisor
* @return
* @param projectIdea the project idea
* @param supervisor the supervisor
* @return boolean
*/
private boolean isCompatibleLanguage(ProjectIdea projectIdea,
Employee supervisor) {
@ -218,8 +215,8 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
/**
* Calculate score for match using Weights
* @param match
* @return
* @param match the match
* @return Match
*/
private Match calculateScore(Match match) {
int points = 0;
@ -245,8 +242,8 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
/**
*
* @param availableProjectClasses
* @param supervisorAvailability
* @param availableProjectClasses the list with available project classes
* @param supervisorAvailability the list with available supervisors
* @return Supervisors availability sorted on ProjectClasses.code
*/
private HashMap<String, List<Availability>> getSortedAvailability(
@ -266,9 +263,9 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
}
/**
*
* @param availableProjectClasses
* @param unmatchedProjectIdeaList
* @param availableProjectClasses the project classes that exists, regardless of there is a match or not,
* that is ok because the List with project ideas will be empty in case no project class match
* @param unmatchedProjectIdeaList the unmatched project ideas
* @return unmatched ProjectIdeas sorted on ProjectClasses.code
*/
private HashMap<String, List<ProjectIdea>> getSortedProjectIdeas(
@ -289,8 +286,8 @@ public class GreedyMatchingAlgorithm implements MatchingAlgorithm {
/**
*
* @param unmatchedProjectIdeas
* @param supervisorAvailability
* @param unmatchedProjectIdeas a list of unmatched project ideas
* @param supervisorAvailability list of available supervisors
* @return all available ProjectClass codes
*/
private List<String> getAvailableProjectClass(