Package app.entity

Class RepositoryList<T extends ITaggedItem>

java.lang.Object
app.entity.RepositoryList<T>
Type Parameters:
T - The type of items in the repository, which must implement the ITaggedItem interface.
All Implemented Interfaces:
ISerializable, Iterable<T>
Direct Known Subclasses:
CampList, EnquiryList, SuggestionList, UserList

public abstract class RepositoryList<T extends ITaggedItem> extends Object implements Iterable<T>, ISerializable
The RepositoryList class is an abstract base class representing a list-based repository of items implementing the ITaggedItem interface.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected List<T>
    The list containing all items in the repository.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty repository list.
    Constructs a repository list with the given list of items.
    Constructs a repository list with the given set of items.
    Constructs a repository list with the given array of items.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(T object)
    Adds an item to the repository.
    boolean
    Clears all items from the repository.
    get(int index)
    Gets the item at the specified index in the repository.
    Returns an iterator over the items in the repository.
    boolean
    remove(T object)
    Removes an item from the repository.
    int
    Returns the size of the repository.
    Converts the repository to an array.
    boolean
    update(T object)
    Updates an item in the repository based on its ID.
    boolean
    update(T object, int index)
    Updates the item at the specified index in the repository.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface app.entity.interfaces.ISerializable

    serialize

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • all

      protected List<T extends ITaggedItem> all
      The list containing all items in the repository.
  • Constructor Details

    • RepositoryList

      public RepositoryList(List<T> all)
      Constructs a repository list with the given list of items.
      Parameters:
      all - The list of items to initialize the repository.
    • RepositoryList

      public RepositoryList()
      Constructs an empty repository list.
    • RepositoryList

      public RepositoryList(T[] all)
      Constructs a repository list with the given array of items.
      Parameters:
      all - The array of items to initialize the repository.
    • RepositoryList

      public RepositoryList(Set<T> all)
      Constructs a repository list with the given set of items.
      Parameters:
      all - The set of items to initialize the repository.
  • Method Details

    • size

      public int size()
      Returns the size of the repository.
      Returns:
      The number of items in the repository.
    • iterator

      public Iterator<T> iterator()
      Returns an iterator over the items in the repository.
      Specified by:
      iterator in interface Iterable<T extends ITaggedItem>
      Returns:
      An iterator over the items in the repository.
    • get

      public T get(int index)
      Gets the item at the specified index in the repository.
      Parameters:
      index - The index of the item to retrieve.
      Returns:
      The item at the specified index, or null if the index is out of bounds.
    • add

      public boolean add(T object)
      Adds an item to the repository. If an item with the same ID already exists in the repository, it is replaced.
      Parameters:
      object - The item to add or replace in the repository.
      Returns:
      true if the item was added or replaced successfully, false otherwise.
    • remove

      public boolean remove(T object)
      Removes an item from the repository.
      Parameters:
      object - The item to remove from the repository.
      Returns:
      true if the item was successfully removed, false otherwise.
    • update

      public boolean update(T object, int index)
      Updates the item at the specified index in the repository.
      Parameters:
      object - The item to use for the update.
      index - The index of the item to update.
      Returns:
      true if the update was successful, false otherwise.
    • update

      public boolean update(T object)
      Updates an item in the repository based on its ID. If an item with the same ID is found, it is replaced.
      Parameters:
      object - The item to use for the update.
      Returns:
      true if the update was successful, false otherwise.
    • clear

      public boolean clear()
      Clears all items from the repository.
      Returns:
      true if the repository was cleared successfully, false otherwise.
    • toArray

      public Object[] toArray()
      Converts the repository to an array.
      Returns:
      An array containing all items in the repository.