aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/comparators/CardComparators.java
blob: 99f7ded81d186e6b8bcfce4645df3eb9cc3e8cb0 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package eu.equalparts.cardbase.comparators;

import java.util.Comparator;

import eu.equalparts.cardbase.data.Card;

public final class CardComparators {

	private CardComparators() {}

	public enum Order {
		NATURAL, REVERSE;
	}

	public static class NameComparator implements Comparator<Card> {

		private Order order = Order.NATURAL;

		public NameComparator() {}

		public NameComparator(Order order) {
			this.order = order;
		}

		@Override
		public int compare(Card o1, Card o2) {
			if (order == Order.NATURAL) {
				return o1.name.compareTo(o2.name);
			} else {
				return o2.name.compareTo(o1.name);
			}

		}
	}

	public static class LayoutComparator implements Comparator<Card> {

		private Order order = Order.NATURAL;

		public LayoutComparator() {}

		public LayoutComparator(Order order) {
			this.order = order;
		}

		@Override
		public int compare(Card o1, Card o2) {
			if (order == Order.NATURAL) {
				return o1.layout.compareTo(o2.layout);
			} else {
				return o2.layout.compareTo(o1.layout);
			}
		}
	}

	public static class ManaCostComparator implements Comparator<Card> {

		private Order order = Order.NATURAL;

		public ManaCostComparator() {}

		public ManaCostComparator(Order order) {
			this.order = order;
		}

		@Override
		public int compare(Card o1, Card o2) {
			if (order == Order.NATURAL) {
				return o1.manaCost.compareTo(o2.manaCost);
			} else {
				return o2.manaCost.compareTo(o1.manaCost);
			}
		}
	}

}