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
jaroslav@266
     1
/**
jaroslav@266
     2
 * Quoridor server and related libraries
jaroslav@266
     3
 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@266
     4
 *
jaroslav@266
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@266
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@266
     7
 * the Free Software Foundation, either version 3 of the License.
jaroslav@266
     8
 *
jaroslav@266
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@266
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@266
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@266
    12
 * GNU General Public License for more details.
jaroslav@266
    13
 *
jaroslav@266
    14
 * You should have received a copy of the GNU General Public License
jaroslav@266
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@266
    16
 * If not, see http://www.gnu.org/licenses/.
jaroslav@266
    17
 */
jaroslav@266
    18
jaroslav@115
    19
package cz.xelfi.quoridor.webidor;
jaroslav@115
    20
jaroslav@115
    21
import cz.xelfi.quoridor.IllegalPositionException;
jaroslav@115
    22
import cz.xelfi.quoridor.Move;
jaroslav@115
    23
import java.util.ArrayList;
jaroslav@115
    24
import java.util.List;
jaroslav@115
    25
import javax.xml.bind.annotation.XmlAttribute;
jaroslav@115
    26
import javax.xml.bind.annotation.XmlElement;
jaroslav@115
    27
jaroslav@115
    28
public final class CommentedMove {
jaroslav@115
    29
    Move move;
jaroslav@115
    30
    int index;
jaroslav@115
    31
    List<Note> comments;
jaroslav@115
    32
jaroslav@115
    33
    private CommentedMove() {
jaroslav@115
    34
        super();
jaroslav@115
    35
    }
jaroslav@115
    36
jaroslav@115
    37
    CommentedMove(Move move, int index) {
jaroslav@115
    38
        super();
jaroslav@115
    39
        this.move = move;
jaroslav@115
    40
        this.index = index;
jaroslav@115
    41
    }
jaroslav@115
    42
jaroslav@115
    43
    public Move getMove() {
jaroslav@115
    44
        return move;
jaroslav@115
    45
    }
jaroslav@115
    46
jaroslav@115
    47
    @XmlAttribute(name="move")
jaroslav@115
    48
    String getMoveText() {
jaroslav@115
    49
        return move.toString();
jaroslav@115
    50
    }
jaroslav@115
    51
jaroslav@115
    52
    void setMoveText(String m) throws IllegalPositionException {
jaroslav@115
    53
        move = Move.valueOf(m);
jaroslav@115
    54
    }
jaroslav@115
    55
    
jaroslav@115
    56
    @XmlAttribute
jaroslav@115
    57
    int getIndex() {
jaroslav@115
    58
        return index;
jaroslav@115
    59
    }
jaroslav@115
    60
jaroslav@115
    61
    void setIndex(int i) {
jaroslav@115
    62
        index = i;
jaroslav@115
    63
    }
jaroslav@115
    64
jaroslav@115
    65
    void addNote(Note n) {
jaroslav@115
    66
        if (comments == null) {
jaroslav@115
    67
            comments = new ArrayList<Note>();
jaroslav@115
    68
        }
jaroslav@115
    69
        comments.add(n);
jaroslav@115
    70
    }
jaroslav@115
    71
jaroslav@115
    72
    @XmlElement(name="comment", required=false)
jaroslav@115
    73
    public final List<Note> getComments() {
jaroslav@115
    74
        return comments;
jaroslav@115
    75
    }
jaroslav@115
    76
jaroslav@115
    77
    final void setComments(List<Note> l) {
jaroslav@115
    78
        this.comments = l;
jaroslav@115
    79
    }
jaroslav@115
    80
jaroslav@115
    81
    @Override
jaroslav@115
    82
    public String toString() {
jaroslav@115
    83
        StringBuilder sb = new StringBuilder();
jaroslav@115
    84
        sb.append("Move[").append(move).append("@").append(index);
jaroslav@115
    85
        if (comments != null) {
jaroslav@115
    86
            sb.append(", ");
jaroslav@115
    87
            sb.append(comments);
jaroslav@115
    88
        }
jaroslav@115
    89
        sb.append("]");
jaroslav@115
    90
        return sb.toString();
jaroslav@115
    91
    }
jaroslav@115
    92
jaroslav@115
    93
    @Override
jaroslav@115
    94
    public boolean equals(Object obj) {
jaroslav@115
    95
        if (obj == null) {
jaroslav@115
    96
            return false;
jaroslav@115
    97
        }
jaroslav@115
    98
        if (getClass() != obj.getClass()) {
jaroslav@115
    99
            return false;
jaroslav@115
   100
        }
jaroslav@115
   101
        final CommentedMove other = (CommentedMove) obj;
jaroslav@115
   102
        if (this.move != other.move && (this.move == null || !this.move.equals(other.move))) {
jaroslav@115
   103
            return false;
jaroslav@115
   104
        }
jaroslav@115
   105
        if (this.index != other.index) {
jaroslav@115
   106
            return false;
jaroslav@115
   107
        }
jaroslav@115
   108
        if (this.comments != other.comments && (this.comments == null || !this.comments.equals(other.comments))) {
jaroslav@115
   109
            return false;
jaroslav@115
   110
        }
jaroslav@115
   111
        return true;
jaroslav@115
   112
    }
jaroslav@115
   113
jaroslav@115
   114
    @Override
jaroslav@115
   115
    public int hashCode() {
jaroslav@115
   116
        int hash = 5;
jaroslav@115
   117
        hash = 43 * hash + (this.move != null ? this.move.hashCode() : 0);
jaroslav@115
   118
        hash = 43 * hash + this.index;
jaroslav@115
   119
        hash = 43 * hash + (this.comments != null ? this.comments.hashCode() : 0);
jaroslav@115
   120
        return hash;
jaroslav@115
   121
    }
jaroslav@115
   122
}