aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/cardfield
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/equalparts/cardbase/cardfield')
-rw-r--r--src/eu/equalparts/cardbase/cardfield/CardField.java4
-rw-r--r--src/eu/equalparts/cardbase/cardfield/IntegerCardField.java21
-rw-r--r--src/eu/equalparts/cardbase/cardfield/StringCardField.java14
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();
}
}
}