Class CommandPath

java.lang.Object
revxrsal.commands.core.CommandPath
All Implemented Interfaces:
Comparable<CommandPath>, Iterable<String>
Direct Known Subclasses:
MutableCommandPath

public class CommandPath extends Object implements Iterable<String>, Comparable<CommandPath>
Represents the full, qualified, case-insensitive path of a command.

This class is immutable, hence is thread-safe, and is intended to be used as a key for maps that use hashing.

  • Field Details

    • path

      protected final LinkedList<String> path
      Represents the actual path of this command
  • Method Details

    • get

      @NotNull public static @NotNull CommandPath get(@NotNull @NotNull String... path)
      Returns the corresponding CommandPath to the given path
      Parameters:
      path - Path to wrap
      Returns:
      The command path
    • get

      @NotNull public static @NotNull CommandPath get(@NotNull @NotNull Collection<String> path)
      Returns the corresponding CommandPath to the given path
      Parameters:
      path - Path to wrap
      Returns:
      The command path
    • toRealString

      @NotNull public @NotNull String toRealString()
      Converts this path to a string, where all elements in the path are joined by a space.
      Returns:
      The real path
    • toList

      @NotNull public @NotNull LinkedList<String> toList()
      Returns a clone linked list of this path.
      Returns:
      A linked list of this path
    • getParent

      @NotNull public @NotNull String getParent()
      Returns the root parent of this command path. This is equivilent to calling getFirst().
      Returns:
      The parent
    • getName

      @NotNull public @NotNull String getName()
      Returns the name (tail) of this command path. This is equivilent to calling getLast().
      Returns:
      The name
    • getFirst

      @NotNull public @NotNull String getFirst()
      Returns the first element of this command path
      Returns:
      The first element
    • getLast

      @NotNull public @NotNull String getLast()
      Returns the last element in this command path
      Returns:
      The last element
    • get

      @NotNull public @NotNull String get(int index)
      Returns the string element at the given index.
      Parameters:
      index - Index to fetch at
      Returns:
      The string at the given index
      Throws:
      IndexOutOfBoundsException - -
    • size

      public int size()
      Returns the size of this command path
      Returns:
      The path size
    • isRoot

      public boolean isRoot()
      Returns whether this path represents a root command path or not
      Returns:
      If this path represents a root path
    • getCategoryPath

      @Nullable public @Nullable CommandPath getCategoryPath()
      Returns the full path of the category of this command. This will return null if this path represents a root command.
      Returns:
      The command category path
    • getSubcommandPath

      @NotNull public @NotNull LinkedList<String> getSubcommandPath()
      Returns the subcommand path of this command path. This will simply drop the command's parent name.
      Returns:
      The subcommand path.
    • toMutablePath

      public MutableCommandPath toMutablePath()
      Returns a mutable copy of this command path.
      Returns:
      The mutable copy.
    • isMutable

      public boolean isMutable()
      Returns whether is this command path mutable or not.

      This should only return true in cases of MutableCommandPath.

      Returns:
      Whether is the path mutable or not.
    • isChildOf

      public boolean isChildOf(CommandPath other)
      Tests whether is this path a child of the specified path or not
      Parameters:
      other - Path to test against
      Returns:
      True if this is a child of it, false if otherwise.
    • isParentOf

      public boolean isParentOf(CommandPath other)
      Tests whether is this path a parent of the specified path or not
      Parameters:
      other - Path to test against
      Returns:
      True if this is a child of it, false if otherwise.
    • 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
    • iterator

      @NotNull public @NotNull Iterator<String> iterator()
      Specified by:
      iterator in interface Iterable<String>
    • compareTo

      public int compareTo(@NotNull @NotNull CommandPath o)
      Specified by:
      compareTo in interface Comparable<CommandPath>