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 {
|
|
|
|
private String key;
|
|
|
|
private String value;
|
|
|
|
public Flag(String key, String value) {
|
2014-09-23 15:28:26 +10:00
|
|
|
if (!StringUtils.isAlphanumeric(key) || !StringUtils.isAlphanumeric(ChatColor.stripColor(value).replace(" ", "")))
|
2014-09-23 12:08:31 +10:00
|
|
|
throw new IllegalArgumentException("Flag must be alphanumerical");
|
|
|
|
if (key.length()>16)
|
|
|
|
throw new IllegalArgumentException("Key must be <= 16 characters");
|
|
|
|
if (value.length()>48)
|
|
|
|
throw new IllegalArgumentException("Value must be <= 48 characters");
|
|
|
|
this.key = key.toLowerCase();
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
public String getKey() {
|
|
|
|
return this.key;
|
|
|
|
}
|
|
|
|
public String getValue() {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
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-23 15:58:30 +10:00
|
|
|
return (this.key==other.key && this.value == other.value);
|
2014-09-23 12:08:31 +10:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return key.hashCode();
|
|
|
|
}
|
|
|
|
}
|