[519] | 1 | package geniusweb.issuevalue;
|
---|
| 2 |
|
---|
| 3 | import java.math.BigInteger;
|
---|
| 4 | import java.util.Collection;
|
---|
| 5 | import java.util.Collections;
|
---|
| 6 | import java.util.Iterator;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
[804] | 9 | import org.eclipse.jdt.annotation.NonNull;
|
---|
| 10 |
|
---|
[519] | 11 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
---|
| 12 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
---|
| 13 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
| 14 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
| 15 | import com.fasterxml.jackson.databind.JsonDeserializer;
|
---|
| 16 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
---|
| 17 |
|
---|
| 18 | import 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)
|
---|
| 26 | public 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 | */
|
---|
[804] | 32 | private final @NonNull ArrayListSet<DiscreteValue> values = new ArrayListSet<DiscreteValue>();
|
---|
[519] | 33 |
|
---|
| 34 | @JsonCreator
|
---|
| 35 | public DiscreteValueSet(
|
---|
[804] | 36 | @JsonProperty("values") @NonNull Collection<DiscreteValue> values) {
|
---|
[742] | 37 | this.values.addAll(values);
|
---|
[519] | 38 | }
|
---|
| 39 |
|
---|
[769] | 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 | // }
|
---|
[519] | 46 |
|
---|
[804] | 47 | public @NonNull List<DiscreteValue> getValues() {
|
---|
[519] | 48 | return Collections.unmodifiableList(values);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | @Override
|
---|
| 52 | public Boolean contains(Value value) {
|
---|
| 53 | return values.contains(value);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | @Override
|
---|
[804] | 57 | public @NonNull DiscreteValue get(@NonNull BigInteger index) {
|
---|
[519] | 58 | return values.get(index.intValue());
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | @Override
|
---|
[804] | 62 | public @NonNull BigInteger size() {
|
---|
[519] | 63 | return BigInteger.valueOf(values.size());
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | @Override
|
---|
[804] | 67 | public @NonNull DiscreteValue get(long index) {
|
---|
[519] | 68 | return values.get((int) index);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | @Override
|
---|
| 72 | public Iterator iterator() {
|
---|
| 73 | return values.iterator();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | @Override
|
---|
[804] | 77 | public @NonNull String toString() {
|
---|
[734] | 78 | return "DiscreteValueSet" + values.toString();
|
---|
[519] | 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 | }
|
---|