webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java
author Jaroslav Tulach <jtulach@netbeans.org>
Fri, 11 Sep 2009 22:25:21 +0200
changeset 78 5ea4172dcf8b
parent 77 d574ac6e44cc
child 96 2eeaa41236c3
permissions -rw-r--r--
Showing the time that has passed since the last move on the board
jaroslav@48
     1
/*
jaroslav@48
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jaroslav@48
     3
 *
jaroslav@48
     4
 * The contents of this file are subject to the terms of either the GNU
jaroslav@48
     5
 * General Public License Version 2 only ("GPL") or the Common
jaroslav@48
     6
 * Development and Distribution License("CDDL") (collectively, the
jaroslav@48
     7
 * "License"). You may not use this file except in compliance with the
jaroslav@48
     8
 * License. You can obtain a copy of the License at
jaroslav@48
     9
 * http://www.netbeans.org/cddl-gplv2.html
jaroslav@48
    10
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jaroslav@48
    11
 * specific language governing permissions and limitations under the
jaroslav@48
    12
 * License.  When distributing the software, include this License Header
jaroslav@48
    13
 * Notice in each file and include the License file at
jaroslav@48
    14
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
jaroslav@48
    15
 * particular file as subject to the "Classpath" exception as provided
jaroslav@48
    16
 * by Sun in the GPL Version 2 section of the License file that
jaroslav@48
    17
 * accompanied this code. If applicable, add the following below the
jaroslav@48
    18
 * License Header, with the fields enclosed by brackets [] replaced by
jaroslav@48
    19
 * your own identifying information:
jaroslav@48
    20
 * "Portions Copyrighted [year] [name of copyright owner]"
jaroslav@48
    21
 *
jaroslav@48
    22
 * Contributor(s):
jaroslav@48
    23
 *
jaroslav@48
    24
 * Portions Copyrighted 2009 Jaroslav Tulach
jaroslav@48
    25
 */
jaroslav@48
    26
jaroslav@48
    27
package cz.xelfi.quoridor.webidor;
jaroslav@48
    28
jaroslav@48
    29
import java.util.Date;
jaroslav@48
    30
import java.util.UUID;
jaroslav@48
    31
import javax.xml.bind.annotation.XmlAccessType;
jaroslav@48
    32
import javax.xml.bind.annotation.XmlAccessorType;
jaroslav@48
    33
import javax.xml.bind.annotation.XmlAttribute;
jaroslav@48
    34
import javax.xml.bind.annotation.XmlID;
jaroslav@48
    35
import javax.xml.bind.annotation.XmlRootElement;
jaroslav@48
    36
jaroslav@48
    37
/** Basic identification of a game.
jaroslav@48
    38
 *
jaroslav@48
    39
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@48
    40
 */
jaroslav@48
    41
@XmlRootElement
jaroslav@48
    42
@XmlAccessorType(XmlAccessType.FIELD)
jaroslav@48
    43
public class GameId {
jaroslav@48
    44
    @XmlAttribute
jaroslav@48
    45
    private String white;
jaroslav@48
    46
    @XmlAttribute
jaroslav@48
    47
    private String black;
jaroslav@48
    48
    @XmlAttribute
jtulach@78
    49
    private long started;
jtulach@78
    50
    @XmlAttribute
jtulach@78
    51
    private long modified;
jaroslav@48
    52
    @XmlAttribute
jtulach@77
    53
    private GameStatus status;
jtulach@54
    54
    @XmlID @XmlAttribute
jaroslav@48
    55
    private String id;
jaroslav@48
    56
jaroslav@48
    57
    GameId() {
jaroslav@48
    58
    }
jaroslav@48
    59
jaroslav@48
    60
    public GameId(String first, String second) {
jtulach@78
    61
        this(first, second, new Date());
jtulach@78
    62
    }
jtulach@78
    63
    private GameId(String first, String second, Date d) {
jaroslav@48
    64
        this(
jaroslav@48
    65
            UUID.randomUUID().toString(),
jtulach@78
    66
            first, second, d, d, GameStatus.whiteMove
jaroslav@48
    67
        );
jaroslav@48
    68
    }
jaroslav@48
    69
jtulach@78
    70
    public GameId(String id, String first, String second, Date started, Date last, GameStatus result) {
jaroslav@48
    71
        this.white = first;
jaroslav@48
    72
        this.black = second;
jaroslav@48
    73
        this.id = id;
jtulach@78
    74
        this.started = started.getTime();
jtulach@78
    75
        this.modified = last.getTime();
jtulach@77
    76
        this.status = result;
jaroslav@48
    77
    }
jaroslav@48
    78
jaroslav@48
    79
    public String getId() {
jaroslav@48
    80
        return id;
jaroslav@48
    81
    }
jaroslav@48
    82
jaroslav@48
    83
    public String getWhite() {
jaroslav@48
    84
        return white;
jaroslav@48
    85
    }
jaroslav@48
    86
jaroslav@48
    87
    public String getBlack() {
jaroslav@48
    88
        return black;
jaroslav@48
    89
    }
jaroslav@48
    90
jtulach@78
    91
    public long getStarted() {
jaroslav@48
    92
        return started;
jaroslav@48
    93
    }
jaroslav@48
    94
jtulach@78
    95
    public long getModified() {
jtulach@78
    96
        return modified;
jtulach@78
    97
    }
jtulach@78
    98
jtulach@77
    99
    public GameStatus getStatus() {
jtulach@77
   100
        return status;
jaroslav@48
   101
    }
jaroslav@48
   102
}