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

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

#278 fixing @NonNull annotations

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