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 Summary
FieldsModifier and TypeFieldDescriptionprotected Set<BraveSearchHeader> protected booleanprotected HttpRequest.Builderprotected URI -
Constructor Summary
Constructors -
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.protected final HttpRequestbuild()Builds the request using the current state of the builder.protected final Tclear()Clears the request builder, resetting it to its initial state.protected final TClears the request builder, resetting it to its initial state, retaining the provided 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
-
internalRequestBuilder
-
requestURI
-
headersAttached
protected boolean headersAttached
-
-
Constructor Details
-
AbstractBraveRequestBuilder
public AbstractBraveRequestBuilder()
-
-
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, retaining the provided 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
-