statistics/src/main/java/cz/xelfi/quoridor/statistics/EloEntry.java
branchstatistics-and-elo
changeset 178 4b78d4f028b3
child 264 d60370059c3c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/statistics/src/main/java/cz/xelfi/quoridor/statistics/EloEntry.java	Thu Jan 07 22:34:17 2010 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +/*
     1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 + *
     1.7 + * The contents of this file are subject to the terms of either the GNU
     1.8 + * General Public License Version 2 only ("GPL") or the Common
     1.9 + * Development and Distribution License("CDDL") (collectively, the
    1.10 + * "License"). You may not use this file except in compliance with the
    1.11 + * License. You can obtain a copy of the License at
    1.12 + * http://www.netbeans.org/cddl-gplv2.html
    1.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.14 + * specific language governing permissions and limitations under the
    1.15 + * License.  When distributing the software, include this License Header
    1.16 + * Notice in each file and include the License file at
    1.17 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    1.18 + * particular file as subject to the "Classpath" exception as provided
    1.19 + * by Sun in the GPL Version 2 section of the License file that
    1.20 + * accompanied this code. If applicable, add the following below the
    1.21 + * License Header, with the fields enclosed by brackets [] replaced by
    1.22 + * your own identifying information:
    1.23 + * "Portions Copyrighted [year] [name of copyright owner]"
    1.24 + *
    1.25 + * Contributor(s):
    1.26 + *
    1.27 + * Portions Copyrighted 2010 Martin Rexa
    1.28 + */
    1.29 +
    1.30 +package cz.xelfi.quoridor.statistics;
    1.31 +
    1.32 +import javax.xml.bind.annotation.XmlAttribute;
    1.33 +import java.util.Comparator;
    1.34 +/**
    1.35 + *
    1.36 + * @author Martin Rexa
    1.37 + */
    1.38 +public class EloEntry {
    1.39 +    String player;
    1.40 +    double elo;
    1.41 +    int games;
    1.42 +
    1.43 +    public static final Comparator<EloEntry> BEST_FIRST = new BestFirst();
    1.44 +
    1.45 +    EloEntry(){
    1.46 +        super();
    1.47 +    }
    1.48 +
    1.49 +    EloEntry(String player, double elo, int games){
    1.50 +        super();
    1.51 +        this.player = player;
    1.52 +        this.elo = elo;
    1.53 +        this.games = games;
    1.54 +    }
    1.55 +
    1.56 +    @XmlAttribute
    1.57 +    public String getPlayer(){
    1.58 +        return player;
    1.59 +    }
    1.60 +
    1.61 +    @XmlAttribute
    1.62 +    public Double getElo(){
    1.63 +        return elo;
    1.64 +    }
    1.65 +
    1.66 +    @XmlAttribute
    1.67 +    public Integer getGames(){
    1.68 +        return games;
    1.69 +    }
    1.70 +
    1.71 +    public String toString(){
    1.72 +        return "Player: " + player + ", ELO: " + elo + ", Games: " + games;
    1.73 +    }
    1.74 +
    1.75 +    private static final class BestFirst implements Comparator<EloEntry> {
    1.76 +        public int compare(EloEntry e1, EloEntry e2) {
    1.77 +            if(e1.elo > e2.elo)
    1.78 +                return -1;
    1.79 +            else if(e1.elo < e2.elo)
    1.80 +                return 1;
    1.81 +            else return e1.player.compareTo(e2.player);
    1.82 +        }
    1.83 +    }
    1.84 +
    1.85 +}