[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 |
|
---|
| 9 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
---|
| 10 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
---|
| 11 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
| 12 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
| 13 | import com.fasterxml.jackson.databind.JsonDeserializer;
|
---|
| 14 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
---|
| 15 |
|
---|
| 16 | import 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)
|
---|
| 24 | public 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 | }
|
---|