2014-09-23 12:08:31 +10:00
|
|
|
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;
|
2014-09-23 12:08:31 +10:00
|
|
|
private String value;
|
2014-09-23 19:02:17 +02:00
|
|
|
public Flag(AbstractFlag key, String value) {
|
2014-09-24 10:56:03 +10:00
|
|
|
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value)))
|
2014-09-23 12:08:31 +10:00
|
|
|
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;
|
2014-09-23 12:08:31 +10:00
|
|
|
this.value = value;
|
|
|
|
}
|
2014-09-23 19:02:17 +02:00
|
|
|
public AbstractFlag getAbstractFlag() { return this.key; }
|
2014-09-23 12:08:31 +10:00
|
|
|
public String getKey() {
|
2014-09-23 19:02:17 +02:00
|
|
|
return this.key.getKey();
|
2014-09-23 12:08:31 +10:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2014-09-23 12:08:31 +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;
|
2014-09-24 10:56:03 +10:00
|
|
|
return (this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value));
|
2014-09-23 12:08:31 +10:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2014-09-23 19:02:17 +02:00
|
|
|
return key.getKey().hashCode();
|
2014-09-23 12:08:31 +10:00
|
|
|
}
|
|
|
|
}
|