From a0dceaa713e30fc3a71a49f281886c47a0e6739b Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 6 Feb 2013 17:29:48 -0800 Subject: [PATCH] Added StringAttr. The name of the class could be better. --- .../sk89q/worldguard/region/StringAttr.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/main/java/com/sk89q/worldguard/region/StringAttr.java diff --git a/src/main/java/com/sk89q/worldguard/region/StringAttr.java b/src/main/java/com/sk89q/worldguard/region/StringAttr.java new file mode 100644 index 00000000..69d8a3f2 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/region/StringAttr.java @@ -0,0 +1,84 @@ +// $Id$ +/* + * This file is a part of WorldGuard. + * Copyright (c) sk89q + * Copyright (c) the WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . +*/ + +package com.sk89q.worldguard.region; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.apache.commons.lang.Validate; + +/** + * An attribute that stores string data. + */ +public class StringAttr extends Attribute { + + private String data; + + /** + * No-arg constructor. + */ + public StringAttr() { + } + + /** + * Construct an instance and specify an attribute name. + * + * @param name name of the attribute + */ + public StringAttr(String name) { + super(name); + } + + /** + * Get the text. + * + * @return the text + */ + public String getText() { + return data; + } + + /** + * Set the stored text. + * + * @param text the new text + */ + public void setText(String text) { + Validate.notNull(text); + + this.data = text; + } + + @Override + public void read(DataInputStream in, int len) throws IOException { + data = in.readUTF(); + } + + @Override + public void write(DataOutputStream out) throws IOException { + out.writeUTF(data); + } + + @Override + public String toString() { + return data; + } + +}