forked from edemo/PDEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non-beaten andidates are winners edemo#246
- Loading branch information
Showing
5 changed files
with
55 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
src/main/java/org/rulez/demokracia/pdengine/WinnerCalculatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
package org.rulez.demokracia.pdengine; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.rulez.demokracia.pdengine.dataobjects.Pair; | ||
|
||
public class WinnerCalculatorImpl implements WinnerCalculator { | ||
|
||
@Override | ||
public List<String> calculateWinners(final BeatTable beatTable) { | ||
throw new UnsupportedOperationException(); | ||
return beatTable.getKeyCollection() | ||
.stream() | ||
.filter(choice -> isWinner(choice, beatTable)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private boolean isWinner(final String choice, final BeatTable beatTable) { | ||
Pair nonbeatingPair = new Pair(0, 0); | ||
|
||
return beatTable.getKeyCollection() | ||
.stream() | ||
.allMatch(otherChoice -> nonbeatingPair.equals(beatTable.getElement(otherChoice, choice))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters