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

Last change on this file since 769 was 769, checked in by wouter, 10 months ago

#263 fix custom code in deserializer

File size: 2.7 KB
Line 
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(
34 @JsonProperty("values") Collection<DiscreteValue> values) {
35 this.values.addAll(values);
36 }
37
38 //abandoned, because we can not overload constructor like this in Python
39 // public DiscreteValueSet(DiscreteValue... issuevalues) {
40 // for (DiscreteValue value : issuevalues) {
41 // this.values.add(value);
42 // }
43 // }
44
45 public List<DiscreteValue> getValues() {
46 return Collections.unmodifiableList(values);
47 }
48
49 @Override
50 public Boolean contains(Value value) {
51 return values.contains(value);
52 }
53
54 @Override
55 public DiscreteValue get(BigInteger index) {
56 return values.get(index.intValue());
57 }
58
59 @Override
60 public BigInteger size() {
61 return BigInteger.valueOf(values.size());
62 }
63
64 @Override
65 public DiscreteValue get(long index) {
66 return values.get((int) index);
67 }
68
69 @Override
70 public Iterator iterator() {
71 return values.iterator();
72 }
73
74 @Override
75 public String toString() {
76 return "DiscreteValueSet" + values.toString();
77 }
78
79 @Override
80 public int hashCode() {
81 final int prime = 31;
82 int result = 1;
83 result = prime * result + ((values == null) ? 0 : values.hashCode());
84 return result;
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj)
90 return true;
91 if (obj == null)
92 return false;
93 if (getClass() != obj.getClass())
94 return false;
95 DiscreteValueSet other = (DiscreteValueSet) obj;
96 if (values == null) {
97 if (other.values != null)
98 return false;
99 } else if (!values.equals(other.values))
100 return false;
101 return true;
102 }
103
104}
Note: See TracBrowser for help on using the repository browser.