source: java2python/geniuswebtranslator/geniuswebsrc/geniusweb/issuevalue/DiscreteValueSet.java@ 749

Last change on this file since 749 was 742, checked in by wouter, 12 months ago

#169 fixed @JsonProperty

File size: 2.6 KB
RevLine 
[519]1package geniusweb.issuevalue;
2
3import java.math.BigInteger;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.Iterator;
7import java.util.List;
8
9import com.fasterxml.jackson.annotation.JsonAutoDetect;
10import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
11import com.fasterxml.jackson.annotation.JsonCreator;
12import com.fasterxml.jackson.annotation.JsonProperty;
13import com.fasterxml.jackson.databind.JsonDeserializer;
14import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
15
16import tudelft.utilities.immutablelist.ArrayListSet;
17
18/**
19 * set of discrete values
20 */
21// disable the inherited deserializer to prevent getting into infinite loop...
22@JsonDeserialize(using = JsonDeserializer.None.class)
23@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
24public class DiscreteValueSet implements ValueSet {
25 /*
26 * final, must be immutable so do not provide external access to this list.
27 * ArrayList (instead of List) to help Jackson serializer which avoids
28 * per-field type annotations.
29 */
30 private final ArrayListSet<DiscreteValue> values = new ArrayListSet<DiscreteValue>();
31
32 @JsonCreator
33 public DiscreteValueSet(
[742]34 @JsonProperty("values") Collection<DiscreteValue> values) {
35 this.values.addAll(values);
[519]36 }
37
38 public DiscreteValueSet(DiscreteValue... issuevalues) {
39 for (DiscreteValue value : issuevalues) {
40 this.values.add(value);
41 }
42 }
43
44 public List<DiscreteValue> getValues() {
45 return Collections.unmodifiableList(values);
46 }
47
48 @Override
49 public Boolean contains(Value value) {
50 return values.contains(value);
51 }
52
53 @Override
54 public DiscreteValue get(BigInteger index) {
55 return values.get(index.intValue());
56 }
57
58 @Override
59 public BigInteger size() {
60 return BigInteger.valueOf(values.size());
61 }
62
63 @Override
64 public DiscreteValue get(long index) {
65 return values.get((int) index);
66 }
67
68 @Override
69 public Iterator iterator() {
70 return values.iterator();
71 }
72
73 @Override
74 public String toString() {
[734]75 return "DiscreteValueSet" + values.toString();
[519]76 }
77
78 @Override
79 public int hashCode() {
80 final int prime = 31;
81 int result = 1;
82 result = prime * result + ((values == null) ? 0 : values.hashCode());
83 return result;
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (this == obj)
89 return true;
90 if (obj == null)
91 return false;
92 if (getClass() != obj.getClass())
93 return false;
94 DiscreteValueSet other = (DiscreteValueSet) obj;
95 if (values == null) {
96 if (other.values != null)
97 return false;
98 } else if (!values.equals(other.values))
99 return false;
100 return true;
101 }
102
103}
Note: See TracBrowser for help on using the repository browser.