added Leaderboard interface with first little test cases

Also, streamlined pom.xml files
This commit is contained in:
Axel Uhl committed 2011-07-29 15:36:49 +02:00
1 parent 45b46f3209
commit 0282c6a8c8
67 files changed
+480 -67

No files matched your search

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="test/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="test" sourcepath="test"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.googlecode.java-diff-utils.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.googlecode.java-diff-utils</artifactId>
<version>1.3.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+1 -5
View File
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/mongo-2.6.2.jar">
<attributes>
<attribute name="javadoc_location" value="http://api.mongodb.org/java/2.6.2/"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/mongo-2.6.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.mongodb.driver</artifactId>
<version>2.6.2</version>
<packaging>eclipse-plugin</packaging>
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.declination.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
+2 -2
View File
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="src" path="resources/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.declination</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+2 -2
View File
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="src" path="resources/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -11,4 +11,5 @@ Require-Bundle: com.sap.sailing.domain,
com.sap.sailing.domain.tractracadapter,
org.json.simple;bundle-version="1.1.0",
com.googlecode.java-diff-utils;bundle-version="1.3.0"
Export-Package: com.sap.sailing.domain.test
Export-Package: com.sap.sailing.domain.test,
com.sap.sailing.domain.test.mock
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.domain.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
@@ -0,0 +1,108 @@
package com.sap.sailing.domain.test;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.base.impl.BoatClassImpl;
import com.sap.sailing.domain.base.impl.BoatImpl;
import com.sap.sailing.domain.base.impl.CompetitorImpl;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.base.impl.NationalityImpl;
import com.sap.sailing.domain.base.impl.PersonImpl;
import com.sap.sailing.domain.base.impl.TeamImpl;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.ScoreCorrection;
import com.sap.sailing.domain.leaderboard.impl.LeaderboardImpl;
import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl;
import com.sap.sailing.domain.test.mock.MockedTrackedRace;
import com.sap.sailing.domain.tracking.NoWindException;
import com.sap.sailing.domain.tracking.TrackedRace;
public class LeaderboardTests {
private Set<TrackedRace> testRaces;
private Competitor competitor;
@Before
public void setUp() {
competitor = new CompetitorImpl(123, "Wolfgang Hunger", new TeamImpl("STG", Collections.singleton(
new PersonImpl("Wolfgang Hunger", new NationalityImpl("Germany", "GER"),
/* dateOfBirth */ null, "This is famous Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("The Netherlands", "NED"),
/* dateOfBirth */ null, "This is Rigo, the coach")), new BoatImpl("Wolfgang Hunger's boat", new BoatClassImpl("505")));
}
public void setupRaces(int numberOfStartedRaces, int numberOfNotStartedRaces) {
testRaces = new HashSet<TrackedRace>();
for (int i=0; i<numberOfStartedRaces; i++) {
TrackedRace r = new MockedTrackedRaceWithFixedRank(i, /* started */ true);
testRaces.add(r); // hash set should take care of more or less randomly permuting the races
}
for (int i=0; i<numberOfNotStartedRaces; i++) {
TrackedRace r = new MockedTrackedRaceWithFixedRank(-1, /* started */ false);
testRaces.add(r); // hash set should take care of more or less randomly permuting the races
}
}
@Test
public void testSetup() {
setupRaces(3, 7);
assertEquals(10, testRaces.size());
}
@Test
public void simpleLeaderboardTest() throws NoWindException {
setupRaces(2, 9);
Leaderboard leaderboard = new LeaderboardImpl(new ScoreCorrection() {
@Override
public int getCorrectedScore(int uncorrectedScore, Competitor competitor, TrackedRace trackedRace,
TimePoint timePoint) {
return uncorrectedScore;
}
}, new ResultDiscardingRuleImpl(new int[] { 3, 6 }));
for (TrackedRace race : testRaces) {
leaderboard.addRace(race);
}
TimePoint now = MillisecondsTimePoint.now();
for (TrackedRace race : testRaces) {
if (race.hasStarted(now)) {
assertEquals(race.getRank(competitor, now), leaderboard.getTrackedPoints(competitor, race, now));
assertEquals(race.getRank(competitor, now), leaderboard.getNetPoints(competitor, race, now));
} else {
assertEquals(0, leaderboard.getTrackedPoints(competitor, race, now));
assertEquals(0, leaderboard.getNetPoints(competitor, race, now));
}
}
}
private class MockedTrackedRaceWithFixedRank extends MockedTrackedRace {
private final int rank;
private final boolean started;
public MockedTrackedRaceWithFixedRank(int rank, boolean started) {
this.rank = rank;
this.started = started;
}
@Override
public boolean hasStarted(TimePoint at) {
return started;
}
@Override
public int getRank(Competitor competitor, TimePoint timePoint) throws NoWindException {
return rank;
}
@Override
public int getRank(Competitor competitor) throws NoWindException {
return rank;
}
}
}
@@ -1,4 +1,4 @@
package com.sap.sailing.expeditionconnector.test;
package com.sap.sailing.domain.test.mock;
import java.util.NavigableSet;
@@ -266,4 +266,10 @@ public class MockedTrackedRace implements DynamicTrackedRace {
return null;
}
@Override
public boolean hasStarted(TimePoint at) {
// TODO Auto-generated method stub
return false;
}
}
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.domain.tractracadapter</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+1 -1
View File
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -8,6 +8,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .
Export-Package: com.sap.sailing.domain.base,
com.sap.sailing.domain.base.impl,
com.sap.sailing.domain.leaderboard,
com.sap.sailing.domain.leaderboard.impl,
com.sap.sailing.domain.standings,
com.sap.sailing.domain.tracking,
com.sap.sailing.domain.tracking.impl,
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.domain</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
@@ -1,6 +1,6 @@
package com.sap.sailing.domain.base;
public interface Team extends Named, WithNationality {
Iterable<Person> getSailors();
Iterable<? extends Person> getSailors();
Person getCoach();
}
@@ -5,17 +5,17 @@ import com.sap.sailing.domain.base.Person;
import com.sap.sailing.domain.base.Team;
public class TeamImpl extends NamedImpl implements Team {
private final Iterable<Person> sailors;
private final Iterable<? extends Person> sailors;
private final Person coach;
public TeamImpl(String name, Iterable<Person> sailors, Person coach) {
public TeamImpl(String name, Iterable<? extends Person> sailors, Person coach) {
super(name);
this.sailors = sailors;
this.coach = coach;
}
@Override
public Iterable<Person> getSailors() {
public Iterable<? extends Person> getSailors() {
return sailors;
}
@@ -2,6 +2,7 @@ package com.sap.sailing.domain.leaderboard;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.tracking.NoWindException;
import com.sap.sailing.domain.tracking.TrackedRace;
/**
@@ -24,14 +25,16 @@ public interface Leaderboard {
Iterable<Competitor> getCompetitors();
/**
* Shorthand for {@link TrackedRace#getRank(Competitor, com.sap.sailing.domain.base.TimePoint)}.
* Shorthand for {@link TrackedRace#getRank(Competitor, com.sap.sailing.domain.base.TimePoint)} with the
* additional logic that in case the <code>race</code> hasn't {@link TrackedRace#hasStarted(TimePoint) started}
* yet, 0 points will be allotted to the race for all competitors.
*
* @param competitor
* a competitor contained in the {@link #getCompetitors()} result
* @param race
* a race that is contained in the {@link #getRaces()} result
*/
int getTrackedPoints(Competitor competitor, TrackedRace race, TimePoint timePoint);
int getTrackedPoints(Competitor competitor, TrackedRace race, TimePoint timePoint) throws NoWindException;
/**
* A possibly corrected number of points for the race specified. Defaults to the result of calling
@@ -43,7 +46,7 @@ public interface Leaderboard {
* @param race
* a race that is contained in the {@link #getRaces()} result
*/
int getNetPoints(Competitor competitor, TrackedRace race, TimePoint timePoint);
int getNetPoints(Competitor competitor, TrackedRace race, TimePoint timePoint) throws NoWindException;
/**
* A possibly corrected number of points for the race specified. Defaults to the result of calling
@@ -55,5 +58,9 @@ public interface Leaderboard {
* @param race
* a race that is contained in the {@link #getRaces()} result
*/
int getTotalPoints(Competitor competitor, TrackedRace race, TimePoint timePoint);
int getTotalPoints(Competitor competitor, TrackedRace race, TimePoint timePoint) throws NoWindException;
boolean isDiscarded(Competitor competitor, TrackedRace race, TimePoint timePoint);
void addRace(TrackedRace race);
}
@@ -0,0 +1,19 @@
package com.sap.sailing.domain.leaderboard;
import java.util.Set;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.tracking.TrackedRace;
/**
* A result discarding rule is used to determine for a competitor those races from a list of
* races whose results are to be discarded. Typically, such a rules lists the number of
* races that may be discarded depending on the total number of races completed so far.
*
* @author Axel Uhl (d043530)
*
*/
public interface ResultDiscardingRule {
Set<TrackedRace> getDiscardedRaces(Competitor competitor, Iterable<TrackedRace> races, TimePoint timePoint);
}
@@ -0,0 +1,19 @@
package com.sap.sailing.domain.leaderboard;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.tracking.TrackedRace;
/**
* Manages score corrections for a competitor in a race, in particular handling the following use cases:
* <ul>
* <li>competitor disqualified: maximum points will be granted to the competitor for that race</li>
* <li>imprecise tracking for finish line: jury changed final rankings; usually several competitors affected</li>
* </ul>
*
* @author Axel Uhl (d043530)
*
*/
public interface ScoreCorrection {
int getCorrectedScore(int uncorrectedScore, Competitor competitor, TrackedRace trackedRace, TimePoint timePoint);
}
@@ -0,0 +1,79 @@
package com.sap.sailing.domain.leaderboard.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.ResultDiscardingRule;
import com.sap.sailing.domain.leaderboard.ScoreCorrection;
import com.sap.sailing.domain.tracking.NoWindException;
import com.sap.sailing.domain.tracking.TrackedRace;
public class LeaderboardImpl implements Leaderboard {
private final List<TrackedRace> races;
private final ScoreCorrection scoreCorrection;
private final ResultDiscardingRule resultDiscardingRule;
public LeaderboardImpl(ScoreCorrection scoreCorrection, ResultDiscardingRule resultDiscardingRule) {
this.races = new ArrayList<TrackedRace>();
this.scoreCorrection = scoreCorrection;
this.resultDiscardingRule = resultDiscardingRule;
}
@Override
public void addRace(TrackedRace race) {
if (!races.contains(race)) {
races.add(race);
}
}
@Override
public Iterable<TrackedRace> getRaces() {
return Collections.unmodifiableList(races);
}
@Override
public Iterable<Competitor> getCompetitors() {
Set<Competitor> result = new HashSet<Competitor>();
for (TrackedRace r : getRaces()) {
for (Competitor c : r.getRace().getCompetitors()) {
result.add(c);
}
}
return result;
}
private ScoreCorrection getScoreCorrection() {
return scoreCorrection;
}
private ResultDiscardingRule getResultDiscardingRule() {
return resultDiscardingRule;
}
@Override
public int getTrackedPoints(Competitor competitor, TrackedRace race, TimePoint timePoint) throws NoWindException {
return race.hasStarted(timePoint) ? race.getRank(competitor, timePoint) : 0;
}
@Override
public int getNetPoints(Competitor competitor, TrackedRace race, TimePoint timePoint) throws NoWindException {
return getScoreCorrection().getCorrectedScore(getTrackedPoints(competitor, race, timePoint), competitor, race, timePoint);
}
@Override
public boolean isDiscarded(Competitor competitor, TrackedRace race, TimePoint timePoint) {
return getResultDiscardingRule().getDiscardedRaces(competitor, races, timePoint).contains(race);
}
@Override
public int getTotalPoints(Competitor competitor, TrackedRace race, TimePoint timePoint) throws NoWindException {
return isDiscarded(competitor, race, timePoint) ? 0 : getNetPoints(competitor, race, timePoint);
}
}
@@ -0,0 +1,81 @@
package com.sap.sailing.domain.leaderboard.impl;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.leaderboard.ResultDiscardingRule;
import com.sap.sailing.domain.tracking.NoWindError;
import com.sap.sailing.domain.tracking.NoWindException;
import com.sap.sailing.domain.tracking.TrackedRace;
/**
* Discards <code>i</code> results if the TODO TODO number of races started is greater or equal to
* {@link #discardIndexResultsStartingWithHowManyRaces}<code>[i]</code> and
* <code>i&lt;{@link #discardIndexResultsStartingWithHowManyRaces}.length</code>. If
* <code>i&gt;={@link #discardIndexResultsStartingWithHowManyRaces}.length</code>, then
* <code>{@link #discardIndexResultsStartingWithHowManyRaces}.length</code> results are discarded.
*
* @author Axel Uhl (d043530)
*
*/
public class ResultDiscardingRuleImpl implements ResultDiscardingRule {
private final int[] discardIndexResultsStartingWithHowManyRaces;
public ResultDiscardingRuleImpl(int[] discardIndexResultsStartingWithHowManyRaces) {
super();
this.discardIndexResultsStartingWithHowManyRaces = new int[discardIndexResultsStartingWithHowManyRaces.length];
System.arraycopy(discardIndexResultsStartingWithHowManyRaces, 0,
this.discardIndexResultsStartingWithHowManyRaces, 0, discardIndexResultsStartingWithHowManyRaces.length);
}
@Override
public Set<TrackedRace> getDiscardedRaces(final Competitor competitor, Iterable<TrackedRace> races, final TimePoint timePoint) {
int resultsToDiscard = getNumberOfResultsToDiscard(races, timePoint);
Set<TrackedRace> result = new HashSet<TrackedRace>();
if (resultsToDiscard > 0) {
TreeSet<TrackedRace> sortedRaces = new TreeSet<TrackedRace>(new Comparator<TrackedRace>() {
@Override
public int compare(TrackedRace o1, TrackedRace o2) {
try {
return o1.getRank(competitor, timePoint) - o2.getRank(competitor, timePoint);
} catch (NoWindException e) {
throw new NoWindError(e);
}
}
});
int i=0;
Iterator<TrackedRace> badRacesIter = sortedRaces.descendingIterator();
while (badRacesIter.hasNext() && i<resultsToDiscard) {
result.add(badRacesIter.next());
i++;
}
}
return result;
}
private int getNumberOfResultsToDiscard(Iterable<TrackedRace> races, TimePoint timePoint) {
int numberOfResultsToDiscard;
int numberOfStartedRaces = 0;
for (TrackedRace r : races) {
if (r.hasStarted(timePoint)) {
numberOfStartedRaces++;
}
}
if (numberOfStartedRaces >= discardIndexResultsStartingWithHowManyRaces.length) {
numberOfResultsToDiscard = discardIndexResultsStartingWithHowManyRaces.length;
} else {
numberOfResultsToDiscard = 0;
while (numberOfResultsToDiscard < discardIndexResultsStartingWithHowManyRaces.length
&& discardIndexResultsStartingWithHowManyRaces[numberOfResultsToDiscard] < numberOfStartedRaces) {
numberOfResultsToDiscard++;
}
}
return numberOfResultsToDiscard;
}
}
@@ -42,6 +42,11 @@ public interface TrackedRace {
*/
TimePoint getStart();
/**
* Shorthand for <code>{@link #getStart()}.{@link TimePoint#compareTo(TimePoint) compareTo(at)} &lt;= 0</code>
*/
boolean hasStarted(TimePoint at);
Iterable<TrackedLeg> getTrackedLegs();
TrackedLeg getTrackedLeg(Leg leg);
@@ -101,7 +106,8 @@ public interface TrackedRace {
* Computes the rank of <code>competitor</code> in this race. A competitor is ahead of all
* competitors that are one or more legs behind. Within the same leg, the rank is determined
* by the windward distance to go and therefore depends on the assumptions of the wind direction
* for the given <code>timePoint</code>.
* for the given <code>timePoint</code>. If the race hasn't {@link #hasStarted(TimePoint) started}
* yet, the result is undefined.
*/
int getRank(Competitor competitor, TimePoint timePoint) throws NoWindException;
@@ -179,6 +179,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
}
return result;
}
@Override
public boolean hasStarted(TimePoint at) {
return getStart().compareTo(at) <= 0;
}
protected void setStartTimeReceived(TimePoint start) {
this.startTimeReceived = start;
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -9,4 +9,5 @@ Require-Bundle: org.junit4;bundle-version="4.8.1",
com.sap.sailing.server,
com.sap.sailing.expeditionconnector,
com.sap.sailing.domain,
com.sap.sailing.declination
com.sap.sailing.declination,
com.sap.sailing.domain.test
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.expeditionconnector.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
@@ -32,6 +32,7 @@ import com.sap.sailing.domain.base.Position;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.base.impl.DegreePosition;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.test.mock.MockedTrackedRace;
import com.sap.sailing.domain.tracking.GPSFix;
import com.sap.sailing.domain.tracking.Wind;
import com.sap.sailing.expeditionconnector.ExpeditionListener;
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.expeditionconnector</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+2 -1
View File
@@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.mongodb.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
+1 -1
View File
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.mongodb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+1 -1
View File
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.server.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
+1 -1
View File
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.server</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+2 -6
View File
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/TracTracClientModule.jar">
<attributes>
<attribute name="javadoc_location" value="file:/C:/data/SAP/sailing/workspace/java/com.tractrac.clientmodule/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/TracTracClientModule.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.tractrac.clientmodule</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+4 -8
View File
@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/TracClientLib.jar"/>
<classpathentry exported="true" kind="lib" path="lib/TracClientSail.jar"/>
<classpathentry exported="true" kind="lib" path="lib/TracResultAPI.jar">
<attributes>
<attribute name="javadoc_location" value="file:/C:/data/SAP/sailing/workspace/java/com.tractrac.resultapi/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/TracResultAPI.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry exported="true" kind="lib" path="lib/TracClientSail.jar"/>
<classpathentry exported="true" kind="lib" path="lib/TracClientLib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>com.tractrac.resultapi</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+1 -1
View File
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+6
View File
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
-1
View File
@@ -7,7 +7,6 @@
<groupId>com.sap.sailing</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>org.json.simple</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+6 -2
View File
@@ -10,9 +10,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.sap.sailing</groupId>
<artifactId>root</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
@@ -159,5 +157,11 @@
<id>eclipse</id>
<url>http://download.eclipse.org/releases/indigo/</url>
</repository>
<!--
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
-->
</repositories>
</project>