Class StructureFinder

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.structures.retriever.StructureFinder

@ThreadSafe public final class StructureFinder extends Object
Represents a class that can be used to retrieve structures when only partial data is provided.

For example, given a set of structures with the names "myDoor", "myPortcullis", "flagThatIsMine", this can be used to retrieve "myDoor" and "myPortcullis" from a search input of "my" (provided both structures are owned by the ICommandSender responsible for the search request.)

This class uses a RollingCache to keep track of provided inputs. This allows both narrowing the search results from new input and rolling back to previous states (e.g. when fixing typos) without causing new database requests. For example, assume we have an input of "My" and some returned results "MyPortcullis" and "MyWindmill". If the next input is then "MyW", the finder will return only "MyWindmill" without querying the database again.

The finder uses the command sender to determine which structures are visible to the user if the command sender is a player. If the command sender is the console, all structures are visible.

  • Method Details

    • processInput

      public StructureFinder processInput(String input, Collection<Property<?>> properties)
      Processes the given input.

      If the new input starts with the last input, the new input is used to narrow down the search results.

      If the new input does not start with the last input, an attempt is made to roll back the search results to a previous state where the last input was a prefix of the new input. If this is not possible, the search is restarted.

      Parameters:
      input - The input to process.
      properties - The properties that the structures must have.
      Returns:
      The current instance of this class.
    • getStructureIdentifiersIfAvailable

      public Optional<Set<String>> getStructureIdentifiersIfAvailable()
      Tries to get all identifiers of structures that have been found, if any.

      This method will return an empty optional if the search is still active on another thread.

      This method uses the default value for fullMatch. See DEFAULT_FULL_MATCH.

      This is a shortcut for getStructureIdentifiersIfAvailable(boolean).

      Returns:
      A list of all structure identifiers (i.e. names or UIDs) of structures that have been found if the search has returned any results. If the search is still active on another thread, this will return an empty optional.
    • getStructureIdentifiersIfAvailable

      public Optional<Set<String>> getStructureIdentifiersIfAvailable(boolean fullMatch)
      Tries to get all identifiers of structures that have been found, if any.

      This method will return an empty optional if the search is still active on another thread.

      Parameters:
      fullMatch - When true, only the entries that have a complete match are returned. E.g. for an input of "door", "door" would be returned, but "door1" would not. Gets the UIDs of all the structures that have been found so far. Defaults to false.
      Returns:
      A list of all structure identifiers (i.e. names or UIDs) of structures that have been found if the search has returned any results. If the search is still active on another thread, this will return an empty optional.
    • getStructureIdentifiers

      public CompletableFuture<Set<String>> getStructureIdentifiers()
      Gets the identifiers of all the structures that have been found using the given search parameters.

      This method uses the default value for fullMatch. See DEFAULT_FULL_MATCH.

      This is a shortcut for getStructureIdentifiers(boolean).

      Returns:
      A list of all identifiers that match the given search parameters. An identifier here can refer to both
    • getStructureIdentifiers

      public CompletableFuture<Set<String>> getStructureIdentifiers(boolean fullMatch)
      Gets the identifiers of all the structures that have been found using the given search parameters.
      Parameters:
      fullMatch - When true, only the entries that have a complete match are returned. E.g. for an input of "door", "door" would be returned, but "door1" would not. Gets the UIDs of all the structures that have been found so far. Defaults to false.
      Returns:
      A list of all identifiers that match the given search parameters. An identifier here can refer to both the UIDs or the names of the structures that match the query.
    • getStructureUIDs

      public Optional<it.unimi.dsi.fastutil.longs.LongSet> getStructureUIDs()
      Gets the UIDs of all the structures that have been found using the given search parameters.

      This method uses the default value for fullMatch. See DEFAULT_FULL_MATCH.

      This is a shortcut for getStructureUIDs(boolean).

      Returns:
      All structure UIDs that have been found if any have been found.
    • getStructureUIDs

      public Optional<it.unimi.dsi.fastutil.longs.LongSet> getStructureUIDs(boolean fullMatch)
      Gets the UIDs of all the structures that have been found using the given search parameters.
      Parameters:
      fullMatch - When true, only the entries that have a complete match are returned. E.g. for an input of "door", "door" would be returned, but "door1" would not. Gets the UIDs of all the structures that have been found so far. Defaults to false.
      Returns:
      All structure UIDs that have been found if any have been found.
    • getStructures

      public CompletableFuture<List<Structure>> getStructures()
      Gets all structures that have been found using the given search parameters.

      This method uses the default value for fullMatch. See DEFAULT_FULL_MATCH.

      This is a shortcut for getStructures(boolean).

      Returns:
      A list of all structures that match the given search parameters.
    • asRetriever

      public StructureRetriever asRetriever(boolean fullMatch)
      Gets all structures that have been found using the given search parameters as a StructureRetriever.
      Parameters:
      fullMatch - When true, only the entries that have a complete match are returned. E.g. for an input of "door", "door" would be returned, but "door1" would not. Gets the UIDs of all the structures that have been found so far. Defaults to false.
      Returns:
      The result as a StructureRetriever.
    • asRetriever

      public StructureRetriever asRetriever()
      Gets all structures that have been found using the given search parameters as a StructureRetriever.

      This method uses the default value for fullMatch. See DEFAULT_FULL_MATCH.

      This is a shortcut for asRetriever(boolean).

      Returns:
      The result as a StructureRetriever.
    • getStructures

      public CompletableFuture<List<Structure>> getStructures(boolean fullMatch)
      Gets all structures that have been found using the given search parameters as a list of Structures.
      Parameters:
      fullMatch - When true, only the entries that have a complete match are returned. E.g. for an input of "door", "door" would be returned, but "door1" would not. Gets the UIDs of all the structures that have been found so far. Defaults to false.
      Returns:
      A list of all structures that match the given search parameters.
    • toString

      public String toString()
      Overrides:
      toString in class Object