Interface JKListHolder<T extends JKIndexable>

Type Parameters:
T - Specifies the type of items this list holder can contain. The items must implement the JKIndexable interface.

public interface JKListHolder<T extends JKIndexable>
This Interface is a generic interface for holding a list of items that implement the JKIndexable interface.

Implementation of this interface provides methods for managing and accessing the list of items.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    addItem(T item)
    This method adds a new item to the list of items, specifying its name in case it didn't have one, then set its parent to this JKListHolder object before returning the item.
    default T
    findItemByIndex(int index)
    This method finds the item associated with the given index from the list of items.
    default void
    This method update the list of items by sorting it in an ascending order, according to the item index.
    default T
    getItemAtIndex(int index)
    This method gets the item at the provided index in the list of items.
    default T
    This method gets the item associated with the specified unique identifier (UID).
    This method gets the item description.
    This method gets the list of all held items.
    default T
    This method retrieves the item that follows the specified item in the list.
    default T
    This method retrieves the item that precedes the specified item in the list.
    default void
    moveItemBackward(int index)
    This method moves the item associated with the specified index one index backward in the list.
    default void
    This method moves the item associated with the specified unique identifier (UID) backward one index, then shift the rest of the items accordingly.
    default void
    moveItemForward(int index)
    This method moves the item associated with the specifies index one index forward in the list.
    default void
    This method moves the item associated with the specified unique identifier (UID) forward one index, then shift the rest of the items accordingly.
    default void
    moveItemToIndex(T original, int newIndex)
    This method moves the specified item to the provided new index.
    default void
    This method recalculates the indices of the items in the list to make them sequential.
    default void
    removeItem(T item)
    This method removes the item specified from the list of items in the JKListHolder object.
    default T
    This method remove the item associated with the specified unique identifier (UID).
    default void
    This method loops over all the items in the list of items, then reset their unique identifiers (UID).
    static String
    suggestName(String prefix, List<?> list)
    This method suggests a unique name based on the provided prefix, ensuring its uniqueness within the given list.
  • Method Details

    • getItemDesc

      @BsonIgnore String getItemDesc()
      This method gets the item description.
      Returns:
      the description of the item.
    • getItemsList

      @BsonIgnore List<T> getItemsList()
      This method gets the list of all held items.
      Returns:
      a list of all the items held.
    • addItem

      default T addItem(T item)
      This method adds a new item to the list of items, specifying its name in case it didn't have one, then set its parent to this JKListHolder object before returning the item.
      Parameters:
      item - Specifies the item to be added.
      Returns:
      the item after it got added to the list.
    • resetItemsUids

      default void resetItemsUids()
      This method loops over all the items in the list of items, then reset their unique identifiers (UID).

      In case the item is an instance of JKBaseModel class, it calls up the resetUid() method instead.

      See Also:
    • removeItemByUId

      default T removeItemByUId(String uid)
      This method remove the item associated with the specified unique identifier (UID).
      Parameters:
      uid - Specifies the unique identifier (UID) of the item to be removed.
      Returns:
      the item with its parent set to null instead of this JKListHolder object. returns null if the list of items doesn't contain an item with the provided unique identifier (UID).
    • getItemAtIndex

      default T getItemAtIndex(int index)
      This method gets the item at the provided index in the list of items.
      Parameters:
      index - Specifies the item index in the list of items.
      Returns:
      the item at the specified index in the list of items.
    • findItemByIndex

      default T findItemByIndex(int index)
      This method finds the item associated with the given index from the list of items.
      Parameters:
      index - Specifies the index the item is associated with.
      Returns:
      the item in the list of items. returns null if there's no item with the specified index.
    • fireItemsUpdated

      default void fireItemsUpdated()
      This method update the list of items by sorting it in an ascending order, according to the item index.
    • removeItem

      default void removeItem(T item)
      This method removes the item specified from the list of items in the JKListHolder object.
      Parameters:
      item - Specifies the item to be removed from the list.
    • getItemByUid

      default T getItemByUid(String uid)
      This method gets the item associated with the specified unique identifier (UID).
      Parameters:
      uid - Specifies the item unique identifier (UID).
      Returns:
      the item which the unique identifier (UID) belongs to. Returns null, if there's no item with the specified UID.
    • moveItemBackward

      default void moveItemBackward(String uid)
      This method moves the item associated with the specified unique identifier (UID) backward one index, then shift the rest of the items accordingly.
      Parameters:
      uid - Specifies the unique identifier (UID) of the item to be moved.
    • moveItemForward

      default void moveItemForward(String uid)
      This method moves the item associated with the specified unique identifier (UID) forward one index, then shift the rest of the items accordingly.
      Parameters:
      uid - Specifies the unique identifier (UID) of the item to be moved.
    • moveItemToIndex

      default void moveItemToIndex(T original, int newIndex)
      This method moves the specified item to the provided new index.
      Parameters:
      original - Specifies the item to be moved.
      newIndex - Specifies the new index for the item to be moved to.
    • getNextSibilingItem

      default T getNextSibilingItem(T field)
      This method retrieves the item that follows the specified item in the list.
      Parameters:
      field - Specifies the item for which to find the following item.
      Returns:
      the item that comes after the provided item in the list.
    • getPreviouseSibilingItem

      default T getPreviouseSibilingItem(T field)
      This method retrieves the item that precedes the specified item in the list.
      Parameters:
      field - Specifies the item for which to find the preceding item.
      Returns:
      the item that comes before the provided item in the list.
    • moveItemBackward

      default void moveItemBackward(int index)
      This method moves the item associated with the specified index one index backward in the list.
      Parameters:
      index - Specifies the index which the item to be moved is associated with.
    • moveItemForward

      default void moveItemForward(int index)
      This method moves the item associated with the specifies index one index forward in the list.
      Parameters:
      index - Specifies the index which the item to be moved is associated with.
    • recaclulateIndices

      default void recaclulateIndices()
      This method recalculates the indices of the items in the list to make them sequential.
    • suggestName

      static String suggestName(String prefix, List<?> list)
      This method suggests a unique name based on the provided prefix, ensuring its uniqueness within the given list.

      This method takes a prefix and a list of objects and generates a suggestion by appending incremental numbers to the prefix. The generated suggestion ensures that it is unique within the list of existing objects.

      Parameters:
      prefix - Specifies the prefix for the suggested name.
      list - Specifies the list of objects to check for uniqueness.
      Returns:
      the suggested name that combine the prefix with incremental number for uniqueness.