Refactoring in ApiVersionInserter

Refine naming of static factory methods, and update them to be
shortcuts for instance creation.

See gh-34919
This commit is contained in:
rstoyanchev
2025-05-19 07:25:21 +01:00
parent f4f0e52003
commit 5b19f6249e
6 changed files with 45 additions and 42 deletions

View File

@@ -53,27 +53,34 @@ public interface ApiVersionInserter {
/**
* Create a builder for an inserter that sets a header.
* Create an inserter that sets a header.
* @param header the name of a header to hold the version
*/
static Builder fromHeader(@Nullable String header) {
return new DefaultApiVersionInserterBuilder(header, null, null);
static ApiVersionInserter useHeader(@Nullable String header) {
return new DefaultApiVersionInserterBuilder(header, null, null).build();
}
/**
* Create a builder for an inserter that sets a query parameter.
* Create an inserter that sets a query parameter.
* @param queryParam the name of a query parameter to hold the version
*/
static Builder fromQueryParam(@Nullable String queryParam) {
return new DefaultApiVersionInserterBuilder(null, queryParam, null);
static ApiVersionInserter useQueryParam(@Nullable String queryParam) {
return new DefaultApiVersionInserterBuilder(null, queryParam, null).build();
}
/**
* Create a builder for an inserter that inserts a path segment.
* Create an inserter that inserts a path segment.
* @param pathSegmentIndex the index of the path segment to hold the version
*/
static Builder fromPathSegment(@Nullable Integer pathSegmentIndex) {
return new DefaultApiVersionInserterBuilder(null, null, pathSegmentIndex);
static ApiVersionInserter usePathSegment(@Nullable Integer pathSegmentIndex) {
return new DefaultApiVersionInserterBuilder(null, null, pathSegmentIndex).build();
}
/**
* Create a builder for an {@link ApiVersionInserter}.
*/
static Builder builder() {
return new DefaultApiVersionInserterBuilder(null, null, null);
}
@@ -86,19 +93,19 @@ public interface ApiVersionInserter {
* Configure the inserter to set a header.
* @param header the name of the header to hold the version
*/
Builder fromHeader(@Nullable String header);
Builder useHeader(@Nullable String header);
/**
* Configure the inserter to set a query parameter.
* @param queryParam the name of the query parameter to hold the version
*/
Builder fromQueryParam(@Nullable String queryParam);
Builder useQueryParam(@Nullable String queryParam);
/**
* Configure the inserter to insert a path segment.
* @param pathSegmentIndex the index of the path segment to hold the version
*/
Builder fromPathSegment(@Nullable Integer pathSegmentIndex);
Builder usePathSegment(@Nullable Integer pathSegmentIndex);
/**
* Format the version Object into a String using the given {@link ApiVersionFormatter}.

View File

@@ -23,9 +23,9 @@ import org.jspecify.annotations.Nullable;
*
* @author Rossen Stoyanchev
* @since 7.0
* @see ApiVersionInserter#fromHeader(String)
* @see ApiVersionInserter#fromQueryParam(String)
* @see ApiVersionInserter#fromPathSegment(Integer)
* @see ApiVersionInserter#useHeader(String)
* @see ApiVersionInserter#useQueryParam(String)
* @see ApiVersionInserter#usePathSegment(Integer)
*/
final class DefaultApiVersionInserterBuilder implements ApiVersionInserter.Builder {
@@ -50,7 +50,7 @@ final class DefaultApiVersionInserterBuilder implements ApiVersionInserter.Build
* Configure the inserter to set a header.
* @param header the name of the header to hold the version
*/
public ApiVersionInserter.Builder fromHeader(@Nullable String header) {
public ApiVersionInserter.Builder useHeader(@Nullable String header) {
this.header = header;
return this;
}
@@ -59,7 +59,7 @@ final class DefaultApiVersionInserterBuilder implements ApiVersionInserter.Build
* Configure the inserter to set a query parameter.
* @param queryParam the name of the query parameter to hold the version
*/
public ApiVersionInserter.Builder fromQueryParam(@Nullable String queryParam) {
public ApiVersionInserter.Builder useQueryParam(@Nullable String queryParam) {
this.queryParam = queryParam;
return this;
}
@@ -68,7 +68,7 @@ final class DefaultApiVersionInserterBuilder implements ApiVersionInserter.Build
* Configure the inserter to insert a path segment.
* @param pathSegmentIndex the index of the path segment to hold the version
*/
public ApiVersionInserter.Builder fromPathSegment(@Nullable Integer pathSegmentIndex) {
public ApiVersionInserter.Builder usePathSegment(@Nullable Integer pathSegmentIndex) {
this.pathSegmentIndex = pathSegmentIndex;
return this;
}