<commit_before>package models;

import com.avaje.ebean.Ebean;
import com.google.common.base.Predicate;
import play.db.ebean.Model;

import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static com.google.common.collect.Collections2.filter;
import static models.Scores.keepBestScoresForEachPlayer;

@Entity
public class Game extends BaseModel<Game> {

    public String cover;

    public String title;

    public String thread;

    @OneToMany(mappedBy = "game")
    public List<Score> scores;

    @OrderBy("name")
    @OneToMany(mappedBy = "game")
    public List<Platform> platforms;

    @OneToMany(mappedBy = "game")
    public List<Difficulty> difficulties;

    @OneToMany(mappedBy = "game")
    public List<Mode> modes;

    @OneToMany(mappedBy = "game")
    public List<Stage> stages;

    public static Finder<Long, Game> finder = new Model.Finder(Long.class, Game.class);

    public Game(String title, String cover, String thread) {
        this.title = title;
        this.cover = cover;
        this.thread = thread;
    }

    public Collection<Score> scores(final Difficulty difficulty, final Mode mode) {
        if (scores == null) {
            return new ArrayList<Score>();
        }
        return filter(scores, new Predicate<Score>() {
            @Override
            public boolean apply(@Nullable Score score) {
                return (difficulty == null || score.concerns(difficulty)) && (mode == null || score.concerns(mode));
            }
        });
    }

    public Collection<Score> bestScoresByPlayers(final Difficulty difficulty, final Mode mode) {
        if (scores == null) {
            return new ArrayList<Score>();
        }
        return keepBestScoresForEachPlayer(filterBy(difficulty, mode));
    }

    public Collection<Score> bestScores() {
        List<Score> bestScores = new ArrayList<Score>();
        if (scores == null) {
            return bestScores;
        }
        for (final Difficulty difficulty : difficulties) {
            for (final Mode mode : modes) {
                bestScores.addAll(keepBestScoresForEachPlayer(filterBy(difficulty, mode)));
            }
        }
        return bestScores;
    }

    private List<Score> filterBy(final Difficulty difficulty, final Mode mode) {
        return new ArrayList<Score>(filter(scores, new Predicate<Score>() {
            @Override
            public boolean apply(@Nullable Score score) {
                return (difficulty == null || score.concerns(difficulty)) && (mode == null || score.concerns(mode));
            }
        }));
    }

    public String post() {
        return thread.replace("viewtopic.php?", "posting.php?mode=reply&");
    }

    @Override
    public String toString() {
        return title;
    }<commit_msg>Bug fix sur le comptage de score pour les jeux sans Modes<commit_after>package models;

import com.avaje.ebean.Ebean;
import com.google.common.base.Predicate;
import play.db.ebean.Model;

import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static com.google.common.collect.Collections2.filter;
import static models.Scores.keepBestScoresForEachGame;
import static models.Scores.keepBestScoresForEachPlayer;

@Entity
public class Game extends BaseModel<Game> {

    public String cover;

    public String title;

    public String thread;

    @OneToMany(mappedBy = "game")
    public List<Score> scores;

    @OrderBy("name")
    @OneToMany(mappedBy = "game")
    public List<Platform> platforms;

    @OneToMany(mappedBy = "game")
    public List<Difficulty> difficulties;

    @OneToMany(mappedBy = "game")
    public List<Mode> modes;

    @OneToMany(mappedBy = "game")
    public List<Stage> stages;

    public static Finder<Long, Game> finder = new Model.Finder(Long.class, Game.class);

    public Game(String title, String cover, String thread) {
        this.title = title;
        this.cover = cover;
        this.thread = thread;
    }

    public Collection<Score> scores(final Difficulty difficulty, final Mode mode) {
        if (scores == null) {
            return new ArrayList<Score>();
        }
        return filter(scores, new Predicate<Score>() {
            @Override
            public boolean apply(@Nullable Score score) {
                return (difficulty == null || score.concerns(difficulty)) && (mode == null || score.concerns(mode));
            }
        });
    }

    public Collection<Score> bestScoresByPlayers(final Difficulty difficulty, final Mode mode) {
        if (scores == null) {
            return new ArrayList<Score>();
        }
        return keepBestScoresForEachPlayer(filterBy(difficulty, mode));
    }

    public Collection<Score> bestScores() {
        List<Score> bestScores = new ArrayList<Score>();
        if (scores == null) {
            return bestScores;
        }
        for (final Difficulty difficulty : difficulties) {
            if(modes.isEmpty()) {
                bestScores.addAll(keepBestScoresForEachPlayer(filterBy(difficulty)));
            } else {
                for (final Mode mode : modes) {
                    bestScores.addAll(keepBestScoresForEachPlayer(filterBy(difficulty, mode)));
                }
            }
        }
        return bestScores;
    }

    private List<Score> filterBy(final Difficulty difficulty, final Mode mode) {
        return new ArrayList<Score>(filter(scores, new Predicate<Score>() {
            @Override
            public boolean apply(@Nullable Score score) {
                return (difficulty == null || score.concerns(difficulty)) && (mode == null || score.concerns(mode));
            }
        }));
    }

    private List<Score> filterBy(final Difficulty difficulty) {
        return new ArrayList<Score>(filter(scores, new Predicate<Score>() {
            @Override
            public boolean apply(@Nullable Score score) {
                return (difficulty == null || score.concerns(difficulty));
            }
        }));
    }

    public String post() {
        return thread.replace("viewtopic.php?", "posting.php?mode=reply&");
    }

    @Override
    public String toString() {
        return title;
    }
{'fraction_non_alphanumeric': 0.10882033793210355, 'fraction_numerical': 0.0003100294527980158, 'mean_word_length': 2.6575963718820863, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2840011', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1767, 'n_words': 441}