aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/cardfield/IntegerCardField.java
blob: 604880aede589d11906fe7c404398a9f048ae189 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package eu.equalparts.cardbase.cardfield;
import eu.equalparts.cardbase.filtering.Filter;

public class IntegerCardField extends CardField<Integer> {

	public IntegerCardField(String name, Integer value) {
		super(name, value);
	}

	@Override
	public boolean filter(Filter filter) throws NumberFormatException {
		if (get() != null) {
			switch (filter.type) {
			case CONTAINS:
				return get().toString().contains(filter.value);
			case EQUALS:
				return get().toString().equalsIgnoreCase(filter.value);
			case REGEX:
				return get().toString().matches(filter.value);
			case GREATER_THAN:
				return get() > Integer.parseInt(filter.value);
			case SMALLER_THAN:
				return get() < Integer.parseInt(filter.value);
			default:
				return false;
			}
		} else {
			return false;
		}
	}
}