Class ContentHandler<RECEIVER,​SELF extends ContentHandler<RECEIVER,​SELF>>

  • All Implemented Interfaces:
    Insertable<RECEIVER,​SELF>, Replaceable<RECEIVER,​SELF>
    Direct Known Subclasses:
    TextParser

    public abstract class ContentHandler<RECEIVER,​SELF extends ContentHandler<RECEIVER,​SELF>>
    extends java.lang.Object
    implements Replaceable<RECEIVER,​SELF>, Insertable<RECEIVER,​SELF>
    • Field Detail

      • parser

        protected java.util.function.BiFunction<RECEIVER,​java.lang.String,​java.lang.String> parser
      • lineSeparator

        protected java.lang.String lineSeparator
      • paramReplacer

        @NotNull
        protected @NotNull ParamReplacer<RECEIVER> paramReplacer
        Used to store the placeholders of the message
      • params

        @NotNull
        protected @NotNull java.lang.String[] params
      • insertion

        @NotNull
        protected final @NotNull java.util.Map<java.lang.String,​@Nullable java.util.function.Function<RECEIVER,​java.util.List<java.lang.String>>> insertion
        Used to store the insertion of the message
      • disableInsertion

        protected boolean disableInsertion
    • Constructor Detail

      • ContentHandler

        public ContentHandler()
    • Method Detail

      • self

        public abstract SELF self()
      • disableInsertion

        public SELF disableInsertion()
        Disable the insertion of the text.
        If the insertion is disabled, the text will be parsed directly.
        Returns:
        the current ContentHandler instance
      • enableInsertion

        public SELF enableInsertion()
        Enable the insertion of the text.
        Returns:
        the current ContentHandler instance
      • lineSeparator

        public SELF lineSeparator​(@NotNull
                                  @NotNull java.lang.String lineSeparator)
        Set the line separator for the text.
        Parameters:
        lineSeparator - the line separator, default is System.lineSeparator()
        Returns:
        the current ContentHandler instance
      • placeholders

        public SELF placeholders​(@NotNull
                                 @NotNull java.util.Map<java.lang.String,​java.lang.Object> placeholders)
        Set all the placeholders for the text.
        Will override the previous placeholders modifications.
        Parameters:
        placeholders - the placeholders
        Returns:
        the current ContentHandler instance
      • placeholders

        public SELF placeholders​(@NotNull
                                 @NotNull java.util.function.Consumer<java.util.Map<java.lang.String,​java.lang.Object>> consumer)
        Set the placeholders for the text.
        Parameters:
        consumer - the placeholders
        Returns:
        the current ContentHandler instance
      • placeholders

        public SELF placeholders​(@Nullable
                                 @Nullable java.lang.Object... values)
        Set the placeholders for the text.
        Parameters:
        values - The values to replace the params(String...).
        Returns:
        the current ContentHandler instance
      • placeholder

        public SELF placeholder​(@NotNull
                                @NotNull java.lang.String key,
                                @Nullable
                                @Nullable java.lang.Object value)
        Set the placeholder for the text.
        Parameters:
        key - the key of the placeholder
        value - the value of the placeholder
        Returns:
        the current ContentHandler instance
      • params

        public SELF params​(@NotNull
                           @NotNull java.lang.String... params)
        Set the params for the text, used for placeholders(Object...) to build the placeholders.
        Parameters:
        params - the params
        Returns:
        the current ContentHandler instance
      • insert

        public SELF insert​(@NotNull
                           @NotNull java.lang.String id,
                           @Nullable
                           @Nullable java.util.function.Function<RECEIVER,​java.util.List<java.lang.String>> supplier)
        Description copied from interface: Insertable
        Insert the specific contents by the id.
        Specified by:
        insert in interface Insertable<RECEIVER,​SELF extends ContentHandler<RECEIVER,​SELF>>
        Parameters:
        id - the id of the insertion text
        supplier - to supply the lines to insert
        Returns:
        the current ContentHandler instance
      • parser

        public SELF parser​(@NotNull
                           @NotNull java.util.function.BiFunction<RECEIVER,​java.lang.String,​java.lang.String> parser)
        Set the parser for the text.
        Parameters:
        parser - The parser
        Returns:
        The current ContentHandler instance
      • parse

        @Nullable
        protected @Nullable java.lang.String parse​(@Nullable
                                                   RECEIVER receiver,
                                                   @NotNull
                                                   @NotNull java.lang.String text)
        Parse the supplied single text for the receiver.
        Parameters:
        receiver - the receiver
        text - the text to parse
        Returns:
        the parsed text
      • handle

        public void handle​(@NotNull
                           @NotNull TextContents contents,
                           @Nullable
                           RECEIVER receiver,
                           @NotNull
                           @NotNull java.util.function.Consumer<java.lang.String> lineConsumer)
      • setPlaceholders

        public static java.lang.String setPlaceholders​(@NotNull
                                                       @NotNull java.lang.String messages,
                                                       @NotNull
                                                       @NotNull java.util.Map<java.lang.String,​java.lang.Object> placeholders)
      • buildParams

        public static java.util.Map<java.lang.String,​java.lang.Object> buildParams​(@NotNull
                                                                                         @NotNull java.util.function.UnaryOperator<java.lang.String> paramBuilder,
                                                                                         @Nullable
                                                                                         @Nullable java.lang.String[] params,
                                                                                         @Nullable
                                                                                         @Nullable java.lang.Object[] values)