Interface TagResolver

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  TagResolver.Builder
      A builder to gradually construct tag resolvers.
      static interface  TagResolver.Single
      A resolver that only handles a single tag key.
      static interface  TagResolver.WithoutArguments
      A tag resolver that only handles tags which do not take arguments.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      static @NotNull TagResolver.Builder builder()
      Create a new builder for a tag resolver.
      static @NotNull TagResolver caching​(@NotNull TagResolver.WithoutArguments resolver)
      Constructs a tag resolver capable of caching resolved tags.
      static @NotNull TagResolver empty()
      An empty tag resolver that will return null for all resolve attempts.
      boolean has​(@NotNull java.lang.String name)
      Get whether this resolver handles tags with a certain name.
      @Nullable Tag resolve​(@NotNull java.lang.String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx)
      Gets a tag from this resolver based on the current state.
      static @NotNull TagResolver resolver​(@NotNull java.lang.Iterable<? extends TagResolver> resolvers)
      Constructs a tag resolver capable of resolving from multiple sources.
      static @NotNull TagResolver resolver​(@NotNull java.lang.String name, @NotNull java.util.function.BiFunction<ArgumentQueue,​Context,​Tag> handler)
      Create a tag resolver that only responds to a single tag name, and whose value does not depend on that name.
      static @NotNull TagResolver.Single resolver​(@NotNull java.lang.String name, @NotNull Tag tag)
      A tag resolver that will resolve a single tag by a case-insensitive key.
      static @NotNull TagResolver resolver​(@NotNull java.util.Set<java.lang.String> names, @NotNull java.util.function.BiFunction<ArgumentQueue,​Context,​Tag> handler)
      Create a tag resolver that only responds to certain tag names, and whose value does not depend on that name.
      static @NotNull TagResolver resolver​(@NotNull TagResolver @NotNull ... resolvers)
      Constructs a tag resolver capable of resolving from multiple sources.
      static @NotNull TagResolver standard()
      Get the tag resolver that resolves all standard tags.
      static @NotNull java.util.stream.Collector<TagResolver,​?,​TagResolver> toTagResolver()
      A collector that will combine a stream of resolvers into one joined resolver.
    • Method Detail

      • builder

        @NotNull
        static @NotNull TagResolver.Builder builder()
        Create a new builder for a tag resolver.
        Returns:
        the tag resolver builder
        Since:
        4.10.0
      • standard

        @NotNull
        static @NotNull TagResolver standard()
        Get the tag resolver that resolves all standard tags.

        This is the default resolver used by parsers.

        Returns:
        the default resolver
        Since:
        4.10.0
      • empty

        @NotNull
        static @NotNull TagResolver empty()
        An empty tag resolver that will return null for all resolve attempts.
        Returns:
        the tag resolver
        Since:
        4.10.0
      • resolver

        static @NotNull TagResolver.Single resolver​(@TagPattern @NotNull
                                                    @NotNull java.lang.String name,
                                                    @NotNull
                                                    @NotNull Tag tag)
        A tag resolver that will resolve a single tag by a case-insensitive key.
        Parameters:
        name - the name of the tag to resolve
        tag - the tag logic to return
        Returns:
        a new tag resolver
        Since:
        4.10.0
      • resolver

        @NotNull
        static @NotNull TagResolver resolver​(@TagPattern @NotNull
                                             @NotNull java.lang.String name,
                                             @NotNull
                                             @NotNull java.util.function.BiFunction<ArgumentQueue,​Context,​Tag> handler)
        Create a tag resolver that only responds to a single tag name, and whose value does not depend on that name.
        Parameters:
        name - the name to respond to
        handler - the tag handler, may throw ParsingException if provided arguments are in an invalid format
        Returns:
        a resolver that creates tags using the provided handler
        Since:
        4.10.0
      • resolver

        @NotNull
        static @NotNull TagResolver resolver​(@NotNull
                                             @NotNull java.util.Set<java.lang.String> names,
                                             @NotNull
                                             @NotNull java.util.function.BiFunction<ArgumentQueue,​Context,​Tag> handler)
        Create a tag resolver that only responds to certain tag names, and whose value does not depend on that name.
        Parameters:
        names - the names to respond to
        handler - the tag handler, may throw ParsingException if provided arguments are in an invalid format
        Returns:
        a resolver that creates tags using the provided handler
        Since:
        4.10.0
      • resolver

        @NotNull
        static @NotNull TagResolver resolver​(@NotNull
                                             @NotNull TagResolver @NotNull ... resolvers)
        Constructs a tag resolver capable of resolving from multiple sources.

        The last specified resolver takes priority.

        Parameters:
        resolvers - the tag resolvers
        Returns:
        the tag resolver
        Since:
        4.10.0
      • resolver

        @NotNull
        static @NotNull TagResolver resolver​(@NotNull
                                             @NotNull java.lang.Iterable<? extends TagResolver> resolvers)
        Constructs a tag resolver capable of resolving from multiple sources.

        The last specified resolver takes priority.

        The provided iterable is copied. This means changes to the iterable will not reflect in the returned resolver.

        Parameters:
        resolvers - the tag resolvers
        Returns:
        the tag resolver
        Since:
        4.10.0
      • caching

        @NotNull
        static @NotNull TagResolver caching​(@NotNull TagResolver.WithoutArguments resolver)
        Constructs a tag resolver capable of caching resolved tags.

        The resolver can return null to indicate it cannot resolve a placeholder. Once a string to replacement mapping has been created, it will be cached to avoid the cost of recreating the replacement.

        Due to the complexity of handling lookups for tags with arguments, the built-in cache does not support anything but tags without arguments.

        Parameters:
        resolver - the resolver
        Returns:
        the caching tag resolver
        Since:
        4.10.0
      • toTagResolver

        @NotNull
        static @NotNull java.util.stream.Collector<TagResolver,​?,​TagResolver> toTagResolver()
        A collector that will combine a stream of resolvers into one joined resolver.
        Returns:
        a collector for tag resolvers
        Since:
        4.10.0
      • resolve

        @Nullable
        @Nullable Tag resolve​(@TagPattern @NotNull
                              @NotNull java.lang.String name,
                              @NotNull
                              @NotNull ArgumentQueue arguments,
                              @NotNull
                              @NotNull Context ctx)
                       throws ParsingException
        Gets a tag from this resolver based on the current state.
        Parameters:
        name - the tag name
        arguments - the arguments passed to the tag
        ctx - the parse context
        Returns:
        a possible tag
        Throws:
        ParsingException - if the provided arguments are invalid
        Since:
        4.10.0
      • has

        boolean has​(@NotNull
                    @NotNull java.lang.String name)
        Get whether this resolver handles tags with a certain name.

        This does not allow validating arguments.

        Parameters:
        name - the tag name
        Returns:
        whether this resolver has a tag with this name
        Since:
        4.10.0