aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase
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
parent500fa2144514e7cb23a3072aae9c96acb4424f84 (diff)
Refactoring sorting
Diffstat (limited to 'src/eu/equalparts/cardbase')
-rw-r--r--src/eu/equalparts/cardbase/Cardbase.java3
-rw-r--r--src/eu/equalparts/cardbase/cardstorage/StandaloneCardContainer.java20
-rw-r--r--src/eu/equalparts/cardbase/sorting/CardSorting.java20
3 files changed, 23 insertions, 20 deletions
diff --git a/src/eu/equalparts/cardbase/Cardbase.java b/src/eu/equalparts/cardbase/Cardbase.java
index 10908c8..9c630bd 100644
--- a/src/eu/equalparts/cardbase/Cardbase.java
+++ b/src/eu/equalparts/cardbase/Cardbase.java
@@ -2,10 +2,7 @@ package eu.equalparts.cardbase;
import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
diff --git a/src/eu/equalparts/cardbase/cardstorage/StandaloneCardContainer.java b/src/eu/equalparts/cardbase/cardstorage/StandaloneCardContainer.java
index 1a4315d..53d248d 100644
--- a/src/eu/equalparts/cardbase/cardstorage/StandaloneCardContainer.java
+++ b/src/eu/equalparts/cardbase/cardstorage/StandaloneCardContainer.java
@@ -1,16 +1,13 @@
package eu.equalparts.cardbase.cardstorage;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.equalparts.cardbase.cards.Card;
-import eu.equalparts.cardbase.comparator.CardComparator;
/**
* TODO fix comments
@@ -46,19 +43,8 @@ public class StandaloneCardContainer extends ReferenceCardContainer {
*
* @return an unmodifiable list of all the cards in the cardbase.
*/
- public Collection<Card> getCards() {
- return Collections.unmodifiableCollection(cardData.values());
- }
-
- /**
- * @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 Collection<Card> sortByField(String fieldName) throws NoSuchFieldException {
- List<Card> sortedCards = new ArrayList<Card>(getCards());
- sortedCards.sort(new CardComparator(Card.class.getDeclaredField(fieldName)));
- return Collections.unmodifiableCollection(sortedCards);
+ public List<Card> getCards() {
+ return new LinkedList<Card>(cardData.values());
}
@Override
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;
+ }
+}