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

Last change on this file since 825 was 818, checked in by wouter, 5 months ago

#278 all code seems annotated @NonNull

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