source: profile/src/main/java/geniusweb/profile/utilityspace/ProductOfValue.java

Last change on this file was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.8 KB
Line 
1package geniusweb.profile.utilityspace;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import com.fasterxml.jackson.annotation.JsonCreator;
7import com.fasterxml.jackson.annotation.JsonValue;
8import com.fasterxml.jackson.databind.JsonDeserializer;
9import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
10
11import geniusweb.issuevalue.Value;
12
13/**
14 * A {@link Value} that is the product of some existing values
15 */
16@JsonDeserialize(using = JsonDeserializer.None.class)
17public 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}
Note: See TracBrowser for help on using the repository browser.