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.java31
-rw-r--r--src/eu/equalparts/cardbase/cardfield/IntegerCardField.java23
-rw-r--r--src/eu/equalparts/cardbase/cardfield/StringCardField.java23
3 files changed, 77 insertions, 0 deletions
diff --git a/src/eu/equalparts/cardbase/cardfield/CardField.java b/src/eu/equalparts/cardbase/cardfield/CardField.java
new file mode 100644
index 0000000..9af775b
--- /dev/null
+++ b/src/eu/equalparts/cardbase/cardfield/CardField.java
@@ -0,0 +1,31 @@
+package eu.equalparts.cardbase.cardfield;
+import eu.equalparts.cardbase.filtering.CardFiltering.Filter;
+
+public abstract class CardField<T extends Comparable<T>> implements Comparable<CardField<T>> {
+ private String name;
+ private T value;
+
+ public CardField(String name, T value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public T get() {
+ return value;
+ }
+
+ public void set(T newValue) {
+ this.value = newValue;
+ }
+
+ @Override
+ public int compareTo(CardField<T> o) {
+ return value.compareTo(o.get());
+ }
+
+ public abstract boolean filter(Filter filter, String s);
+}
diff --git a/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java b/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java
new file mode 100644
index 0000000..4016252
--- /dev/null
+++ b/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java
@@ -0,0 +1,23 @@
+package eu.equalparts.cardbase.cardfield;
+import eu.equalparts.cardbase.filtering.CardFiltering.Filter;
+
+public class IntegerCardField extends CardField<Integer> {
+
+ public IntegerCardField(String name, Integer value) {
+ super(name, value);
+ }
+
+ @Override
+ public boolean filter(Filter filter, String s) {
+ switch (filter) {
+ case CONTAINS:
+ return get().toString().contains(s);
+ case EQUALS:
+ return get().toString().equalsIgnoreCase(s);
+ case REGEX:
+ return get().toString().matches(s);
+ default:
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/eu/equalparts/cardbase/cardfield/StringCardField.java b/src/eu/equalparts/cardbase/cardfield/StringCardField.java
new file mode 100644
index 0000000..059a45d
--- /dev/null
+++ b/src/eu/equalparts/cardbase/cardfield/StringCardField.java
@@ -0,0 +1,23 @@
+package eu.equalparts.cardbase.cardfield;
+import eu.equalparts.cardbase.filtering.CardFiltering.Filter;
+
+public class StringCardField extends CardField<String> {
+
+ public StringCardField(String name, String value) {
+ super(name, value);
+ }
+
+ @Override
+ public boolean filter(Filter filter, String s) {
+ switch (filter) {
+ case CONTAINS:
+ return get().toLowerCase().contains(s.toLowerCase());
+ case EQUALS:
+ return get().equalsIgnoreCase(s);
+ case REGEX:
+ return get().matches(s);
+ default:
+ return false;
+ }
+ }
+}