source: java2python/geniuswebtranslator/geniuswebsrc/geniusweb/issuevalue/DiscreteValue.java@ 829

Last change on this file since 829 was 804, checked in by wouter, 7 months ago

#278 added NonNull annotation in many places in the geniusweb code

File size: 1.2 KB
Line 
1package geniusweb.issuevalue;
2
3import org.eclipse.jdt.annotation.NonNull;
4
5import 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 */
11public class DiscreteValue implements Value {
12
13 // serializes nicely but requires custom deserializer.
14 private final @NonNull String value;
15
16 public DiscreteValue(final @NonNull String value) {
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
49 public @NonNull String toString() {
50 return "\"" + value + "\"";
51 }
52
53 @Override
54 @JsonValue
55 public @NonNull String getValue() {
56 return value;
57 }
58}
Note: See TracBrowser for help on using the repository browser.