wsdor/src/main/java/cz/xelfi/quoridor/webidor/CommentedMove.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Sep 2010 17:04:51 +0200
changeset 256 1758a7727278
parent 115 webidor/src/main/java/cz/xelfi/quoridor/webidor/CommentedMove.java@6a80463a74c0
child 266 15fcdfc4cd4a
permissions -rw-r--r--
Splitting classes representing data types on the server into own module
     1 package cz.xelfi.quoridor.webidor;
     2 
     3 import cz.xelfi.quoridor.IllegalPositionException;
     4 import cz.xelfi.quoridor.Move;
     5 import java.util.ArrayList;
     6 import java.util.List;
     7 import javax.xml.bind.annotation.XmlAttribute;
     8 import javax.xml.bind.annotation.XmlElement;
     9 
    10 public final class CommentedMove {
    11     Move move;
    12     int index;
    13     List<Note> comments;
    14 
    15     private CommentedMove() {
    16         super();
    17     }
    18 
    19     CommentedMove(Move move, int index) {
    20         super();
    21         this.move = move;
    22         this.index = index;
    23     }
    24 
    25     public Move getMove() {
    26         return move;
    27     }
    28 
    29     @XmlAttribute(name="move")
    30     String getMoveText() {
    31         return move.toString();
    32     }
    33 
    34     void setMoveText(String m) throws IllegalPositionException {
    35         move = Move.valueOf(m);
    36     }
    37     
    38     @XmlAttribute
    39     int getIndex() {
    40         return index;
    41     }
    42 
    43     void setIndex(int i) {
    44         index = i;
    45     }
    46 
    47     void addNote(Note n) {
    48         if (comments == null) {
    49             comments = new ArrayList<Note>();
    50         }
    51         comments.add(n);
    52     }
    53 
    54     @XmlElement(name="comment", required=false)
    55     public final List<Note> getComments() {
    56         return comments;
    57     }
    58 
    59     final void setComments(List<Note> l) {
    60         this.comments = l;
    61     }
    62 
    63     @Override
    64     public String toString() {
    65         StringBuilder sb = new StringBuilder();
    66         sb.append("Move[").append(move).append("@").append(index);
    67         if (comments != null) {
    68             sb.append(", ");
    69             sb.append(comments);
    70         }
    71         sb.append("]");
    72         return sb.toString();
    73     }
    74 
    75     @Override
    76     public boolean equals(Object obj) {
    77         if (obj == null) {
    78             return false;
    79         }
    80         if (getClass() != obj.getClass()) {
    81             return false;
    82         }
    83         final CommentedMove other = (CommentedMove) obj;
    84         if (this.move != other.move && (this.move == null || !this.move.equals(other.move))) {
    85             return false;
    86         }
    87         if (this.index != other.index) {
    88             return false;
    89         }
    90         if (this.comments != other.comments && (this.comments == null || !this.comments.equals(other.comments))) {
    91             return false;
    92         }
    93         return true;
    94     }
    95 
    96     @Override
    97     public int hashCode() {
    98         int hash = 5;
    99         hash = 43 * hash + (this.move != null ? this.move.hashCode() : 0);
   100         hash = 43 * hash + this.index;
   101         hash = 43 * hash + (this.comments != null ? this.comments.hashCode() : 0);
   102         return hash;
   103     }
   104 }