1 /*
2 * Metis: Java Data Framework
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.metis.field;
18
19 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
21 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataIndexedItem;
22 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataObjectFormat;
23 import io.github.tonywasher.joceanus.metis.data.MetisDataType;
24
25 import java.util.Iterator;
26
27 /**
28 * FieldItem Interface.
29 */
30 public interface MetisFieldItem
31 extends MetisDataObjectFormat {
32 /**
33 * Obtain the fieldSet.
34 *
35 * @return the fieldSet
36 */
37 MetisFieldSetDef getDataFieldSet();
38
39 /**
40 * Field interface.
41 */
42 interface MetisFieldDef {
43 /**
44 * Obtain the id of the field.
45 *
46 * @return the name of the field.
47 */
48 MetisDataFieldId getFieldId();
49
50 /**
51 * Get the dataType of the field.
52 *
53 * @return the dataType
54 */
55 MetisDataType getDataType();
56
57 /**
58 * Get the maximum length.
59 *
60 * @return the maxLength
61 */
62 Integer getMaxLength();
63
64 /**
65 * Is the field calculated?
66 *
67 * @return true/false
68 */
69 boolean isCalculated();
70
71 /**
72 * Obtain the value of a field.
73 *
74 * @param pObject the object
75 * @return the value
76 */
77 Object getFieldValue(Object pObject);
78
79 /**
80 * Obtain the value of a field cast to a particular class.
81 *
82 * @param <X> the value type
83 * @param pObject the object
84 * @param pClazz the class of the value
85 * @return the value
86 */
87 <X> X getFieldValue(Object pObject,
88 Class<X> pClazz);
89 }
90
91 /**
92 * Versioned Field interface.
93 */
94 interface MetisFieldVersionedDef
95 extends MetisFieldDef {
96 /**
97 * Obtain the index of the field.
98 *
99 * @return the index of the field.
100 */
101 Integer getIndex();
102
103 /**
104 * Is this an equality field?
105 *
106 * @return true/false
107 */
108 boolean isEquality();
109
110 /**
111 * Set the value of a field.
112 *
113 * @param pObject the object
114 * @param pValue the new value
115 * @throws OceanusException on error
116 */
117 void setFieldValue(Object pObject,
118 Object pValue) throws OceanusException;
119
120 /**
121 * Set the value of a field (without checks).
122 *
123 * @param pObject the object
124 * @param pValue the new value
125 */
126 void setFieldUncheckedValue(Object pObject,
127 Object pValue);
128 }
129
130 /**
131 * FieldSet interface.
132 */
133 interface MetisFieldSetDef {
134 /**
135 * Obtain the name of the fieldSet.
136 *
137 * @return the name of the fieldSet.
138 */
139 String getName();
140
141 /**
142 * Obtain the number of versioned fields.
143 *
144 * @return the number of fields.
145 */
146 Integer getNumVersioned();
147
148 /**
149 * Obtain the iterator over the fields.
150 *
151 * @return the iterator
152 */
153 Iterator<MetisFieldDef> fieldIterator();
154
155 /**
156 * Does the item have versioned values?
157 *
158 * @return true/false
159 */
160 boolean hasVersions();
161
162 /**
163 * Does the item have link values?
164 *
165 * @return true/false
166 */
167 default boolean hasLinks() {
168 return false;
169 }
170
171 /**
172 * Does the item have pairedLink values?
173 *
174 * @return true/false
175 */
176 default boolean hasPairedLinks() {
177 return false;
178 }
179
180 /**
181 * Lock the fieldSet.
182 */
183 void setLocked();
184
185 /**
186 * Obtain the itemType.
187 *
188 * @return the itemType
189 */
190 MetisFieldItemType getItemType();
191
192 /**
193 * Obtain field from fieldId.
194 *
195 * @param pId the fieldId.
196 * @return the corresponding field
197 * @throws IllegalArgumentException if name is not present
198 */
199 MetisFieldDef getField(MetisDataFieldId pId);
200 }
201
202 /**
203 * Field Item Type.
204 */
205 interface MetisFieldItemType {
206 /**
207 * Obtain the item name.
208 *
209 * @return the item name
210 */
211 String getItemName();
212
213 /**
214 * Obtain the class of the item.
215 *
216 * @return the clazz
217 */
218 Class<? extends MetisFieldVersionedItem> getClazz();
219 }
220
221 /**
222 * Updateable Item interface.
223 */
224 interface MetisFieldUpdatableItem {
225 /**
226 * Push current values into history buffer ready for changes to be made.
227 */
228 void pushHistory();
229
230 /**
231 * Obtain the next version for the history.
232 *
233 * @return the next version
234 */
235 int getNextVersion();
236
237 /**
238 * Remove the last changes for the history buffer and restore values from it.
239 */
240 void popHistory();
241
242 /**
243 * Check to see whether any changes were made. If no changes were made remove last saved
244 * history since it is not needed.
245 *
246 * @return <code>true</code> if changes were made, <code>false</code> otherwise
247 */
248 boolean checkForHistory();
249
250 /**
251 * Determine whether a particular field has Errors.
252 *
253 * @param pField the particular field
254 * @return <code>true/false</code>
255 */
256 default boolean hasErrors(final MetisDataFieldId pField) {
257 return false;
258 }
259
260 /**
261 * Obtain error details for a field.
262 *
263 * @param pField the field
264 * @return the error details
265 */
266 String getFieldErrors(MetisDataFieldId pField);
267
268 /**
269 * Obtain error details for a set of fields.
270 *
271 * @param pFields the fields
272 * @return the error details
273 */
274 String getFieldErrors(MetisDataFieldId[] pFields);
275
276 /**
277 * Is the item editable?
278 *
279 * @return true/false
280 */
281 default boolean isEditable() {
282 return false;
283 }
284
285 /**
286 * Obtain Object ValueSet.
287 *
288 * @return the ValueSet of the object
289 */
290 MetisFieldVersionValues getValues();
291
292 /**
293 * Obtain original Object ValueSet.
294 *
295 * @return the ValueSet of the object
296 */
297 MetisFieldVersionValues getOriginalValues();
298
299 /**
300 * Obtain Object ValueSet History.
301 *
302 * @return the ValueSet of the object
303 */
304 MetisFieldVersionHistory getValuesHistory();
305
306 /**
307 * Should we skip a ValueSet object?.
308 *
309 * @param pField the field
310 * @return true/false
311 */
312 default boolean skipField(final MetisDataFieldId pField) {
313 return false;
314 }
315 }
316
317 /**
318 * Table Item.
319 */
320 interface MetisFieldTableItem
321 extends MetisFieldItem, MetisDataIndexedItem {
322 }
323 }