Class AbstractBraveRequestBuilder<T extends AbstractBraveRequestBuilder<T>>

java.lang.Object
net.ygbstudio.jbrave.core.builders.AbstractBraveRequestBuilder<T>
Type Parameters:
T - The concrete builder class.
Direct Known Subclasses:
BraveImageQuery.BraveRequestBuilder, BraveNewsQuery.BraveRequestBuilder, BraveSpellcheckQuery.BraveRequestBuilder, BraveSuggestQuery.BraveRequestBuilder, BraveVideoQuery.BraveRequestBuilder, BraveWebQuery.BraveRequestBuilder

public abstract class AbstractBraveRequestBuilder<T extends AbstractBraveRequestBuilder<T>> extends Object
Abstract base class for building Brave API request builders.

This class is the base class for all Brave API request builders. It provides the basic functionality to build requests, such as adding headers to the request and building the request itself.

Note: This builder enforces strict request invariants. Subclasses must not override core lifecycle methods. Extension is intended via additional fluent APIs only.

  • Field Details

    • headers

      protected Set<BraveSearchHeader> headers
    • internalRequestBuilder

      protected HttpRequest.Builder internalRequestBuilder
    • requestURI

      protected URI requestURI
    • headersAttached

      protected boolean headersAttached
  • Constructor Details

    • AbstractBraveRequestBuilder

      public AbstractBraveRequestBuilder()
  • Method Details

    • self

      protected final T self()
      Returns the current instance of the builder.

      The cast is safe because subclasses follow the self-referential generic pattern used by this base class.

      Returns:
      Current instance of the builder.
    • queryURI

      protected final T queryURI(URI query)
      Sets the URI for the request.
      Parameters:
      query - the URI for the request
      Returns:
      the current builder instance
    • addHeader

      protected final <K extends SearchHeader> T addHeader(@NotNull K header, String value)
      Adds a header to the list of headers.
      Type Parameters:
      K - the type of the header, which must extend SearchHeader
      Parameters:
      header - the header to be added
      value - the value of the header
      Returns:
      the current builder instance
    • attachHeaders

      protected final void attachHeaders()
      Attaches the headers to the request builder.
    • subscriptionMissing

      protected final boolean subscriptionMissing()
      Checks if the subscription token header is missing.
      Returns:
      true if the subscription token header is missing, false otherwise.
    • clear

      protected final T clear()
      Clears the request builder, resetting it to its initial state.
      Returns:
      the current builder instance
    • clearRetainURI

      protected final T clearRetainURI()
      Clears the request builder, resetting it to its initial state, retaining the provided URI.
      Returns:
      the current builder instance
    • build

      protected final HttpRequest build()
      Builds the request using the current state of the builder.

      This method attaches the headers to the request builder and throws a MissingSubscriptionTokenException if the subscription token header is missing.

      Returns:
      the built HttpRequest
      Throws:
      MissingSubscriptionTokenException - if the subscription token header is missing