author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sat, 27 Nov 2010 07:52:19 +0100 | |
changeset 272 | 215b417aac98 |
parent 266 | 15fcdfc4cd4a |
child 275 | 0897f0832eb5 |
permissions | -rw-r--r-- |
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 java.util.Date; |
jaroslav@115 | 22 |
import javax.xml.bind.annotation.XmlAccessType; |
jaroslav@115 | 23 |
import javax.xml.bind.annotation.XmlAccessorType; |
jaroslav@115 | 24 |
import javax.xml.bind.annotation.XmlAttribute; |
jaroslav@115 | 25 |
import javax.xml.bind.annotation.XmlValue; |
jaroslav@115 | 26 |
|
jaroslav@115 | 27 |
/** |
jaroslav@115 | 28 |
* |
jaroslav@115 | 29 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@115 | 30 |
*/ |
jaroslav@115 | 31 |
@XmlAccessorType(XmlAccessType.FIELD) |
jaroslav@115 | 32 |
public class Note { |
jaroslav@115 | 33 |
@XmlValue |
jaroslav@115 | 34 |
private String comment; |
jaroslav@115 | 35 |
@XmlAttribute |
jaroslav@115 | 36 |
private Date when; |
jaroslav@115 | 37 |
@XmlAttribute |
jaroslav@115 | 38 |
private String who; |
jaroslav@115 | 39 |
|
jaroslav@115 | 40 |
private Note() { |
jaroslav@115 | 41 |
} |
jaroslav@115 | 42 |
|
jaroslav@115 | 43 |
public Note(String comment, Date when, String who) { |
jaroslav@272 | 44 |
this.comment = eliminateXMLChars(comment); |
jaroslav@115 | 45 |
this.when = new Date(when.getTime()); |
jaroslav@115 | 46 |
this.who = who; |
jaroslav@115 | 47 |
} |
jaroslav@115 | 48 |
|
jaroslav@115 | 49 |
public String getComment() { |
jaroslav@115 | 50 |
return comment; |
jaroslav@115 | 51 |
} |
jaroslav@115 | 52 |
|
jaroslav@115 | 53 |
public Date getWhen() { |
jaroslav@115 | 54 |
return (Date) when.clone(); |
jaroslav@115 | 55 |
} |
jaroslav@115 | 56 |
|
jaroslav@115 | 57 |
public String getWho() { |
jaroslav@115 | 58 |
return who; |
jaroslav@115 | 59 |
} |
jaroslav@115 | 60 |
|
jaroslav@115 | 61 |
@Override |
jaroslav@115 | 62 |
public String toString() { |
jaroslav@115 | 63 |
return "Note[" + who + "@" + when + ": " + comment + "]"; |
jaroslav@115 | 64 |
} |
jaroslav@115 | 65 |
|
jaroslav@115 | 66 |
@Override |
jaroslav@115 | 67 |
public boolean equals(Object obj) { |
jaroslav@115 | 68 |
if (obj == null) { |
jaroslav@115 | 69 |
return false; |
jaroslav@115 | 70 |
} |
jaroslav@115 | 71 |
if (getClass() != obj.getClass()) { |
jaroslav@115 | 72 |
return false; |
jaroslav@115 | 73 |
} |
jaroslav@115 | 74 |
final Note other = (Note) obj; |
jaroslav@115 | 75 |
if ((this.comment == null) ? (other.comment != null) : !this.comment.equals(other.comment)) { |
jaroslav@115 | 76 |
return false; |
jaroslav@115 | 77 |
} |
jaroslav@115 | 78 |
if (this.when != other.when && (this.when == null || !this.when.equals(other.when))) { |
jaroslav@115 | 79 |
return false; |
jaroslav@115 | 80 |
} |
jaroslav@115 | 81 |
if ((this.who == null) ? (other.who != null) : !this.who.equals(other.who)) { |
jaroslav@115 | 82 |
return false; |
jaroslav@115 | 83 |
} |
jaroslav@115 | 84 |
return true; |
jaroslav@115 | 85 |
} |
jaroslav@115 | 86 |
|
jaroslav@115 | 87 |
@Override |
jaroslav@115 | 88 |
public int hashCode() { |
jaroslav@115 | 89 |
int hash = 7; |
jaroslav@115 | 90 |
hash = 59 * hash + (this.comment != null ? this.comment.hashCode() : 0); |
jaroslav@115 | 91 |
hash = 59 * hash + (this.when != null ? this.when.hashCode() : 0); |
jaroslav@115 | 92 |
hash = 59 * hash + (this.who != null ? this.who.hashCode() : 0); |
jaroslav@115 | 93 |
return hash; |
jaroslav@115 | 94 |
} |
jaroslav@115 | 95 |
|
jaroslav@272 | 96 |
private static String eliminateXMLChars(String s) { |
jaroslav@272 | 97 |
StringBuilder sb = new StringBuilder(); |
jaroslav@272 | 98 |
for (int i = 0; i < s.length(); i++) { |
jaroslav@272 | 99 |
char ch = s.charAt(i); |
jaroslav@272 | 100 |
if (ch < 32 && ch != '\n' || ch != '\r') { |
jaroslav@272 | 101 |
} else { |
jaroslav@272 | 102 |
sb.append((char)ch); |
jaroslav@272 | 103 |
} |
jaroslav@272 | 104 |
} |
jaroslav@272 | 105 |
return sb.toString(); |
jaroslav@272 | 106 |
} |
jaroslav@115 | 107 |
} |