1 /***
2 * Jetrix TetriNET Server
3 * Copyright (C) 2001-2003 Emmanuel Bourg
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package net.jetrix.messages.channel;
21
22 import net.jetrix.Field;
23
24 /***
25 * A field change message.
26 *
27 * @author Emmanuel Bourg
28 * @version $Revision: 868 $, $Date: 2010-08-27 13:41:18 +0200 (ven., 27 août 2010) $
29 */
30 public class FieldMessage extends ChannelMessage
31 {
32 private String field;
33
34 public FieldMessage() { }
35
36 public FieldMessage(String field)
37 {
38 this(0, field);
39 }
40
41 public FieldMessage(int slot, String field)
42 {
43 setSlot(slot);
44 setField(field);
45 }
46
47 public String getField()
48 {
49 return field;
50 }
51
52 public void setField(String field)
53 {
54 this.field = field;
55 }
56
57 /***
58 * Tells if the field message is a full update.
59 *
60 * @since 0.3
61 */
62 public boolean isFullUpdate()
63 {
64 return !isEmpty() && field.length() == Field.WIDTH * Field.HEIGHT;
65 }
66
67 /***
68 * Tells if the field message is a partial update.
69 *
70 * @since 0.3
71 */
72 public boolean isPartialUpdate()
73 {
74 if (isEmpty())
75 {
76 return false;
77 }
78
79 char first = field.charAt(0);
80 return first >= 0x21 && first <= 0x2f;
81 }
82
83 /***
84 * Tells if the field message is empty.
85 *
86 * @since 0.3
87 */
88 public boolean isEmpty()
89 {
90 return field == null || field.length() == 0;
91 }
92 }