Merge remote-tracking branch 'origin/master'

This commit is contained in:
fmittag committed 2012-06-17 13:56:53 +02:00
commit 2596ab9ee3
4 files changed
+58 -27

No files matched your search

@@ -1,6 +1,7 @@
package com.sap.sailing.domain.leaderboard;
import java.io.Serializable;
import java.util.concurrent.Callable;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.RaceColumn;
@@ -36,7 +37,8 @@ public interface ScoreCorrection extends Serializable {
* @param numberOfCompetitors
* the number of competitors to use as the basis for penalty score calculation ("max points")
*/
Result getCorrectedScore(int uncorrectedScore, Competitor competitor, RaceColumn raceColumn, TimePoint timePoint, int numberOfCompetitors);
Result getCorrectedScore(Callable<Integer> uncorrectedScore, Competitor competitor, RaceColumn raceColumn,
TimePoint timePoint, int numberOfCompetitors);
/**
* Note the difference between what this method does and a more naive comparison of uncorrected and corrected score.
@@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.Fleet;
@@ -77,7 +78,7 @@ public abstract class AbstractLeaderboardImpl implements Leaderboard, RaceColumn
*
*/
private class EntryImpl implements Entry {
private final int trackedPoints;
private final Callable<Integer> trackedPoints;
private final int netPoints;
private final boolean isNetPointsCorrected;
private final int totalPoints;
@@ -85,7 +86,7 @@ public abstract class AbstractLeaderboardImpl implements Leaderboard, RaceColumn
private final boolean discarded;
private final Fleet fleet;
private EntryImpl(int trackedPoints, int netPoints, boolean isNetPointsCorrected, int totalPoints,
private EntryImpl(Callable<Integer> trackedPoints, int netPoints, boolean isNetPointsCorrected, int totalPoints,
MaxPointsReason maxPointsReason, boolean discarded, Fleet fleet) {
super();
this.trackedPoints = trackedPoints;
@@ -98,7 +99,11 @@ public abstract class AbstractLeaderboardImpl implements Leaderboard, RaceColumn
}
@Override
public int getTrackedPoints() {
return trackedPoints;
try {
return trackedPoints.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public int getNetPoints() {
@@ -259,8 +264,13 @@ public abstract class AbstractLeaderboardImpl implements Leaderboard, RaceColumn
}
@Override
public int getNetPoints(Competitor competitor, RaceColumn raceColumn, TimePoint timePoint) throws NoWindException {
return getScoreCorrection().getCorrectedScore(getTrackedRank(competitor, raceColumn, timePoint), competitor,
public int getNetPoints(final Competitor competitor, final RaceColumn raceColumn, final TimePoint timePoint) throws NoWindException {
return getScoreCorrection().getCorrectedScore(
new Callable<Integer>() {
public Integer call() throws NoWindException {
return getTrackedRank(competitor, raceColumn, timePoint);
}
}, competitor,
raceColumn, timePoint, Util.size(getCompetitors())).getCorrectedScore();
}
@@ -294,8 +304,12 @@ public abstract class AbstractLeaderboardImpl implements Leaderboard, RaceColumn
}
@Override
public Entry getEntry(Competitor competitor, RaceColumn race, TimePoint timePoint) throws NoWindException {
int trackedPoints = getTrackedRank(competitor, race, timePoint);
public Entry getEntry(final Competitor competitor, final RaceColumn race, final TimePoint timePoint) throws NoWindException {
Callable<Integer> trackedPoints = new Callable<Integer>() {
public Integer call() throws NoWindException {
return getTrackedRank(competitor, race, timePoint);
}
};
final Result correctedResults = getScoreCorrection().getCorrectedScore(trackedPoints, competitor, race,
timePoint, Util.size(getCompetitors()));
boolean discarded = isDiscarded(competitor, race, timePoint);
@@ -306,18 +320,24 @@ public abstract class AbstractLeaderboardImpl implements Leaderboard, RaceColumn
}
@Override
public Map<Pair<Competitor, RaceColumn>, Entry> getContent(TimePoint timePoint) throws NoWindException {
public Map<Pair<Competitor, RaceColumn>, Entry> getContent(final TimePoint timePoint) throws NoWindException {
Map<Pair<Competitor, RaceColumn>, Entry> result = new HashMap<Pair<Competitor, RaceColumn>, Entry>();
Map<Competitor, Set<RaceColumn>> discardedRaces = new HashMap<Competitor, Set<RaceColumn>>();
for (RaceColumn raceColumn : getRaceColumns()) {
for (Competitor competitor : getCompetitors()) {
int trackedPoints;
final TrackedRace trackedRace = raceColumn.getTrackedRace(competitor);
if (trackedRace != null && trackedRace.hasStarted(timePoint)) {
trackedPoints = trackedRace.getRank(competitor, timePoint);
} else {
trackedPoints = 0;
}
for (final RaceColumn raceColumn : getRaceColumns()) {
for (final Competitor competitor : getCompetitors()) {
Callable<Integer> trackedPoints = new Callable<Integer>() {
@Override
public Integer call() throws Exception {
int trackedPoints;
final TrackedRace trackedRace = raceColumn.getTrackedRace(competitor);
if (trackedRace != null && trackedRace.hasStarted(timePoint)) {
trackedPoints = trackedRace.getRank(competitor, timePoint);
} else {
trackedPoints = 0;
}
return trackedPoints;
}
};
Result correctedResults = getScoreCorrection().getCorrectedScore(trackedPoints, competitor, raceColumn,
timePoint, Util.size(getCompetitors()));
Set<RaceColumn> discardedRacesForCompetitor = discardedRaces.get(competitor);
@@ -2,6 +2,7 @@ package com.sap.sailing.domain.leaderboard.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.RaceColumn;
@@ -82,7 +83,7 @@ public class ScoreCorrectionImpl implements SettableScoreCorrection {
* <p>
*/
@Override
public Result getCorrectedScore(int uncorrectedScore, final Competitor competitor, final RaceColumn raceColumn,
public Result getCorrectedScore(Callable<Integer> uncorrectedScore, final Competitor competitor, final RaceColumn raceColumn,
TimePoint timePoint, int numberOfCompetitorsInLeaderboard) {
int result;
final MaxPointsReason maxPointsReason = getMaxPointsReason(competitor, raceColumn);
@@ -122,10 +123,14 @@ public class ScoreCorrectionImpl implements SettableScoreCorrection {
* reasons, computes the corrected score. If {@link #correctedScores} contains an entry for the <code>competitor</code>'s key,
* it is used. Otherwise, the <code>uncorrectedScore</code> is returned.
*/
protected int getCorrectedNonMaxedScore(Competitor competitor, RaceColumn raceColumn, int uncorrectedScore) {
protected int getCorrectedNonMaxedScore(Competitor competitor, RaceColumn raceColumn, Callable<Integer> uncorrectedScore) {
Integer correctedNonMaxedScore = correctedScores.get(raceColumn.getKey(competitor));
if (correctedNonMaxedScore == null) {
return uncorrectedScore;
try {
return uncorrectedScore.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
return correctedNonMaxedScore;
}
@@ -359,9 +359,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
private TimePoint getLastPassingOfFinishLine() {
TimePoint passingTime = null;
Iterable<MarkPassing> markPassingsInOrder = getMarkPassingsInOrder(getRace().getCourse().getLastWaypoint());
synchronized (markPassingsInOrder) {
for (MarkPassing passingFinishLine : markPassingsInOrder) {
passingTime = passingFinishLine.getTimePoint();
if (markPassingsInOrder != null) {
synchronized (markPassingsInOrder) {
for (MarkPassing passingFinishLine : markPassingsInOrder) {
passingTime = passingFinishLine.getTimePoint();
}
}
}
return passingTime;
@@ -370,9 +372,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
private TimePoint getFirstPassingTime(Waypoint waypoint) {
NavigableSet<MarkPassing> markPassingsInOrder = getMarkPassingsInOrderAsNavigableSet(waypoint);
MarkPassing firstMarkPassing = null;
synchronized (markPassingsInOrder) {
if (!markPassingsInOrder.isEmpty()) {
firstMarkPassing = markPassingsInOrder.first();
if (markPassingsInOrder != null) {
synchronized (markPassingsInOrder) {
if (!markPassingsInOrder.isEmpty()) {
firstMarkPassing = markPassingsInOrder.first();
}
}
}
TimePoint timeOfFirstMarkPassing = null;