Rev | Line | |
---|
[519] | 1 | package geniusweb.issuevalue;
|
---|
| 2 |
|
---|
[804] | 3 | import org.eclipse.jdt.annotation.NonNull;
|
---|
| 4 |
|
---|
[519] | 5 | import com.fasterxml.jackson.annotation.JsonValue;
|
---|
| 6 |
|
---|
| 7 | /**
|
---|
| 8 | * A value for a discrete issue. Constructor guarantees this is non-null and
|
---|
| 9 | * non-empty. immutable.
|
---|
| 10 | */
|
---|
| 11 | public class DiscreteValue implements Value {
|
---|
| 12 |
|
---|
[526] | 13 | // serializes nicely but requires custom deserializer.
|
---|
[804] | 14 | private final @NonNull String value;
|
---|
[519] | 15 |
|
---|
[804] | 16 | public DiscreteValue(final @NonNull String value) {
|
---|
[519] | 17 | if (value == null || value.isEmpty())
|
---|
| 18 | throw new NullPointerException(
|
---|
| 19 | "value must be non-null and non-empty");
|
---|
| 20 | this.value = value;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | @Override
|
---|
| 24 | public int hashCode() {
|
---|
| 25 | final int prime = 31;
|
---|
| 26 | int result = 1;
|
---|
| 27 | result = prime * result + ((value == null) ? 0 : value.hashCode());
|
---|
| 28 | return result;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | @Override
|
---|
| 32 | public boolean equals(Object obj) {
|
---|
| 33 | if (this == obj)
|
---|
| 34 | return true;
|
---|
| 35 | if (obj == null)
|
---|
| 36 | return false;
|
---|
| 37 | if (getClass() != obj.getClass())
|
---|
| 38 | return false;
|
---|
| 39 | DiscreteValue other = (DiscreteValue) obj;
|
---|
| 40 | if (value == null) {
|
---|
| 41 | if (other.value != null)
|
---|
| 42 | return false;
|
---|
| 43 | } else if (!value.equals(other.value))
|
---|
| 44 | return false;
|
---|
| 45 | return true;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | @Override
|
---|
[804] | 49 | public @NonNull String toString() {
|
---|
[519] | 50 | return "\"" + value + "\"";
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[804] | 53 | @Override
|
---|
[526] | 54 | @JsonValue
|
---|
[804] | 55 | public @NonNull String getValue() {
|
---|
[519] | 56 | return value;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.