TF-PlotSquared/PlotSquared/src/com/intellectualcrafters/plot/Flag.java

47 lines
1.4 KiB
Java
Raw Normal View History

package com.intellectualcrafters.plot;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
public class Flag {
2014-09-23 19:02:17 +02:00
private AbstractFlag key;
private String value;
2014-09-23 19:02:17 +02:00
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value)))
throw new IllegalArgumentException("Flag must be alphanumerical");
if (value.length()>48)
throw new IllegalArgumentException("Value must be <= 48 characters");
2014-09-23 19:02:17 +02:00
this.key = key;
this.value = value;
}
2014-09-23 19:02:17 +02:00
public AbstractFlag getAbstractFlag() { return this.key; }
public String getKey() {
2014-09-23 19:02:17 +02:00
return this.key.getKey();
}
public String getValue() {
return this.value;
}
@Override
public String toString() {
2014-09-23 19:54:06 +10:00
if (this.value.equals("")) {
2014-09-23 19:02:17 +02:00
return this.key.getKey();
2014-09-23 19:54:06 +10:00
}
return this.key+":"+this.value;
}
@Override
public boolean equals(Object obj){
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Flag other = (Flag) obj;
return (this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value));
}
@Override
public int hashCode() {
2014-09-23 19:02:17 +02:00
return key.getKey().hashCode();
}
}