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/cardfield/CardField.java | 4 ++-- .../cardbase/cardfield/IntegerCardField.java | 21 ++++++++------------- .../cardbase/cardfield/StringCardField.java | 14 +++++++------- 3 files changed, 17 insertions(+), 22 deletions(-) (limited to 'src/eu/equalparts/cardbase/cardfield') diff --git a/src/eu/equalparts/cardbase/cardfield/CardField.java b/src/eu/equalparts/cardbase/cardfield/CardField.java index 9af775b..e088577 100644 --- a/src/eu/equalparts/cardbase/cardfield/CardField.java +++ b/src/eu/equalparts/cardbase/cardfield/CardField.java @@ -1,5 +1,5 @@ package eu.equalparts.cardbase.cardfield; -import eu.equalparts.cardbase.filtering.CardFiltering.Filter; +import eu.equalparts.cardbase.filtering.Filter; public abstract class CardField> implements Comparable> { private String name; @@ -27,5 +27,5 @@ public abstract class CardField> implements Comparable { @@ -9,22 +8,18 @@ public class IntegerCardField extends CardField { } @Override - public boolean filter(Filter filter, String s) { - switch (filter) { + public boolean filter(Filter filter) throws NumberFormatException { + switch (filter.type) { case CONTAINS: - return get().toString().contains(s); + return get().toString().contains(filter.value); case EQUALS: - return get().toString().equalsIgnoreCase(s); + return get().toString().equalsIgnoreCase(filter.value); case REGEX: - return get().toString().matches(s); + return get().toString().matches(filter.value); case GREATER_THAN: - if (InputSanity.isInteger(s)) { - return get() > Integer.valueOf(s); - } + return get() > Integer.parseInt(filter.value); case SMALLER_THAN: - if (InputSanity.isInteger(s)) { - return get() < Integer.valueOf(s); - } + return get() < Integer.parseInt(filter.value); default: return false; } diff --git a/src/eu/equalparts/cardbase/cardfield/StringCardField.java b/src/eu/equalparts/cardbase/cardfield/StringCardField.java index 059a45d..8239138 100644 --- a/src/eu/equalparts/cardbase/cardfield/StringCardField.java +++ b/src/eu/equalparts/cardbase/cardfield/StringCardField.java @@ -1,5 +1,5 @@ package eu.equalparts.cardbase.cardfield; -import eu.equalparts.cardbase.filtering.CardFiltering.Filter; +import eu.equalparts.cardbase.filtering.Filter; public class StringCardField extends CardField { @@ -8,16 +8,16 @@ public class StringCardField extends CardField { } @Override - public boolean filter(Filter filter, String s) { - switch (filter) { + public boolean filter(Filter filter) { + switch (filter.type) { case CONTAINS: - return get().toLowerCase().contains(s.toLowerCase()); + return get().toLowerCase().contains(filter.value.toLowerCase()); case EQUALS: - return get().equalsIgnoreCase(s); + return get().equalsIgnoreCase(filter.value); case REGEX: - return get().matches(s); + return get().matches(filter.value); default: - return false; + throw new IllegalArgumentException(); } } } -- cgit v1.2.3