From 8cb35b358563e5a81ad9e4aceb123b85222cf4cc Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 14 Aug 2016 18:09:22 +0200 Subject: Implemented some more filtering tests, sorted out validation and exceptions --- src/eu/equalparts/cardbase/comparator/CardComparator.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/eu/equalparts/cardbase/comparator') 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 { 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."); -- cgit v1.2.3