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 theITaggedIteminterface.
- 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 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty repository list.RepositoryList(List<T> all) Constructs a repository list with the given list of items.RepositoryList(Set<T> all) Constructs a repository list with the given set of items.RepositoryList(T[] all) Constructs a repository list with the given array of items. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an item to the repository.booleanclear()Clears all items from the repository.get(int index) Gets the item at the specified index in the repository.iterator()Returns an iterator over the items in the repository.booleanRemoves an item from the repository.intsize()Returns the size of the repository.Object[]toArray()Converts the repository to an array.booleanUpdates an item in the repository based on its ID.booleanUpdates 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, waitMethods inherited from interface app.entity.interfaces.ISerializable
serializeMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
all
The list containing all items in the repository.
-
-
Constructor Details
-
RepositoryList
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
Constructs a repository list with the given array of items.- Parameters:
all- The array of items to initialize the repository.
-
RepositoryList
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
Returns an iterator over the items in the repository.- Specified by:
iteratorin interfaceIterable<T extends ITaggedItem>- Returns:
- An iterator over the items in the repository.
-
get
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
nullif the index is out of bounds.
-
add
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:
trueif the item was added or replaced successfully,falseotherwise.
-
remove
Removes an item from the repository.- Parameters:
object- The item to remove from the repository.- Returns:
trueif the item was successfully removed,falseotherwise.
-
update
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:
trueif the update was successful,falseotherwise.
-
update
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:
trueif the update was successful,falseotherwise.
-
clear
public boolean clear()Clears all items from the repository.- Returns:
trueif the repository was cleared successfully,falseotherwise.
-
toArray
Converts the repository to an array.- Returns:
- An array containing all items in the repository.
-