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 Details

    • of

      @NonNull static <T> IModelInstanceCollectionInfo<T> of(@NonNull IBoundInstanceModel<T> instance)
      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

      @NonNull IBoundInstanceModel<ITEM> getInstance()
      Get the associated instance binding for which this info is for.
      Returns:
      the instance binding
    • size

      int size(@Nullable Object value)
      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 0 if value is null
    • isEmpty

      boolean isEmpty(@Nullable Object value)
      Determine if the value is empty.
      Parameters:
      value - the value representing a collection
      Returns:
      true if the value represents a collection with no items or false otherwise
    • getItemType

      @NonNull Class<? extends ITEM> 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

      @NonNull Collection<? extends ITEM> getItemsFromValue(Object value)
      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 null for 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 from
      toObject - the target object to copy items to
      Returns:
      the copied value
      Throws:
      BindingException - if an error occurs during the deep copy
    • readItems

      @Nullable Object readItems(@NonNull IModelInstanceReadHandler<ITEM> handler) throws IOException
      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 null if 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 handler
      value - the value containing items to write
      Throws:
      IOException - if there was an error when writing the data