/*
	cursus - Race series management program
	Copyright 2011  Simon Arlott

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package eu.lp0.cursus.scoring;

import java.util.Map.Entry;
import java.util.Set;

import eu.lp0.cursus.db.data.Pilot;
import eu.lp0.cursus.db.data.Race;

public class GenericOverallPointsData<T extends ScoredData & RacePointsData & RaceDiscardsData & OverallPenaltiesData> extends AbstractOverallPointsData<T> {
	public GenericOverallPointsData(T scores) {
		super(scores);
	}

	@Override
	protected int calculateOverallPoints(Pilot pilot) {
		int points = 0;

		Set<Race> discardedRaces = scores.getDiscardedRaces(pilot);

		// Add race points but not discards
		for (Entry<Race, Integer> racePoints : scores.getRacePoints(pilot).entrySet()) {
			if (!discardedRaces.contains(racePoints.getKey())) {
				points += racePoints.getValue();
			}
		}

		// Add all penalties (this includes race penalties)
		points += scores.getOverallPenalties(pilot);
		if (points < 0) {
			points = 0;
		}

		return points;
	}
}
@@ -758,28 +758,88 @@
 ry;%0A
+%0A
 import 
-java.util.Set
+com.google.common.base.Predicates;%0Aimport com.google.common.collect.Maps
 ;%0A%0Ai
@@ -1220,71 +1220,8 @@
 0;%0A%0A
-%09%09Set%3CRace%3E discardedRaces = scores.getDiscardedRaces(pilot);%0A%0A
 %09%09//
@@ -1295,16 +1295,32 @@
 oints : 
+Maps.filterKeys(
 scores.g
@@ -1342,80 +1342,93 @@
 lot)
-.entrySet()) %7B%0A%09%09%09if (!discardedRaces.contains(racePoints.getKey()
+, Predicates.not(Predicates.in(scores.getDiscardedRaces(pilot))))%0A%09%09%09%09.entrySet(
 )) %7B%0A
-%09
 %09%09%09p
@@ -1463,13 +1463,8 @@
 ();%0A
-%09%09%09%7D%0A
 %09%09%7D%0A

simplify using a filter