Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a bunch of final keywords #2927

Merged
merged 2 commits into from Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,7 +53,7 @@ public void stop() {

protected abstract WebClient newClient();

protected String baseUrl() {
protected final String baseUrl() {
return "h2c://127.0.0.1:" + server.activeLocalPort(SessionProtocol.HTTP);
}

Expand Down
Expand Up @@ -47,19 +47,19 @@ static AbstractEventLoopState of(List<EventLoop> eventLoops, int maxNumEventLoop
this.scheduler = scheduler;
}

List<EventLoop> eventLoops() {
final List<EventLoop> eventLoops() {
return eventLoops;
}

DefaultEventLoopScheduler scheduler() {
final DefaultEventLoopScheduler scheduler() {
return scheduler;
}

long lastActivityTimeNanos() {
final long lastActivityTimeNanos() {
return lastActivityTimeNanos;
}

void setLastActivityTimeNanos() {
final void setLastActivityTimeNanos() {
lastActivityTimeNanos = System.nanoTime();
}

Expand Down
Expand Up @@ -133,7 +133,7 @@ private static Scheme validateScheme(String scheme) {
* {@link WebClient#builder(String)} or
* {@link WebClient#builder(URI)} is not an HTTP scheme
*/
protected WebClient buildWebClient() {
protected final WebClient buildWebClient() {
final ClientOptions options = buildOptions();
final ClientBuilderParams params = clientBuilderParams(options);
final ClientFactory factory = options.factory();
Expand All @@ -147,7 +147,7 @@ protected WebClient buildWebClient() {
* {@link WebClient#builder(String)} or
* {@link WebClient#builder(URI)} is not an HTTP scheme
*/
protected ClientBuilderParams clientBuilderParams(ClientOptions options) {
protected final ClientBuilderParams clientBuilderParams(ClientOptions options) {
requireNonNull(options, "options");
if (uri != null) {
return ClientBuilderParams.of(uri, WebClient.class, options);
Expand Down
Expand Up @@ -32,11 +32,11 @@ abstract class PooledChannel implements ReleasableHolder<Channel> {
}

@Override
public Channel get() {
public final Channel get() {
return channel;
}

SessionProtocol protocol() {
final SessionProtocol protocol() {
return protocol;
}
}
Expand Up @@ -120,7 +120,7 @@ final CircuitBreakerRule fromRuleWithContent() {
}

@Override
public O execute(ClientRequestContext ctx, I req) throws Exception {
public final O execute(ClientRequestContext ctx, I req) throws Exception {
final CircuitBreaker circuitBreaker;
try {
circuitBreaker = mapping.get(ctx, req);
Expand Down
Expand Up @@ -63,12 +63,12 @@ private AbstractCircuitBreakerClientBuilder(
this.ruleWithContent = ruleWithContent;
}

CircuitBreakerRule rule() {
final CircuitBreakerRule rule() {
checkState(rule != null, "rule is not set.");
return rule;
}

CircuitBreakerRuleWithContent<O> ruleWithContent() {
final CircuitBreakerRuleWithContent<O> ruleWithContent() {
checkState(ruleWithContent != null, "ruleWithContent is not set.");
return ruleWithContent;
}
Expand All @@ -84,7 +84,7 @@ public AbstractCircuitBreakerClientBuilder<O> mapping(CircuitBreakerMapping mapp
return this;
}

CircuitBreakerMapping mapping() {
final CircuitBreakerMapping mapping() {
return mapping;
}

Expand Down
Expand Up @@ -26,7 +26,7 @@
/**
* Stores configurations of circuit breaker.
*/
class CircuitBreakerConfig {
final class CircuitBreakerConfig {

@Nullable
private final String name;
Expand Down
Expand Up @@ -188,7 +188,7 @@ public AbstractHealthCheckedEndpointGroupBuilder maxEndpointCount(int maxEndpoin
/**
* Returns a newly created {@link HealthCheckedEndpointGroup} based on the properties set so far.
*/
public HealthCheckedEndpointGroup build() {
public final HealthCheckedEndpointGroup build() {
final HealthCheckStrategy healthCheckStrategy;
if (maxEndpointCount != null) {
healthCheckStrategy = new PartialHealthCheckStrategyBuilder()
Expand Down
Expand Up @@ -113,12 +113,12 @@ static void validateMaxConcurrency(int maxConcurrency) {
/**
* Returns the number of the {@link Request}s that are being executed.
*/
public int numActiveRequests() {
public final int numActiveRequests() {
return numActiveRequests.get();
}

@Override
public O execute(ClientRequestContext ctx, I req) throws Exception {
public final O execute(ClientRequestContext ctx, I req) throws Exception {
return maxConcurrency == 0 ? unlimitedExecute(ctx, req)
: limitedExecute(ctx, req);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ private O unlimitedExecute(ClientRequestContext ctx, I req) throws Exception {
}
}

void drain() {
final void drain() {
while (!pendingRequests.isEmpty()) {
final int currentActiveRequests = numActiveRequests.get();
if (currentActiveRequests >= maxConcurrency) {
Expand Down
Expand Up @@ -124,7 +124,7 @@ abstract class AbstractLoggingClient<I extends Request, O extends Response>
}

@Override
public O execute(ClientRequestContext ctx, I req) throws Exception {
public final O execute(ClientRequestContext ctx, I req) throws Exception {
if (sampler.isSampled(ctx)) {
ctx.log().whenRequestComplete().thenAccept(requestLogger);
ctx.log().whenComplete().thenAccept(responseLogger);
Expand Down
Expand Up @@ -46,7 +46,7 @@ abstract class AbstractMetricCollectingClient<I extends Request, O extends Respo
}

@Override
public O execute(ClientRequestContext ctx, I req) throws Exception {
public final O execute(ClientRequestContext ctx, I req) throws Exception {
RequestMetricSupport.setup(ctx, REQUEST_METRICS_SET, meterIdPrefixFunction, false);
return unwrap().execute(ctx, req);
}
Expand Down
Expand Up @@ -125,7 +125,7 @@ private AbstractRetryingClient(Client<I, O> delegate, @Nullable RetryRule retryR
}

@Override
public O execute(ClientRequestContext ctx, I req) throws Exception {
public final O execute(ClientRequestContext ctx, I req) throws Exception {
final State state =
new State(maxTotalAttempts, responseTimeoutMillisForEachAttempt, ctx.responseTimeoutMillis());
ctx.setAttr(STATE, state);
Expand Down Expand Up @@ -165,7 +165,7 @@ protected final RetryRuleWithContent<O> retryRuleWithContent() {
return retryRuleWithContent;
}

RetryRule fromRetryRuleWithContent() {
final RetryRule fromRetryRuleWithContent() {
checkState(retryRuleWithContent != null, "retryRuleWithContent is not set.");
return fromRetryRuleWithContent;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ protected static ClientRequestContext newDerivedContext(ClientRequestContext ctx
return derived;
}

private static class State {
private static final class State {

private final int maxTotalAttempts;
private final long responseTimeoutMillisForEachAttempt;
Expand Down
Expand Up @@ -67,12 +67,12 @@ private AbstractRetryingClientBuilder(@Nullable RetryRule retryRule,
this.retryRuleWithContent = retryRuleWithContent;
}

RetryRule retryRule() {
final RetryRule retryRule() {
checkState(retryRule != null, "retryRule is not set.");
return retryRule;
}

RetryRuleWithContent<O> retryRuleWithContent() {
final RetryRuleWithContent<O> retryRuleWithContent() {
checkState(retryRuleWithContent != null, "retryRuleWithContent is not set.");
return retryRuleWithContent;
}
Expand All @@ -90,7 +90,7 @@ public AbstractRetryingClientBuilder<O> maxTotalAttempts(int maxTotalAttempts) {
return this;
}

int maxTotalAttempts() {
final int maxTotalAttempts() {
return maxTotalAttempts;
}

Expand All @@ -114,7 +114,7 @@ public AbstractRetryingClientBuilder<O> responseTimeoutMillisForEachAttempt(
return this;
}

long responseTimeoutMillisForEachAttempt() {
final long responseTimeoutMillisForEachAttempt() {
return responseTimeoutMillisForEachAttempt;
}

Expand All @@ -139,7 +139,7 @@ public String toString() {
return toStringHelper().toString();
}

ToStringHelper toStringHelper() {
final ToStringHelper toStringHelper() {
return MoreObjects.toStringHelper(this).omitNullValues()
.add("retryRule", retryRule)
.add("retryRuleWithContent", retryRuleWithContent)
Expand Down
Expand Up @@ -27,12 +27,12 @@ abstract class AbstractAggregatedHttpMessage implements AggregatedHttpMessage {
}

@Override
public HttpData content() {
public final HttpData content() {
return content;
}

@Override
public HttpHeaders trailers() {
public final HttpHeaders trailers() {
return trailers;
}
}
Expand Up @@ -47,7 +47,7 @@ public final MediaType contentType() {
return getters != null ? getters.contentType() : null;
}

public SELF contentType(MediaType contentType) {
public final SELF contentType(MediaType contentType) {
setters().contentType(contentType);
return self();
}
Expand Down
Expand Up @@ -507,7 +507,7 @@ public AbstractRequestContextBuilder timedOut(boolean timedOut) {
}

@SuppressWarnings("ComparableImplementedButEqualsNotOverridden")
private static class FakeChannel implements Channel {
private static final class FakeChannel implements Channel {

private final ChannelId id = DefaultChannelId.newInstance();
private final EventLoop eventLoop;
Expand Down
Expand Up @@ -38,7 +38,7 @@ class DefaultContextAwareExecutorService implements ContextAwareExecutorService
}

@Override
public RequestContext context() {
public final RequestContext context() {
return context;
}

Expand Down
Expand Up @@ -15,7 +15,7 @@
*/
package com.linecorp.armeria.common;

class DefaultHttpHeadersBuilder
final class DefaultHttpHeadersBuilder
extends AbstractHttpHeadersBuilder<DefaultHttpHeadersBuilder>
implements HttpHeadersBuilder {

Expand Down
Expand Up @@ -96,28 +96,28 @@ class HttpHeadersBase
}

@Override
int hashName(CharSequence name) {
final int hashName(CharSequence name) {
return AsciiString.hashCode(name);
}

@Override
boolean nameEquals(AsciiString a, CharSequence b) {
final boolean nameEquals(AsciiString a, CharSequence b) {
return a.contentEqualsIgnoreCase(b);
}

@Override
AsciiString normalizeName(CharSequence name) {
final AsciiString normalizeName(CharSequence name) {
return HttpHeaderNames.of(name);
}

@Override
boolean isFirstGroup(AsciiString name) {
final boolean isFirstGroup(AsciiString name) {
// Pseudo headers must come first during iteration.
return !name.isEmpty() && name.byteAt(0) == ':';
}

@Override
void validateValue(String value) {
final void validateValue(String value) {
if (!Flags.validateHeaders()) {
return;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ final void endOfStream(boolean endOfStream) {
}

@Override
public int hashCode() {
public final int hashCode() {
final int hashCode = super.hashCode();
return endOfStream ? ~hashCode : hashCode;
}
Expand Down
Expand Up @@ -81,12 +81,12 @@ protected NonWrappingRequestContext(
}

@Override
public HttpRequest request() {
public final HttpRequest request() {
return req;
}

@Override
public RpcRequest rpcRequest() {
public final RpcRequest rpcRequest() {
return rpcReq;
}

Expand Down Expand Up @@ -193,29 +193,29 @@ public <V> V attr(AttributeKey<V> key) {

@Nullable
@Override
public <V> V ownAttr(AttributeKey<V> key) {
public final <V> V ownAttr(AttributeKey<V> key) {
requireNonNull(key, "key");
return attrs.ownAttr(key);
}

@Override
public <V> void setAttr(AttributeKey<V> key, @Nullable V value) {
public final <V> void setAttr(AttributeKey<V> key, @Nullable V value) {
requireNonNull(key, "key");
attrs.setAttr(key, value);
}

@Nullable
@Override
public <V> V setAttrIfAbsent(AttributeKey<V> key, V value) {
public final <V> V setAttrIfAbsent(AttributeKey<V> key, V value) {
requireNonNull(key, "key");
requireNonNull(value, "value");
return attrs.setAttrIfAbsent(key, value);
}

@Nullable
@Override
public <V> V computeAttrIfAbsent(AttributeKey<V> key,
Function<? super AttributeKey<V>, ? extends V> mappingFunction) {
public final <V> V computeAttrIfAbsent(AttributeKey<V> key,
Function<? super AttributeKey<V>, ? extends V> mappingFunction) {
requireNonNull(key, "key");
requireNonNull(mappingFunction, "mappingFunction");
return attrs.computeAttrIfAbsent(key, mappingFunction);
Expand All @@ -227,7 +227,7 @@ public Iterator<Entry<AttributeKey<?>, Object>> attrs() {
}

@Override
public Iterator<Entry<AttributeKey<?>, Object>> ownAttrs() {
public final Iterator<Entry<AttributeKey<?>, Object>> ownAttrs() {
return attrs.ownAttrs();
}
}