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.metis.data.MetisDataItem.MetisDataFieldId;
20 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataIndexedItem;
21 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataObjectFormat;
22 import io.github.tonywasher.joceanus.metis.data.MetisDataType;
23 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
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 /**
215 * Table Item.
216 */
217 interface MetisFieldTableItem
218 extends MetisFieldItem, MetisDataIndexedItem {
219 }
220
221 /**
222 * FieldSet.
223 *
224 * @param <T> the data type
225 */
226 interface MetisFieldSetCtl<T extends MetisFieldItem> {
227 /**
228 * Obtain the field class.
229 *
230 * @return the field class
231 */
232 Class<T> getFieldClass();
233
234 /**
235 * Obtain next value index.
236 *
237 * @return the next index
238 */
239 Integer getNextIndex();
240 }
241 }