001 /**
002 * Jetrix TetriNET Server
003 * Copyright (C) 2001-2003 Emmanuel Bourg
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019
020 package net.jetrix.messages.channel;
021
022 import net.jetrix.Field;
023
024 /**
025 * A field change message.
026 *
027 * @author Emmanuel Bourg
028 * @version $Revision: 868 $, $Date: 2010-08-27 13:41:18 +0200 (ven., 27 août 2010) $
029 */
030 public class FieldMessage extends ChannelMessage
031 {
032 private String field;
033
034 public FieldMessage() { }
035
036 public FieldMessage(String field)
037 {
038 this(0, field);
039 }
040
041 public FieldMessage(int slot, String field)
042 {
043 setSlot(slot);
044 setField(field);
045 }
046
047 public String getField()
048 {
049 return field;
050 }
051
052 public void setField(String field)
053 {
054 this.field = field;
055 }
056
057 /**
058 * Tells if the field message is a full update.
059 *
060 * @since 0.3
061 */
062 public boolean isFullUpdate()
063 {
064 return !isEmpty() && field.length() == Field.WIDTH * Field.HEIGHT;
065 }
066
067 /**
068 * Tells if the field message is a partial update.
069 *
070 * @since 0.3
071 */
072 public boolean isPartialUpdate()
073 {
074 if (isEmpty())
075 {
076 return false;
077 }
078
079 char first = field.charAt(0);
080 return first >= 0x21 && first <= 0x2f;
081 }
082
083 /**
084 * Tells if the field message is empty.
085 *
086 * @since 0.3
087 */
088 public boolean isEmpty()
089 {
090 return field == null || field.length() == 0;
091 }
092 }