package geniusweb.issuevalue; 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 { @JsonValue // serializes nicely but requires custom deserializer. private final String value; public DiscreteValue(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 String toString() { return "\"" + value + "\""; } public String getValue() { return value; } }