statistics/src/main/java/cz/xelfi/quoridor/statistics/EloEntry.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 178 4b78d4f028b3
permissions -rw-r--r--
Changing headers to GPLv3
jaroslav@178
     1
/*
jaroslav@264
     2
 * Quoridor server and related libraries
jaroslav@264
     3
 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@178
     4
 *
jaroslav@264
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@264
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@264
     7
 * the Free Software Foundation, either version 3 of the License.
jaroslav@178
     8
 *
jaroslav@264
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@264
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@264
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@264
    12
 * GNU General Public License for more details.
jaroslav@178
    13
 *
jaroslav@264
    14
 * You should have received a copy of the GNU General Public License
jaroslav@264
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@264
    16
 * If not, see http://www.gnu.org/licenses/.
jaroslav@178
    17
 */
jaroslav@178
    18
package cz.xelfi.quoridor.statistics;
jaroslav@178
    19
jaroslav@178
    20
import javax.xml.bind.annotation.XmlAttribute;
jaroslav@178
    21
import java.util.Comparator;
jaroslav@178
    22
/**
jaroslav@178
    23
 *
jaroslav@178
    24
 * @author Martin Rexa
jaroslav@178
    25
 */
jaroslav@178
    26
public class EloEntry {
jaroslav@178
    27
    String player;
jaroslav@178
    28
    double elo;
jaroslav@178
    29
    int games;
jaroslav@178
    30
jaroslav@178
    31
    public static final Comparator<EloEntry> BEST_FIRST = new BestFirst();
jaroslav@178
    32
jaroslav@178
    33
    EloEntry(){
jaroslav@178
    34
        super();
jaroslav@178
    35
    }
jaroslav@178
    36
jaroslav@178
    37
    EloEntry(String player, double elo, int games){
jaroslav@178
    38
        super();
jaroslav@178
    39
        this.player = player;
jaroslav@178
    40
        this.elo = elo;
jaroslav@178
    41
        this.games = games;
jaroslav@178
    42
    }
jaroslav@178
    43
jaroslav@178
    44
    @XmlAttribute
jaroslav@178
    45
    public String getPlayer(){
jaroslav@178
    46
        return player;
jaroslav@178
    47
    }
jaroslav@178
    48
jaroslav@178
    49
    @XmlAttribute
jaroslav@178
    50
    public Double getElo(){
jaroslav@178
    51
        return elo;
jaroslav@178
    52
    }
jaroslav@178
    53
jaroslav@178
    54
    @XmlAttribute
jaroslav@178
    55
    public Integer getGames(){
jaroslav@178
    56
        return games;
jaroslav@178
    57
    }
jaroslav@178
    58
jaroslav@178
    59
    public String toString(){
jaroslav@178
    60
        return "Player: " + player + ", ELO: " + elo + ", Games: " + games;
jaroslav@178
    61
    }
jaroslav@178
    62
jaroslav@178
    63
    private static final class BestFirst implements Comparator<EloEntry> {
jaroslav@178
    64
        public int compare(EloEntry e1, EloEntry e2) {
jaroslav@178
    65
            if(e1.elo > e2.elo)
jaroslav@178
    66
                return -1;
jaroslav@178
    67
            else if(e1.elo < e2.elo)
jaroslav@178
    68
                return 1;
jaroslav@178
    69
            else return e1.player.compareTo(e2.player);
jaroslav@178
    70
        }
jaroslav@178
    71
    }
jaroslav@178
    72
jaroslav@178
    73
}