diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-08-11 23:59:10 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-08-11 23:59:10 +0200 |
commit | c07d860f1d90dc3961b31c87dbe637dbcd87da76 (patch) | |
tree | e31997581287fd5d021aebc60ea7c5ad08539bbc /src/eu/equalparts/cardbase/cardfield | |
parent | f7fe057b745d3f0e19b5dd6bd1819b11fc89c551 (diff) |
Refactored the Card data structure to be able to do filtering properly
Diffstat (limited to 'src/eu/equalparts/cardbase/cardfield')
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; + } + } +} |