statistics/src/main/java/cz/xelfi/quoridor/statistics/resources/Elo.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 07 Jan 2010 22:34:17 +0100
branchstatistics-and-elo
changeset 178 4b78d4f028b3
child 201 b919d0796fbf
permissions -rw-r--r--
Initial version of statistics and ELO rating. Donated by Martin Rexa
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * The contents of this file are subject to the terms of either the GNU
     5  * General Public License Version 2 only ("GPL") or the Common
     6  * Development and Distribution License("CDDL") (collectively, the
     7  * "License"). You may not use this file except in compliance with the
     8  * License. You can obtain a copy of the License at
     9  * http://www.netbeans.org/cddl-gplv2.html
    10  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    11  * specific language governing permissions and limitations under the
    12  * License.  When distributing the software, include this License Header
    13  * Notice in each file and include the License file at
    14  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    15  * particular file as subject to the "Classpath" exception as provided
    16  * by Sun in the GPL Version 2 section of the License file that
    17  * accompanied this code. If applicable, add the following below the
    18  * License Header, with the fields enclosed by brackets [] replaced by
    19  * your own identifying information:
    20  * "Portions Copyrighted [year] [name of copyright owner]"
    21  *
    22  * Contributor(s):
    23  *
    24  * Portions Copyrighted 2010 Martin Rexa
    25  */
    26 
    27 package cz.xelfi.quoridor.statistics.resources;
    28 
    29 import cz.xelfi.quoridor.statistics.EloList;
    30 import cz.xelfi.quoridor.webidor.Game;
    31 import cz.xelfi.quoridor.webidor.GameId;
    32 import cz.xelfi.quoridor.webidor.GameStatus;
    33 import javax.ws.rs.GET;
    34 import javax.ws.rs.Path;
    35 import javax.ws.rs.PathParam;
    36 import javax.ws.rs.Produces;
    37 import javax.ws.rs.core.MediaType;
    38 
    39 /**
    40  *
    41  * @author Martin Rexa
    42  */
    43 public final class Elo {
    44     private EloList list;
    45 
    46     public Elo(){
    47         list = new EloList();
    48     }
    49 
    50     public void processGame(Game game){
    51         GameId gId = game.getId();
    52         GameStatus status = gId.getStatus();
    53         if(status.equals(GameStatus.whiteWon)){
    54             list.putResult(gId.getWhite(), gId.getBlack());
    55         }else if(status.equals(GameStatus.blackWon)){
    56             list.putResult(gId.getBlack(), gId.getWhite());
    57         }
    58     }
    59 
    60     @GET
    61     @Path("list")
    62     @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
    63     public EloList getList(){
    64         return list;
    65     }
    66 
    67     @GET
    68     @Path("{username}")
    69     @Produces(MediaType.TEXT_PLAIN)
    70     public String getElo(@PathParam("username") String id){
    71         list.getElo(id);
    72         return Double.toString(list.getElo(id));
    73     }
    74 
    75 }