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:
@@ -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}.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user