Class HelpEntryList<S extends Source>

java.lang.Object
studio.mevera.imperat.command.tree.help.HelpEntryList<S>
Type Parameters:
S - the source type
All Implemented Interfaces:
Iterable<HelpEntry<S>>

public final class HelpEntryList<S extends Source> extends Object implements Iterable<HelpEntry<S>>
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 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

      public static <S extends Source> HelpEntryList<S> empty()
    • add

      public boolean add(HelpEntry<S> entry)
      Adds an entry if it's not already present.
      Parameters:
      entry - the entry to add
      Returns:
      true if the entry was added, false if it was a duplicate
    • get

      public HelpEntry<S> get(int index)
      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:
      true if empty, false otherwise
    • contains

      public boolean contains(HelpEntry<S> entry)
      Checks if an entry exists in the list.
      Parameters:
      entry - the entry to check
      Returns:
      true if the entry exists, false otherwise
    • clear

      public void clear()
      Clears all entries.
    • indexOf

      public int indexOf(HelpEntry<S> entry)
      Returns the index of an entry.
      Parameters:
      entry - the entry to find
      Returns:
      the index of the entry, or -1 if not found
    • remove

      public HelpEntry<S> remove(int index)
      Removes an entry by index.
      Parameters:
      index - the index to remove
      Returns:
      the removed entry
      Throws:
      IndexOutOfBoundsException - if index is out of range
    • remove

      public boolean remove(HelpEntry<S> entry)
      Removes a specific entry.
      Parameters:
      entry - the entry to remove
      Returns:
      true if the entry was removed, false if not found
    • toArray

      public HelpEntry<S>[] 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

      public HelpEntryList<S> subList(int fromIndex, int toIndex)
      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

      public int addAll(HelpEntryList<S> other)
      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

      public Iterator<HelpEntry<S>> iterator()
      Specified by:
      iterator in interface Iterable<S extends Source>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toSet

      public Set<HelpEntry<S>> 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