| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard; |
| 16 | |
| 17 | import java.util.Date; |
| 18 | import java.util.HashSet; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | import org.apache.hivemind.util.ToStringBuilder; |
| 22 | |
| 23 | public class Board |
| 24 | { |
| 25 | public Board copy() |
| 26 | { |
| 27 | Board clone = new Board(); |
| 28 | copy(this, clone, true); |
| 29 | return clone; |
| 30 | } |
| 31 | |
| 32 | static public void copy(Board from, Board to, boolean deep) |
| 33 | { |
| 34 | to._id = from._id; |
| 35 | to._name = from._name; |
| 36 | to._discriminator = from._discriminator; |
| 37 | to._description = from._description; |
| 38 | to._width = from._width; |
| 39 | to._height = from._height; |
| 40 | to._tokenSetter = from._tokenSetter; |
| 41 | to._initiator = from._initiator; |
| 42 | to._writer = from._writer; |
| 43 | if (deep) |
| 44 | { |
| 45 | to._participants = new HashSet<Integer>(from._participants); |
| 46 | to._presents = new HashSet<Integer>(from._presents); |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | to._participants = from._participants; |
| 51 | to._presents = from._presents; |
| 52 | } |
| 53 | to._creationDate = from._creationDate; |
| 54 | to._closingDate = from._closingDate; |
| 55 | to._version = from._version; |
| 56 | } |
| 57 | |
| 58 | public void setId(int id) |
| 59 | { |
| 60 | _id = id; |
| 61 | } |
| 62 | public int getId() |
| 63 | { |
| 64 | return _id; |
| 65 | } |
| 66 | |
| 67 | public void setName(String name) |
| 68 | { |
| 69 | _name = name; |
| 70 | } |
| 71 | public String getName() |
| 72 | { |
| 73 | return _name; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Discriminator is used to enable several accounts with the same visa but |
| 78 | * only one in valid state. |
| 79 | * For a valid account, it is always 0; when an account is deactivated, this |
| 80 | * value will be set to <code>select max(discriminator) + 1 from accounts</code>. |
| 81 | */ |
| 82 | public void setDiscriminator(int discriminator) |
| 83 | { |
| 84 | _discriminator = discriminator; |
| 85 | } |
| 86 | public int getDiscriminator() |
| 87 | { |
| 88 | return _discriminator; |
| 89 | } |
| 90 | |
| 91 | public void setDescription(String description) |
| 92 | { |
| 93 | _description = description; |
| 94 | } |
| 95 | public String getDescription() |
| 96 | { |
| 97 | return _description; |
| 98 | } |
| 99 | |
| 100 | public void setWidth(short width) |
| 101 | { |
| 102 | _width = width; |
| 103 | } |
| 104 | public short getWidth() |
| 105 | { |
| 106 | return _width; |
| 107 | } |
| 108 | |
| 109 | public void setHeight(short height) |
| 110 | { |
| 111 | _height = height; |
| 112 | } |
| 113 | public short getHeight() |
| 114 | { |
| 115 | return _height; |
| 116 | } |
| 117 | |
| 118 | public void setTokenSetter(BoardTokenSetter tokenSetter) |
| 119 | { |
| 120 | _tokenSetter = tokenSetter; |
| 121 | } |
| 122 | public BoardTokenSetter getTokenSetter() |
| 123 | { |
| 124 | return _tokenSetter; |
| 125 | } |
| 126 | |
| 127 | public void setInitiator(int initiator) |
| 128 | { |
| 129 | _initiator = initiator; |
| 130 | } |
| 131 | public int getInitiator() |
| 132 | { |
| 133 | return _initiator; |
| 134 | } |
| 135 | |
| 136 | public void setWriter(int writer) |
| 137 | { |
| 138 | _writer = writer; |
| 139 | } |
| 140 | public int getWriter() |
| 141 | { |
| 142 | return _writer; |
| 143 | } |
| 144 | |
| 145 | public void setParticipants(Set<Integer> participants) |
| 146 | { |
| 147 | _participants = participants; |
| 148 | } |
| 149 | public Set<Integer> getParticipants() |
| 150 | { |
| 151 | return _participants; |
| 152 | } |
| 153 | |
| 154 | public void setPresents(Set<Integer> presents) |
| 155 | { |
| 156 | _presents = presents; |
| 157 | } |
| 158 | public Set<Integer> getPresents() |
| 159 | { |
| 160 | return _presents; |
| 161 | } |
| 162 | |
| 163 | public void setCreationDate(Date creationDate) |
| 164 | { |
| 165 | _creationDate = creationDate; |
| 166 | } |
| 167 | |
| 168 | public Date getCreationDate() |
| 169 | { |
| 170 | return _creationDate; |
| 171 | } |
| 172 | |
| 173 | public void setClosingDate(Date closingDate) |
| 174 | { |
| 175 | _closingDate = closingDate; |
| 176 | } |
| 177 | |
| 178 | public Date getClosingDate() |
| 179 | { |
| 180 | return _closingDate; |
| 181 | } |
| 182 | |
| 183 | public void setVersion(int version) |
| 184 | { |
| 185 | _version = version; |
| 186 | } |
| 187 | public int getVersion() |
| 188 | { |
| 189 | return _version; |
| 190 | } |
| 191 | |
| 192 | // CSOFF: MagicNumberCheck |
| 193 | @Override public int hashCode() |
| 194 | { |
| 195 | return _id * 45621 + 5631; |
| 196 | } |
| 197 | // CSON: MagicNumberCheck |
| 198 | |
| 199 | @Override public boolean equals(Object o) |
| 200 | { |
| 201 | if (!(o instanceof Board)) |
| 202 | { |
| 203 | return false; |
| 204 | } |
| 205 | Board that = (Board) o; |
| 206 | return (this.getId() == that.getId()); |
| 207 | } |
| 208 | |
| 209 | @Override public String toString() |
| 210 | { |
| 211 | ToStringBuilder builder = new ToStringBuilder(this); |
| 212 | builder.append("id", _id); |
| 213 | builder.append("name", _name); |
| 214 | builder.append("initiator", _initiator); |
| 215 | builder.append("writer", _writer); |
| 216 | return builder.toString(); |
| 217 | } |
| 218 | |
| 219 | private int _id; |
| 220 | private String _name; |
| 221 | private int _discriminator; |
| 222 | private String _description; |
| 223 | private short _width; |
| 224 | private short _height; |
| 225 | private BoardTokenSetter _tokenSetter = BoardTokenSetter.InitiatorOnly; |
| 226 | private int _initiator; |
| 227 | private int _writer; |
| 228 | private Set<Integer> _participants = new HashSet<Integer>(); |
| 229 | private Set<Integer> _presents = new HashSet<Integer>(); |
| 230 | private Date _creationDate; |
| 231 | private Date _closingDate; |
| 232 | private int _version; |
| 233 | } |