1 | package geniusweb.profile.utilityspace;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
7 | import com.fasterxml.jackson.annotation.JsonValue;
|
---|
8 | import com.fasterxml.jackson.databind.JsonDeserializer;
|
---|
9 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
---|
10 |
|
---|
11 | import geniusweb.issuevalue.Value;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * A {@link Value} that is the product of some existing values
|
---|
15 | */
|
---|
16 | @JsonDeserialize(using = JsonDeserializer.None.class)
|
---|
17 | public class ProductOfValue implements Value {
|
---|
18 | private final List<Value> values = new ArrayList<Value>();
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * @param newvals the values to make a product of
|
---|
22 | */
|
---|
23 | @JsonCreator
|
---|
24 | public ProductOfValue(List<Value> newvals) {
|
---|
25 | values.addAll(newvals);
|
---|
26 | }
|
---|
27 |
|
---|
28 | @JsonValue
|
---|
29 | public List<Value> getValues() {
|
---|
30 | return values;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public String toString() {
|
---|
35 | return values.toString();
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public int hashCode() {
|
---|
40 | final int prime = 31;
|
---|
41 | int result = 1;
|
---|
42 | result = prime * result + ((values == null) ? 0 : values.hashCode());
|
---|
43 | return result;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | *
|
---|
48 | * @param other a {@link ProductOfValue} with more issues to be merged into
|
---|
49 | * this.
|
---|
50 | * @return new ProductOfValue that contains this and other values.
|
---|
51 | */
|
---|
52 | public ProductOfValue merge(ProductOfValue other) {
|
---|
53 | List<Value> newvalues = new ArrayList<Value>(values);
|
---|
54 | newvalues.addAll(other.getValues());
|
---|
55 | return new ProductOfValue(newvalues);
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public boolean equals(Object obj) {
|
---|
60 | if (this == obj)
|
---|
61 | return true;
|
---|
62 | if (obj == null)
|
---|
63 | return false;
|
---|
64 | if (getClass() != obj.getClass())
|
---|
65 | return false;
|
---|
66 | ProductOfValue other = (ProductOfValue) obj;
|
---|
67 | if (values == null) {
|
---|
68 | if (other.values != null)
|
---|
69 | return false;
|
---|
70 | } else if (!values.equals(other.values))
|
---|
71 | return false;
|
---|
72 | return true;
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public Object getValue() {
|
---|
77 | return getValues();
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|