package geniusweb.issuevalue; import org.eclipse.jdt.annotation.NonNull; import com.fasterxml.jackson.annotation.JsonValue; /** * A value for a discrete issue. Constructor guarantees this is non-null and * non-empty. immutable. */ public class DiscreteValue implements Value { // serializes nicely but requires custom deserializer. private final @NonNull String value; public DiscreteValue(final @NonNull String value) { if (value == null || value.isEmpty()) throw new NullPointerException( "value must be non-null and non-empty"); this.value = value; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; DiscreteValue other = (DiscreteValue) obj; if (value == null) { if (other.value != null) return false; } else if (!value.equals(other.value)) return false; return true; } @Override public @NonNull String toString() { return "\"" + value + "\""; } @Override @JsonValue public @NonNull String getValue() { return value; } }