package geniusweb.issuevalue; import java.math.BigInteger; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import tudelft.utilities.immutablelist.ArrayListSet; /** * set of discrete values */ // disable the inherited deserializer to prevent getting into infinite loop... @JsonDeserialize(using = JsonDeserializer.None.class) @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) public class DiscreteValueSet implements ValueSet { /* * final, must be immutable so do not provide external access to this list. * ArrayList (instead of List) to help Jackson serializer which avoids * per-field type annotations. */ private final ArrayListSet values = new ArrayListSet(); @JsonCreator public DiscreteValueSet( @JsonProperty("values") Collection issuevalues) { this.values.addAll(issuevalues); } public DiscreteValueSet(DiscreteValue... issuevalues) { for (DiscreteValue value : issuevalues) { this.values.add(value); } } public List getValues() { return Collections.unmodifiableList(values); } @Override public Boolean contains(Value value) { return values.contains(value); } @Override public DiscreteValue get(BigInteger index) { return values.get(index.intValue()); } @Override public BigInteger size() { return BigInteger.valueOf(values.size()); } @Override public DiscreteValue get(long index) { return values.get((int) index); } @Override public Iterator iterator() { return values.iterator(); } @Override public String toString() { return "DiscreteValueSet" + values; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((values == null) ? 0 : values.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; DiscreteValueSet other = (DiscreteValueSet) obj; if (values == null) { if (other.values != null) return false; } else if (!values.equals(other.values)) return false; return true; } }