aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/sorting/CardSorting.java
blob: 04413b92c0ca421a22280daaf2c42ff7b8634372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
	}
}