Class ExplainMapBuilder


  • public final class ExplainMapBuilder
    extends Object
    A builder for the map of explanatory values.

    This is a mutable builder for ExplainMap that must be used from a single thread.

    • Method Detail

      • openListEntry

        public <R extends List<?>> ExplainMapBuilder openListEntry​(ExplainKey<R> key)
        Opens a list entry to be populated.

        This returns the builder for the new list entry. If the list does not exist, it is created and the first entry added. If the list has already been created, the entry is appended.

        Once opened, the child builder resulting from this method must be used. The method closeListEntry(ExplainKey) must be used to close the child and receive an instance of the parent back again.

        Type Parameters:
        R - the type of the value
        Parameters:
        key - the list key to open
        Returns:
        the child builder
      • closeListEntry

        public <R extends List<?>> ExplainMapBuilder closeListEntry​(ExplainKey<R> key)
        Closes the currently open list.

        This returns the parent builder.

        Type Parameters:
        R - the type of the value
        Parameters:
        key - the list key to close
        Returns:
        the parent builder
      • addListEntry

        public <R extends List<?>> ExplainMapBuilder addListEntry​(ExplainKey<R> key,
                                                                  Consumer<ExplainMapBuilder> consumer)
        Adds a list entry using a consumer callback function.

        This is an alternative to using openListEntry(ExplainKey) and closeListEntry(ExplainKey) directly. The consumer function receives the child builder and must add data to it.

        Type Parameters:
        R - the type of the value
        Parameters:
        key - the list key to open
        consumer - the consumer that receives the list entry builder and adds to it
        Returns:
        this builder
      • addListEntryWithIndex

        public <R extends List<?>> ExplainMapBuilder addListEntryWithIndex​(ExplainKey<R> key,
                                                                           Consumer<ExplainMapBuilder> consumer)
        Adds a list entry using a consumer callback function, including the list index.

        This is an alternative to using openListEntry(ExplainKey) and closeListEntry(ExplainKey) directly. The consumer function receives the child builder and must add data to it.

        Type Parameters:
        R - the type of the value
        Parameters:
        key - the list key to open
        consumer - the consumer that receives the list entry builder and adds to it
        Returns:
        this builder
      • put

        public <R> ExplainMapBuilder put​(ExplainKey<R> key,
                                         R value)
        Puts a single value into the map.

        If the key already exists, the value will be replaced.

        Type Parameters:
        R - the type of the value
        Parameters:
        key - the key to add
        value - the value to add
        Returns:
        this builder
      • build

        public ExplainMap build()
        Builds the map.
        Returns:
        the resulting map