Extract out common constants & magic values into factory classes

This commit is contained in:
Luck
2017-12-18 22:19:18 +00:00
Unverified
parent a415a2705f
commit fb92fd9357
156 changed files with 706 additions and 675 deletions
@@ -42,17 +42,12 @@ public enum ChatMetaType {
/**
* Represents a prefix
*/
PREFIX {
PREFIX("prefix") {
@Override
public boolean matches(@Nonnull Node node) {
return Preconditions.checkNotNull(node, "node").isPrefix();
}
@Override
public boolean shouldIgnore(@Nonnull Node node) {
return !Preconditions.checkNotNull(node, "node").isPrefix();
}
@Nonnull
@Override
public Map.Entry<Integer, String> getEntry(@Nonnull Node node) {
@@ -63,17 +58,12 @@ public enum ChatMetaType {
/**
* Represents a suffix
*/
SUFFIX {
SUFFIX("suffix") {
@Override
public boolean matches(@Nonnull Node node) {
return Preconditions.checkNotNull(node, "node").isSuffix();
}
@Override
public boolean shouldIgnore(@Nonnull Node node) {
return !Preconditions.checkNotNull(node, "node").isSuffix();
}
@Nonnull
@Override
public Map.Entry<Integer, String> getEntry(@Nonnull Node node) {
@@ -81,6 +71,12 @@ public enum ChatMetaType {
}
};
private final String str;
ChatMetaType(String str) {
this.str = str;
}
/**
* Returns if the passed node matches the type
*
@@ -95,7 +91,9 @@ public enum ChatMetaType {
* @param node the node to test
* @return true if the node does not share the same type
*/
public abstract boolean shouldIgnore(@Nonnull Node node);
public boolean shouldIgnore(@Nonnull Node node) {
return !matches(node);
}
/**
* Maps the corresponding entry from the given node
@@ -107,6 +105,11 @@ public enum ChatMetaType {
@Nonnull
public abstract Map.Entry<Integer, String> getEntry(@Nonnull Node node);
@Override
public String toString() {
return str;
}
/**
* Parses a ChatMetaType from the given node.
*
@@ -59,13 +59,29 @@ public enum Tristate {
* Returns a {@link Tristate} from a boolean
*
* @param val the boolean value
* @return {@link #TRUE} or {@link #FALSE}, depending on the value of the boolean.
* @return {@link #TRUE} or {@link #FALSE}, if the value is <code>true</code> or <code>false</code>, respectively.
*/
@Nonnull
public static Tristate fromBoolean(boolean val) {
return val ? TRUE : FALSE;
}
/**
* Returns a {@link Tristate} from a nullable boolean.
*
* <p>Unlike {@link #fromBoolean(boolean)}, this method returns {@link #UNDEFINED}
* if the value is null.</p>
*
* @param val the boolean value
* @return {@link #UNDEFINED}, {@link #TRUE} or {@link #FALSE}, if the value
* is <code>null</code>, <code>true</code> or <code>false</code>, respectively.
* @since 4.1
*/
@Nonnull
public static Tristate fromNullableBoolean(Boolean val) {
return val == null ? UNDEFINED : val ? TRUE : FALSE;
}
private final boolean booleanValue;
Tristate(boolean booleanValue) {