Class HelpEntryList<S extends Source>
java.lang.Object
studio.mevera.imperat.command.tree.help.HelpEntryList<S>
- Type Parameters:
S- the source type
A custom list implementation that maintains insertion order, prevents duplicates,
and supports indexing - implemented without using any Java collections.
Uses a dynamically resizing array with linear search for duplicate detection. Optimized for small to medium-sized lists (typical for help entries).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new HelpEntryList with default initial capacity.HelpEntryList(int initialCapacity) Creates a new HelpEntryList with specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an entry if it's not already present.intaddAll(HelpEntryList<S> other) Adds all entries from another HelpEntryList.intcapacity()Returns the current capacity of the internal array.voidclear()Clears all entries.booleanChecks if an entry exists in the list.static <S extends Source>
HelpEntryList<S>empty()booleanget(int index) Gets an entry by index.inthashCode()intReturns the index of an entry.booleanisEmpty()Checks if the list is empty.iterator()remove(int index) Removes an entry by index.booleanRemoves a specific entry.intsize()Returns the number of entries.subList(int fromIndex, int toIndex) Creates a copy of a range of elements.toArray()Converts to an array.toSet()Converts to a Java Set (LinkedHashSet).toString()voidTrims the internal capacity to the current size.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
HelpEntryList
public HelpEntryList()Creates a new HelpEntryList with default initial capacity. -
HelpEntryList
public HelpEntryList(int initialCapacity) Creates a new HelpEntryList with specified initial capacity.- Parameters:
initialCapacity- the initial capacity
-
-
Method Details
-
empty
-
add
Adds an entry if it's not already present.- Parameters:
entry- the entry to add- Returns:
trueif the entry was added,falseif it was a duplicate
-
get
Gets an entry by index.- Parameters:
index- the index- Returns:
- the entry at the specified index
- Throws:
IndexOutOfBoundsException- if index is out of range
-
size
public int size()Returns the number of entries.- Returns:
- the size of the list
-
isEmpty
public boolean isEmpty()Checks if the list is empty.- Returns:
trueif empty,falseotherwise
-
contains
Checks if an entry exists in the list.- Parameters:
entry- the entry to check- Returns:
trueif the entry exists,falseotherwise
-
clear
public void clear()Clears all entries. -
indexOf
Returns the index of an entry.- Parameters:
entry- the entry to find- Returns:
- the index of the entry, or -1 if not found
-
remove
Removes an entry by index.- Parameters:
index- the index to remove- Returns:
- the removed entry
- Throws:
IndexOutOfBoundsException- if index is out of range
-
remove
Removes a specific entry.- Parameters:
entry- the entry to remove- Returns:
trueif the entry was removed,falseif not found
-
toArray
Converts to an array.- Returns:
- an array containing all entries
-
trimToSize
public void trimToSize()Trims the internal capacity to the current size. Call this after adding all elements to save memory. -
subList
Creates a copy of a range of elements.- Parameters:
fromIndex- low endpoint (inclusive)toIndex- high endpoint (exclusive)- Returns:
- a new HelpEntryList containing the specified range
-
addAll
Adds all entries from another HelpEntryList.- Parameters:
other- the other list- Returns:
- the number of entries actually added (excluding duplicates)
-
capacity
public int capacity()Returns the current capacity of the internal array.- Returns:
- the current capacity
-
iterator
-
equals
-
hashCode
public int hashCode() -
toString
-
toSet
Converts to a Java Set (LinkedHashSet). This is the only method that uses Java collections for API compatibility.- Returns:
- a LinkedHashSet containing all entries in order
-