aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/comparator
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2016-08-14 18:09:22 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2016-08-14 18:09:22 +0200
commit8cb35b358563e5a81ad9e4aceb123b85222cf4cc (patch)
tree0d73eebfe29e7d90d4e0d6c5d40a36db75de3fdc /src/eu/equalparts/cardbase/comparator
parent78e369043f95e78b27c265f7eab4d766e54054f4 (diff)
Implemented some more filtering tests, sorted out validation and exceptions
Diffstat (limited to 'src/eu/equalparts/cardbase/comparator')
-rw-r--r--src/eu/equalparts/cardbase/comparator/CardComparator.java12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/eu/equalparts/cardbase/comparator/CardComparator.java b/src/eu/equalparts/cardbase/comparator/CardComparator.java
index d2cd0c1..31d42ad 100644
--- a/src/eu/equalparts/cardbase/comparator/CardComparator.java
+++ b/src/eu/equalparts/cardbase/comparator/CardComparator.java
@@ -1,6 +1,5 @@
package eu.equalparts.cardbase.comparator;
-import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Comparator;
import java.util.function.BiFunction;
@@ -9,6 +8,7 @@ import eu.equalparts.cardbase.card.Card;
import eu.equalparts.cardbase.cardfield.CardField;
import eu.equalparts.cardbase.comparator.SpecialFields.DirtyNumber;
import eu.equalparts.cardbase.comparator.SpecialFields.Rarity;
+import eu.equalparts.cardbase.utils.Utils;
/**
* I'm new to this reflection business, so bear with me.
@@ -56,12 +56,10 @@ public class CardComparator implements Comparator<Card> {
this.fieldToCompare = fieldToCompare;
// if annotated with a special comparator, set the comparison delegate here
- for (Annotation annotation : fieldToCompare.getAnnotations()) {
- if (annotation.annotationType() == DirtyNumber.class) {
- this.comparisonDelegate = ComparatorDelegates::compareDirtyNumber;
- } else if (annotation.annotationType() == Rarity.class) {
- this.comparisonDelegate = ComparatorDelegates::compareRarity;
- }
+ if (Utils.hasAnnotation(fieldToCompare, DirtyNumber.class)) {
+ this.comparisonDelegate = ComparatorDelegates::compareDirtyNumber;
+ } else if (Utils.hasAnnotation(fieldToCompare, Rarity.class)) {
+ this.comparisonDelegate = ComparatorDelegates::compareRarity;
}
} else {
throw new IllegalArgumentException("The field provided is not valid.");