aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/sorting
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2016-06-12 21:03:29 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2016-06-12 21:03:29 +0200
commit64c8e926d167a17865a6c3d86e48b383d413b569 (patch)
treebb218b11736d57dbb18c52abaa0660cbe8bf0487 /src/eu/equalparts/cardbase/sorting
parent500fa2144514e7cb23a3072aae9c96acb4424f84 (diff)
Refactoring sorting
Diffstat (limited to 'src/eu/equalparts/cardbase/sorting')
-rw-r--r--src/eu/equalparts/cardbase/sorting/CardSorting.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/eu/equalparts/cardbase/sorting/CardSorting.java b/src/eu/equalparts/cardbase/sorting/CardSorting.java
new file mode 100644
index 0000000..04413b9
--- /dev/null
+++ b/src/eu/equalparts/cardbase/sorting/CardSorting.java
@@ -0,0 +1,20 @@
+package eu.equalparts.cardbase.sorting;
+
+import java.util.List;
+
+import eu.equalparts.cardbase.cards.Card;
+import eu.equalparts.cardbase.comparator.CardComparator;
+
+public abstract class CardSorting {
+
+ /**
+ * @param cards
+ * @param fieldName the name of the field by which to sort.
+ * @return an unmodifiable collection representing the cardbase sorted in the required order.
+ * @throws NoSuchFieldException if the field provided is invalid.
+ */
+ public static List<Card> sortByField(List<Card> cards, String fieldName) throws NoSuchFieldException {
+ cards.sort(new CardComparator(Card.class.getDeclaredField(fieldName)));
+ return cards;
+ }
+}