package geniusweb.profile.utilityspace; import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import geniusweb.issuevalue.Value; /** * A {@link Value} that is the product of some existing values */ @JsonDeserialize(using = JsonDeserializer.None.class) public class ProductOfValue implements Value { private final List values = new ArrayList(); /** * @param newvals the values to make a product of */ @JsonCreator public ProductOfValue(List newvals) { values.addAll(newvals); } @JsonValue public List getValues() { return values; } @Override public String toString() { return values.toString(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((values == null) ? 0 : values.hashCode()); return result; } /** * * @param other a {@link ProductOfValue} with more issues to be merged into * this. * @return new ProductOfValue that contains this and other values. */ public ProductOfValue merge(ProductOfValue other) { List newvalues = new ArrayList(values); newvalues.addAll(other.getValues()); return new ProductOfValue(newvalues); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ProductOfValue other = (ProductOfValue) obj; if (values == null) { if (other.values != null) return false; } else if (!values.equals(other.values)) return false; return true; } @Override public Object getValue() { return getValues(); } }