From 9d5b181c4de0b6c789ed7c3df43b210da0733ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bujdos=C3=B3=20Valentin?= Date: Mon, 1 Apr 2019 18:19:31 +0200 Subject: [PATCH] Use compareBeats instead of reimpelement #307 (#308) * Use compareBeats instead of reimpelement #307 --- .../demokracia/pdengine/Normalizable.java | 28 ++++++------------- .../testhelpers/CreatedBeatTable.java | 6 +--- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/rulez/demokracia/pdengine/Normalizable.java b/src/main/java/org/rulez/demokracia/pdengine/Normalizable.java index d0a6dffa..31a09a16 100644 --- a/src/main/java/org/rulez/demokracia/pdengine/Normalizable.java +++ b/src/main/java/org/rulez/demokracia/pdengine/Normalizable.java @@ -2,7 +2,6 @@ import java.util.Collection; -import org.rulez.demokracia.pdengine.BeatTable.Direction; import org.rulez.demokracia.pdengine.dataobjects.Pair; public interface Normalizable extends ContainingBeats { @@ -10,30 +9,19 @@ public interface Normalizable extends ContainingBeats { long serialVersionUID = 1L; default void normalize() { - for (String key : getKeyCollection()) { - setElement(key, key, new Pair(0, 0)); - } - Collection keys = getKeyCollection(); - + for (String key1 : keys) { for (String key2 : keys) { - int key1Win = beatInformation(key1, key2, Direction.DIRECTION_FORWARD); - int key2Win = beatInformation(key2, key1, Direction.DIRECTION_FORWARD); - - if (key1Win > key2Win) + Pair beats1 = getPair(key1, key2); + Pair beats2 = getPair(key2, key1); + Pair pair = compareBeats(beats1, beats2); + + if(pair.equals(beats1)) setElement(key2, key1, new Pair(0, 0)); - if (key1Win == key2Win) { - int key1Los = beatInformation(key1, key2, Direction.DIRECTION_BACKWARD); - int key2Los = beatInformation(key2, key1, Direction.DIRECTION_BACKWARD); - - if (key1Los == key2Los) { - setElement(key2, key1, new Pair(0, 0)); - setElement(key1, key2, new Pair(0, 0)); - } - } + if(pair.equals(beats2)) + setElement(key1, key2, new Pair(0, 0)); } } } - } diff --git a/src/test/java/org/rulez/demokracia/pdengine/testhelpers/CreatedBeatTable.java b/src/test/java/org/rulez/demokracia/pdengine/testhelpers/CreatedBeatTable.java index 7ee4029f..792588e0 100644 --- a/src/test/java/org/rulez/demokracia/pdengine/testhelpers/CreatedBeatTable.java +++ b/src/test/java/org/rulez/demokracia/pdengine/testhelpers/CreatedBeatTable.java @@ -61,11 +61,7 @@ protected void createNewBeatTableWithComplexData() { } protected void createNewBeatTableWithEqualData() { - List list = new ArrayList(); - list.add(choice1); - list.add(choice2); - list.add(choice3); - beatTable = new BeatTable(list); + createNewBeatTableWithData(); beatTable.setElement(choice1, choice2, new Pair(2, 2)); beatTable.setElement(choice2, choice1, new Pair(2, 2)); beatTable.setElement(choice1, choice3, new Pair(4, 1));