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:
BraveVerticalSearchRequest,BraveWebSearchRequest
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 Summary
FieldsModifier and TypeFieldDescriptionprotected Set<BraveSearchHeader> Headers accumulated for the request before they are attached.protected booleanWhether the accumulated headers have already been attached to the request.protected HttpRequest.BuilderThe underlying HTTP request builder.protected URIThe request URI, retained byclearRetainURI(). -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new abstract request builder with an empty request state. -
Method Summary
Modifier and TypeMethodDescriptionprotected final <K extends SearchHeader>
TAdds a header to the list of headers.protected final voidAttaches the headers to the request builder.final HttpRequestbuild()Builds the request using the current state of the builder.final Tclear()Clears the request builder, resetting it to its initial state.final TClears the request builder, resetting it to its initial state while retaining the currently set URI.protected final TSets the URI for the request.protected final Tself()Returns the current instance of the builder.protected final booleanChecks if the subscription token header is missing.
-
Field Details
-
headers
Headers accumulated for the request before they are attached. -
internalRequestBuilder
The underlying HTTP request builder. -
requestURI
The request URI, retained byclearRetainURI(). -
headersAttached
protected boolean headersAttachedWhether the accumulated headers have already been attached to the request.
-
-
Constructor Details
-
AbstractBraveRequestBuilder
public AbstractBraveRequestBuilder()Creates a new abstract request builder with an empty request state.Concrete subclasses must call
clear()to initialize the builder before use.
-
-
Method Details
-
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
Sets the URI for the request.- Parameters:
query- the URI for the request- Returns:
- the current builder instance
-
addHeader
Adds a header to the list of headers.- Type Parameters:
K- the type of the header, which must extendSearchHeader- Parameters:
header- the header to be addedvalue- 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
Clears the request builder, resetting it to its initial state.- Returns:
- the current builder instance
-
clearRetainURI
Clears the request builder, resetting it to its initial state while retaining the currently set URI.- Returns:
- the current builder instance
-
build
Builds the request using the current state of the builder.This method attaches the headers to the request builder and throws a
MissingSubscriptionTokenExceptionif the subscription token header is missing.- Returns:
- the built
HttpRequest - Throws:
MissingSubscriptionTokenException- if the subscription token header is missing
-