public CostList(final CostPair... pairs) {
		TreeMap<Resource, Integer> resources = new TreeMap<>();
		for (CostPair pair : pairs) {
			if (pair.getCost() == 0) {
				continue;
			}
			if (resources.containsKey(pair.getResource())) {
				// increment by cost if it already exists
				resources.put(pair.getResource(),
						resources.get(pair.getResource()) + pair.getCost());
			}
			else {
				resources.put(pair.getResource(), pair.getCost());
			}
		}
		ArrayList<CostPair> costList = new ArrayList<>();
		for (Resource res : resources.keySet()) {
			costList.add(new CostPair(resources.get(res), res));
		}
		resources.clear();
		this.costs = (CostPair[]) costList.toArray();
		costList.clear();
	}