aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/query/Test.java
blob: 646139e6ab3c2559ba1121c46719c1db925a2f50 (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
package eu.equalparts.cardbase.query;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import eu.equalparts.cardbase.data.Card;
import eu.equalparts.cardbase.data.CardSet;

public class Test {
	
//	public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
//		ObjectMapper mapper = new ObjectMapper();
//		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//
//		@SuppressWarnings("unchecked")
//		List<Card> allCards = getAllCards((Map<String, CardSet>) mapper
//				.readValue(new File("AllSets.json"), new TypeReference<Map<String, CardSet>>() {}));
//
//		System.out.println("Number of cards: " + allCards.size());
//	}
//
//	public static List<Card> getAllCards(Map<String, CardSet> sets) {
//		List<Card> allCards = new ArrayList<Card>();
//
//		for (CardSet set : sets.values()) {
//			for (Card card : set.getCards()) {
//				card.setSetCode(set.getCode());
//				card.setSetName(set.getName());
//				// System.out.println(set.getName() + ": " + card.getName());
//
//				allCards.add(card);
//			}
//		}
//
//		return allCards;
//	}
	
	public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

//		@SuppressWarnings("unchecked")
		CardSet set = mapper.readValue(new File("M15.json"), CardSet.class);
		System.out.println(set.getCardByNumber("281").getName());
		
	}

	public static List<Card> getAllCards(Map<String, CardSet> sets) {
		List<Card> allCards = new ArrayList<Card>();

		for (CardSet set : sets.values()) {
			for (Card card : set.getCards()) {
				card.setSetCode(set.getCode());
				card.setSetName(set.getName());
				// System.out.println(set.getName() + ": " + card.getName());

				allCards.add(card);
			}
		}

		return allCards;
	}
}