diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-08-14 18:09:22 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-08-14 18:09:22 +0200 |
commit | 8cb35b358563e5a81ad9e4aceb123b85222cf4cc (patch) | |
tree | 0d73eebfe29e7d90d4e0d6c5d40a36db75de3fdc /src/eu/equalparts/cardbase/cardfield | |
parent | 78e369043f95e78b27c265f7eab4d766e54054f4 (diff) |
Implemented some more filtering tests, sorted out validation and exceptions
Diffstat (limited to 'src/eu/equalparts/cardbase/cardfield')
3 files changed, 17 insertions, 22 deletions
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<T extends Comparable<T>> implements Comparable<CardField<T>> { private String name; @@ -27,5 +27,5 @@ public abstract class CardField<T extends Comparable<T>> implements Comparable<C return value.compareTo(o.get()); } - public abstract boolean filter(Filter filter, String s); + public abstract boolean filter(Filter filter); } diff --git a/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java b/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java index 3ee10e7..8526640 100644 --- a/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java +++ b/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java @@ -1,6 +1,5 @@ package eu.equalparts.cardbase.cardfield; -import eu.equalparts.cardbase.filtering.CardFiltering.Filter; -import eu.equalparts.cardbase.utils.InputSanity; +import eu.equalparts.cardbase.filtering.Filter; public class IntegerCardField extends CardField<Integer> { @@ -9,22 +8,18 @@ public class IntegerCardField extends CardField<Integer> { } @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<String> { @@ -8,16 +8,16 @@ public class StringCardField extends CardField<String> { } @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(); } } } |