1 package fr.ifremer.tutti.persistence.entities.data;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
26
27 import java.io.Serializable;
28
29
30
31
32
33
34
35 public class SampleCategory<C extends Serializable> implements Serializable {
36
37 private static final long serialVersionUID = 1L;
38
39 public static final String PROPERTY_CATEGORY_WEIGHT = "categoryWeight";
40
41 public static final String PROPERTY_CATEGORY_VALUE = "categoryValue";
42
43
44
45
46
47
48 protected SampleCategoryModelEntry categoryDef;
49
50
51
52
53
54
55 protected C categoryValue;
56
57
58
59
60
61
62 protected Float categoryWeight;
63
64
65
66
67
68
69 protected Float computedWeight;
70
71
72
73
74
75
76
77 protected boolean subSample;
78
79
80
81
82
83
84
85 protected boolean onlyOneFrequency;
86
87 public static <C extends Serializable> SampleCategory<C> newSample(SampleCategoryModelEntry categoryDef) {
88 SampleCategory<C> result = new SampleCategory<>();
89 result.setCategoryDef(categoryDef);
90 return result;
91 }
92
93 protected SampleCategory() {
94 }
95
96 public SampleCategoryModelEntry getCategoryDef() {
97 return categoryDef;
98 }
99
100 public void setCategoryDef(SampleCategoryModelEntry categoryDef) {
101 this.categoryDef = categoryDef;
102 }
103
104 public Integer getCategoryId() {
105 return categoryDef.getCategoryId();
106 }
107
108 public C getCategoryValue() {
109 return categoryValue;
110 }
111
112 public void setCategoryValue(C categoryValue) {
113 this.categoryValue = categoryValue;
114 }
115
116 public Float getCategoryWeight() {
117 return categoryWeight;
118 }
119
120 public void setCategoryWeight(Float categoryWeight) {
121 this.categoryWeight = categoryWeight;
122 }
123
124 public Float getComputedWeight() {
125 return computedWeight;
126 }
127
128 public void setComputedWeight(Float computedWeight) {
129 this.computedWeight = computedWeight;
130 }
131
132 public boolean isSubSample() {
133 return subSample;
134 }
135
136 public void setSubSample(boolean subSample) {
137 this.subSample = subSample;
138 }
139
140 public boolean hasOnlyOneFrequency() {
141 return onlyOneFrequency;
142 }
143
144 public void setOnlyOneFrequency(boolean onlyOneFrequency) {
145 this.onlyOneFrequency = onlyOneFrequency;
146 }
147
148 public boolean isValid() {
149 return categoryValue != null;
150 }
151
152 public boolean isEmpty() {
153 return categoryValue == null
154 && categoryWeight == null
155 && computedWeight == null;
156 }
157
158 public boolean isEmptyOrValid() {
159 return isEmpty() || isValid();
160 }
161
162 public Float getNotNullWeight() {
163 Float result = categoryWeight;
164 if (result == null) {
165 result = computedWeight;
166 }
167 return result;
168 }
169
170 @Override
171 public String toString() {
172 return new ReflectionToStringBuilder(this).
173 appendSuper(super.toString()).
174 toString();
175 }
176 }