wsdor/src/main/java/cz/xelfi/quoridor/webidor/CommentedMove.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 09:46:43 +0200
changeset 266 15fcdfc4cd4a
parent 256 1758a7727278
permissions -rw-r--r--
Using maven-license-plugin and updating all missing headers
     1 /**
     2  * Quoridor server and related libraries
     3  * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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/.
    17  */
    18 
    19 package cz.xelfi.quoridor.webidor;
    20 
    21 import cz.xelfi.quoridor.IllegalPositionException;
    22 import cz.xelfi.quoridor.Move;
    23 import java.util.ArrayList;
    24 import java.util.List;
    25 import javax.xml.bind.annotation.XmlAttribute;
    26 import javax.xml.bind.annotation.XmlElement;
    27 
    28 public final class CommentedMove {
    29     Move move;
    30     int index;
    31     List<Note> comments;
    32 
    33     private CommentedMove() {
    34         super();
    35     }
    36 
    37     CommentedMove(Move move, int index) {
    38         super();
    39         this.move = move;
    40         this.index = index;
    41     }
    42 
    43     public Move getMove() {
    44         return move;
    45     }
    46 
    47     @XmlAttribute(name="move")
    48     String getMoveText() {
    49         return move.toString();
    50     }
    51 
    52     void setMoveText(String m) throws IllegalPositionException {
    53         move = Move.valueOf(m);
    54     }
    55     
    56     @XmlAttribute
    57     int getIndex() {
    58         return index;
    59     }
    60 
    61     void setIndex(int i) {
    62         index = i;
    63     }
    64 
    65     void addNote(Note n) {
    66         if (comments == null) {
    67             comments = new ArrayList<Note>();
    68         }
    69         comments.add(n);
    70     }
    71 
    72     @XmlElement(name="comment", required=false)
    73     public final List<Note> getComments() {
    74         return comments;
    75     }
    76 
    77     final void setComments(List<Note> l) {
    78         this.comments = l;
    79     }
    80 
    81     @Override
    82     public String toString() {
    83         StringBuilder sb = new StringBuilder();
    84         sb.append("Move[").append(move).append("@").append(index);
    85         if (comments != null) {
    86             sb.append(", ");
    87             sb.append(comments);
    88         }
    89         sb.append("]");
    90         return sb.toString();
    91     }
    92 
    93     @Override
    94     public boolean equals(Object obj) {
    95         if (obj == null) {
    96             return false;
    97         }
    98         if (getClass() != obj.getClass()) {
    99             return false;
   100         }
   101         final CommentedMove other = (CommentedMove) obj;
   102         if (this.move != other.move && (this.move == null || !this.move.equals(other.move))) {
   103             return false;
   104         }
   105         if (this.index != other.index) {
   106             return false;
   107         }
   108         if (this.comments != other.comments && (this.comments == null || !this.comments.equals(other.comments))) {
   109             return false;
   110         }
   111         return true;
   112     }
   113 
   114     @Override
   115     public int hashCode() {
   116         int hash = 5;
   117         hash = 43 * hash + (this.move != null ? this.move.hashCode() : 0);
   118         hash = 43 * hash + this.index;
   119         hash = 43 * hash + (this.comments != null ? this.comments.hashCode() : 0);
   120         return hash;
   121     }
   122 }