mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-20 19:20:04 +00:00
added implementation of CompetitorResultsImpl.hasConflicts
Change-Id: I7b1fa2e0f64f8b2cf3719a3533a63d667c1146b3
This commit is contained in:
1 parent
87439312e0
commit
c98e3b8edb
2 files changed
+19
-1
No files matched your search
+7
@@ -8,5 +8,12 @@ package com.sap.sailing.domain.abstractlog.race;
|
||||
public interface CompetitorResults extends Iterable<CompetitorResult> {
|
||||
boolean add(CompetitorResult result);
|
||||
|
||||
/**
|
||||
* @return {@code true} if there are more than one {@link CompetitorResult} contained with equal
|
||||
* {@link CompetitorResult#getOneBasedRank() rank}. A client can take this as an indicator that
|
||||
* there may be an inconsistency, caused, e.g., by merging results entered on different devices
|
||||
* concurrently. The client shall use the {@link #iterator()} method to enumerate the
|
||||
* {@link CompetitorResult} objects, finding the conflicting elements.
|
||||
*/
|
||||
boolean hasConflicts();
|
||||
}
|
||||
+12
-1
@@ -1,6 +1,8 @@
|
||||
package com.sap.sailing.domain.abstractlog.race.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.race.CompetitorResult;
|
||||
import com.sap.sailing.domain.abstractlog.race.CompetitorResults;
|
||||
@@ -10,6 +12,15 @@ public class CompetitorResultsImpl extends ArrayList<CompetitorResult> implement
|
||||
|
||||
@Override
|
||||
public boolean hasConflicts() {
|
||||
return true; // FIXME just for testing
|
||||
final Set<Integer> oneBasedRanks = new HashSet<>();
|
||||
for (final CompetitorResult r : this) {
|
||||
final int oneBasedRank = r.getOneBasedRank();
|
||||
if (oneBasedRank != 0) {
|
||||
if (!oneBasedRanks.add(oneBasedRank)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user