2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
19 package cz.xelfi.quoridor.webidor;
21 import java.util.Comparator;
22 import java.util.Date;
23 import java.util.UUID;
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlAttribute;
27 import javax.xml.bind.annotation.XmlID;
28 import javax.xml.bind.annotation.XmlRootElement;
30 /** Basic identification of a game.
32 * @author Jaroslav Tulach <jtulach@netbeans.org>
35 @XmlAccessorType(XmlAccessType.FIELD)
37 public static final Comparator<GameId> NEWEST_FIRST = new NewestFirst();
46 private long modified;
48 private GameStatus status;
54 private boolean finished;
59 public GameId(String first, String second) {
60 this(first, second, new Date());
62 private GameId(String first, String second, Date d) {
64 UUID.randomUUID().toString(),
65 first, second, d, d, GameStatus.whiteMove, 0, false
70 String id, String first, String second,
71 Date started, Date last, GameStatus result,
72 int comments, boolean finished
77 this.started = started.getTime();
78 this.modified = last.getTime();
80 this.comments = comments;
81 this.finished = finished;
84 public String getId() {
88 public String getWhite() {
92 public String getBlack() {
96 public long getStarted() {
100 public long getModified() {
104 public GameStatus getStatus() {
108 public int getComments() {
112 public boolean isFinished() {
116 private static final class NewestFirst implements Comparator<GameId> {
117 public int compare(GameId o1, GameId o2) {
121 long diff = o2.getModified() - o1.getModified();
123 return diff < 0 ? -1 : 1;
125 return o1.getId().compareTo(o2.getId());