Module dev.metaschema.databind
Interface IModelInstanceCollectionInfo<ITEM>
- Type Parameters:
ITEM- the Java type of items in the collection
- All Known Implementing Classes:
AbstractModelInstanceCollectionInfo
public interface IModelInstanceCollectionInfo<ITEM>
Provides information about the collection type for a model instance.
This interface abstracts the differences between singleton, list, and map collection types for model instances.
-
Method Summary
Modifier and TypeMethodDescriptiondeepCopyItems(IBoundObject fromObject, IBoundObject toObject) Create a deep copy of items from one object to another.Get an empty value appropriate for this collection type.Get the associated instance binding for which this info is for.default Collection<? extends ITEM>getItemsFromParentInstance(Object parentInstance) Get the items from a parent instance's property value.Collection<? extends ITEM>getItemsFromValue(Object value) Get the items from a raw value object.Get the type of the bound object.booleanDetermine if the value is empty.static <T> IModelInstanceCollectionInfo<T>of(IBoundInstanceModel<T> instance) Create a new collection info instance for the provided model instance.readItems(IModelInstanceReadHandler<ITEM> handler) Read the value data for the model instance.intGet the number of items associated with the value.voidwriteItems(IModelInstanceWriteHandler<ITEM> handler, Object value) Write the items represented by the given value.
-
Method Details
-
of
Create a new collection info instance for the provided model instance.The appropriate collection info type is determined based on the instance's maximum occurrence and JSON group-as behavior.
- Type Parameters:
T- the Java type of items in the collection- Parameters:
instance- the model instance to create collection info for- Returns:
- the new collection info instance
-
getInstance
Get the associated instance binding for which this info is for.- Returns:
- the instance binding
-
size
Get the number of items associated with the value.- Parameters:
value- the value to identify items for- Returns:
- the number of items, which will be
0if value isnull
-
isEmpty
Determine if the value is empty.- Parameters:
value- the value representing a collection- Returns:
trueif the value represents a collection with no items orfalseotherwise
-
getItemType
Get the type of the bound object.- Returns:
- the raw type of the bound object
-
getItemsFromParentInstance
@NonNull default Collection<? extends ITEM> getItemsFromParentInstance(@NonNull Object parentInstance) Get the items from a parent instance's property value.- Parameters:
parentInstance- the parent instance to get items from- Returns:
- a collection of items, which may be empty but never
null
-
getItemsFromValue
Get the items from a raw value object.- Parameters:
value- the value object to extract items from- Returns:
- a collection of items, which may be empty but never
null
-
emptyValue
Object emptyValue()Get an empty value appropriate for this collection type.- Returns:
- an empty collection value, or
nullfor singleton types
-
deepCopyItems
Object deepCopyItems(@NonNull IBoundObject fromObject, @NonNull IBoundObject toObject) throws BindingException Create a deep copy of items from one object to another.- Parameters:
fromObject- the source object to copy items fromtoObject- the target object to copy items to- Returns:
- the copied value
- Throws:
BindingException- if an error occurs during the deep copy
-
readItems
Read the value data for the model instance.This method will return a value based on the instance's value type.
- Parameters:
handler- the item parsing handler- Returns:
- the item collection object or
nullif the instance is not defined - Throws:
IOException- if there was an error when reading the data
-
writeItems
void writeItems(@NonNull IModelInstanceWriteHandler<ITEM> handler, @NonNull Object value) throws IOException Write the items represented by the given value.- Parameters:
handler- the item writing handlervalue- the value containing items to write- Throws:
IOException- if there was an error when writing the data
-