Skip to content

Commit

Permalink
Require "final" for parameters when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Apr 20, 2018
1 parent 36975cc commit 236b153
Show file tree
Hide file tree
Showing 47 changed files with 148 additions and 138 deletions.
Expand Up @@ -49,7 +49,7 @@ public HonoBasicAuthHandler(final AuthProvider authProvider, final String realm)
}

@Override
public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) {
public void parseCredentials(final RoutingContext context, final Handler<AsyncResult<JsonObject>> handler) {

parseAuthorization(context, false, parseAuthorization -> {
if (parseAuthorization.failed()) {
Expand Down Expand Up @@ -83,11 +83,12 @@ public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObj
}

@Override
protected String authenticateHeader(RoutingContext context) {
protected String authenticateHeader(final RoutingContext context) {
return "Basic realm=\"" + realm + "\"";
}

protected final void parseAuthorization(RoutingContext ctx, boolean optional, Handler<AsyncResult<String>> handler) {
protected final void parseAuthorization(final RoutingContext ctx, final boolean optional,
final Handler<AsyncResult<String>> handler) {

final HttpServerRequest request = ctx.request();
final String authorization = request.headers().get(HttpHeaders.AUTHORIZATION);
Expand Down
Expand Up @@ -90,7 +90,7 @@ protected void addRoutes(final Router router) {
}
}

private void addTelemetryApiRoutes(final Router router, Handler<RoutingContext> basicAuthHandler) {
private void addTelemetryApiRoutes(final Router router, final Handler<RoutingContext> basicAuthHandler) {

// support CORS headers for PUTing telemetry
router.routeWithRegex("\\/telemetry\\/[^\\/]+\\/.*").handler(CorsHandler.create(getConfig().getCorsAllowedOrigin())
Expand Down Expand Up @@ -125,7 +125,7 @@ private void addTelemetryApiRoutes(final Router router, Handler<RoutingContext>
.handler(ctx -> uploadTelemetryMessage(ctx, getTenantParam(ctx), getDeviceIdParam(ctx)));
}

private void addEventApiRoutes(final Router router, Handler<RoutingContext> basicAuthHandler) {
private void addEventApiRoutes(final Router router, final Handler<RoutingContext> basicAuthHandler) {

// support CORS headers for PUTing events
router.routeWithRegex("\\/event\\/[^\\/]+\\/.*").handler(CorsHandler.create(getConfig().getCorsAllowedOrigin())
Expand Down
Expand Up @@ -197,7 +197,7 @@ public void testMapTopicMapsKuraDataMessagesToEventApi(final TestContext ctx) {
assertThat(context.contentType(), is(config.getDataMsgContentType()));
}

private void assertAddress(final ResourceIdentifier address, final String endpoint, String tenantId, final String deviceId) {
private void assertAddress(final ResourceIdentifier address, final String endpoint, final String tenantId, final String deviceId) {
assertThat(address.getEndpoint(), is(endpoint));
assertThat(address.getTenantId(), is(tenantId));
assertThat(address.getResourceId(), is(deviceId));
Expand Down
Expand Up @@ -552,7 +552,7 @@ private void forceClientMocksToConnected() {
when(credentialsServiceClient.isConnected()).thenReturn(Future.succeededFuture());
}

private MqttEndpoint getMqttEndpointAuthenticated(String username, String password) {
private MqttEndpoint getMqttEndpointAuthenticated(final String username, final String password) {
final MqttEndpoint endpoint = mock(MqttEndpoint.class);
when(endpoint.auth()).thenReturn(new MqttAuth(username, password));
return endpoint;
Expand Down
Expand Up @@ -229,16 +229,18 @@ public final Future<ProtonDelivery> send(final String deviceId, final Map<String
}

@Override
public final Future<ProtonDelivery> send(String deviceId, Map<String, ?> properties, String payload, String contentType,
String registrationAssertion, Handler<Void> capacityAvailableHandler) {
public final Future<ProtonDelivery> send(final String deviceId, final Map<String, ?> properties,
final String payload, final String contentType, final String registrationAssertion,
final Handler<Void> capacityAvailableHandler) {
Objects.requireNonNull(payload);
final Charset charset = getCharsetForContentType(Objects.requireNonNull(contentType));
return send(deviceId, properties, payload.getBytes(charset), contentType, registrationAssertion, capacityAvailableHandler);
}

@Override
public final Future<ProtonDelivery> send(String deviceId, Map<String, ?> properties, byte[] payload, String contentType,
String registrationAssertion, Handler<Void> capacityAvailableHandler) {
public final Future<ProtonDelivery> send(final String deviceId, final Map<String, ?> properties,
final byte[] payload, final String contentType, final String registrationAssertion,
final Handler<Void> capacityAvailableHandler) {

Objects.requireNonNull(deviceId);
Objects.requireNonNull(payload);
Expand Down
Expand Up @@ -152,7 +152,7 @@ protected Future<ProtonDelivery> sendMessage(final Message message) {
* @throws NullPointerException if the message is {@code null}.
*/
@Override
public Future<ProtonDelivery> sendAndWaitForOutcome(Message message) {
public Future<ProtonDelivery> sendAndWaitForOutcome(final Message message) {

return sendMessageAndWaitForOutcome(message);
}
Expand Down
Expand Up @@ -556,7 +556,7 @@ public void setExpectedSucceedingConnectionAttempts(final int attempts) {
expectedSucceedingConnectionAttempts = new CountDownLatch(attempts);
}

public boolean await(long timeout, TimeUnit unit) {
public boolean await(final long timeout, final TimeUnit unit) {
try {
return expectedSucceedingConnectionAttempts.await(timeout, unit);
} catch (InterruptedException e) {
Expand Down
Expand Up @@ -242,7 +242,7 @@ public final String getAmqpHostname() {
*
* @param amqpHostname The host name to set.
*/
public final void setAmqpHostname(String amqpHostname) {
public final void setAmqpHostname(final String amqpHostname) {
this.amqpHostname = amqpHostname;
}

Expand Down Expand Up @@ -367,7 +367,7 @@ public final boolean isHostnameVerificationRequired() {
*
* @param hostnameVerificationRequired {@code true} if the host name should be matched.
*/
public final void setHostnameVerificationRequired(boolean hostnameVerificationRequired) {
public final void setHostnameVerificationRequired(final boolean hostnameVerificationRequired) {
this.hostnameVerificationRequired = hostnameVerificationRequired;
}

Expand Down Expand Up @@ -400,7 +400,7 @@ public final boolean isTlsEnabled() {
*
* @param enabled {@code true} if the server identity should be verified.
*/
public final void setTlsEnabled(boolean enabled) {
public final void setTlsEnabled(final boolean enabled) {
this.tlsEnabled = enabled;
}
}
Expand Up @@ -61,7 +61,7 @@ public static CacheDirective noCacheDirective() {
* @param directive The directive to parse.
* @return The cache directive or {@code null} if the directive cannot be parsed.
*/
public static CacheDirective from(String directive) {
public static CacheDirective from(final String directive) {

if (directive == null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/eclipse/hono/util/EndpointType.java
Expand Up @@ -24,7 +24,7 @@ public enum EndpointType {
* @return The enum literal of the endpoint type. Returns {@link #UNKNOWN} if it cannot find the endpoint type.
* Never returns {@code null}.
*/
public static EndpointType fromString(String name) {
public static EndpointType fromString(final String name) {
switch (name) {
case TelemetryConstants.TELEMETRY_ENDPOINT:
case TelemetryConstants.TELEMETRY_ENDPOINT_SHORT:
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/eclipse/hono/util/JwtHelper.java
Expand Up @@ -192,7 +192,7 @@ public static final Date getExpiration(final String token) {

@SuppressWarnings("rawtypes")
@Override
public Key resolveSigningKey(JwsHeader header, Claims claims) {
public Key resolveSigningKey(final JwsHeader header, final Claims claims) {
Date exp = claims.getExpiration();
if (exp != null) {
result.set(exp);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/eclipse/hono/util/TriTuple.java
Expand Up @@ -26,7 +26,7 @@ public final class TriTuple<A, B, C> {
private final B two;
private final C three;

private TriTuple(final A one, B two, C three) {
private TriTuple(final A one, final B two, final C three) {

if (one == null && two == null && three == null) {
throw new IllegalArgumentException("at least one argument must be non-null");
Expand Down Expand Up @@ -91,7 +91,7 @@ public int hashCode() {
*/
@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/org/eclipse/hono/util/StringsTest.java
Expand Up @@ -30,7 +30,7 @@ private static class Mock {

private String value;

Mock(String value) {
Mock(final String value) {
this.value = value;
}

Expand Down
@@ -1,57 +1,57 @@
package org.eclipse.hono.jmeter.client;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.dns.AddressResolverOptions;
import io.vertx.proton.ProtonClientOptions;

/**
* Base class for implementing JMeter samplers connecting to Hono.
*
*/
public abstract class AbstractClient {

static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 1000;
static final int DEFAULT_ADDRESS_RESOLUTION_TIMEOUT_MILLIS = 2000;
static final String TIME_STAMP_VARIABLE = "timeStamp";

/**
* The vert.x instance to use for connecting to Hono.
*/
protected final Vertx vertx;

/**
* Creates a new client.
*/
protected AbstractClient() {
vertx = vertx();
}

final Vertx vertx() {
VertxOptions options = new VertxOptions()
.setWarningExceptionTime(1500000000)
.setAddressResolverOptions(new AddressResolverOptions()
.setCacheNegativeTimeToLive(0) // discard failed DNS lookup results immediately
.setCacheMaxTimeToLive(0) // support DNS based service resolution
.setRotateServers(true)
.setQueryTimeout(DEFAULT_ADDRESS_RESOLUTION_TIMEOUT_MILLIS));
return Vertx.vertx(options);
}

final ProtonClientOptions getClientOptions(int reconnectAttempts) {
return new ProtonClientOptions().setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS)
.setReconnectAttempts(reconnectAttempts);
}

/**
* Closes the vert.x instance.
*
* @return A future that will succeed once the instance is closed.
*/
protected final Future<Void> closeVertx() {
final Future<Void> result = Future.future();
vertx.close(result.completer());
return result;
}
}
package org.eclipse.hono.jmeter.client;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.dns.AddressResolverOptions;
import io.vertx.proton.ProtonClientOptions;

/**
* Base class for implementing JMeter samplers connecting to Hono.
*
*/
public abstract class AbstractClient {

static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 1000;
static final int DEFAULT_ADDRESS_RESOLUTION_TIMEOUT_MILLIS = 2000;
static final String TIME_STAMP_VARIABLE = "timeStamp";

/**
* The vert.x instance to use for connecting to Hono.
*/
protected final Vertx vertx;

/**
* Creates a new client.
*/
protected AbstractClient() {
vertx = vertx();
}

final Vertx vertx() {
VertxOptions options = new VertxOptions()
.setWarningExceptionTime(1500000000)
.setAddressResolverOptions(new AddressResolverOptions()
.setCacheNegativeTimeToLive(0) // discard failed DNS lookup results immediately
.setCacheMaxTimeToLive(0) // support DNS based service resolution
.setRotateServers(true)
.setQueryTimeout(DEFAULT_ADDRESS_RESOLUTION_TIMEOUT_MILLIS));
return Vertx.vertx(options);
}

final ProtonClientOptions getClientOptions(final int reconnectAttempts) {
return new ProtonClientOptions().setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS)
.setReconnectAttempts(reconnectAttempts);
}

/**
* Closes the vert.x instance.
*
* @return A future that will succeed once the instance is closed.
*/
protected final Future<Void> closeVertx() {
final Future<Void> result = Future.future();
vertx.close(result.completer());
return result;
}
}
Expand Up @@ -174,7 +174,7 @@ private void noMessagesReceived(final SampleResult result) {
result.setIdleTime(0);
}

private void verifySenderTimeAndSetSamplingTime(final Long senderTime, long sampleReceivedTime) {
private void verifySenderTimeAndSetSamplingTime(final Long senderTime, final long sampleReceivedTime) {
if (senderTime != null) {
if (sampleStart == 0) { // set sample start only once when the first message is received.
sampleStart = senderTime;
Expand Down
1 change: 1 addition & 0 deletions legal/src/main/resources/checkstyle/default.xml
Expand Up @@ -42,6 +42,7 @@
<module name="HideUtilityClassConstructor"/>
<module name="OneStatementPerLine" />
<module name="StringLiteralEquality" />
<module name="FinalParameters"/>

<!-- whitespaces, linebreaks -->

Expand Down
Expand Up @@ -60,7 +60,7 @@ protected Future<Void> startInternal() {
* @param stopFuture Will be completed if all of the invoked methods return a succeeded Future.
*/
@Override
public final void stop(Future<Void> stopFuture) {
public final void stop(final Future<Void> stopFuture) {
stopInternal().setHandler(stopFuture.completer());
}

Expand Down
Expand Up @@ -63,7 +63,7 @@ public final class HealthCheckServer implements Lifecycle {
* @throws NullPointerException if vertx is {@code null}.
* @throws NullPointerException if config is {@code null}.
*/
public HealthCheckServer(Vertx vertx, ApplicationConfigProperties config) {
public HealthCheckServer(final Vertx vertx, final ApplicationConfigProperties config) {
this.vertx = Objects.requireNonNull(vertx);
this.config = Objects.requireNonNull(config);

Expand Down
Expand Up @@ -731,7 +731,7 @@ public void registerReadinessChecks(final HealthCheckHandler handler) {
* @param handler The health check handler to register the checks with.
*/
@Override
public void registerLivenessChecks(HealthCheckHandler handler) {
public void registerLivenessChecks(final HealthCheckHandler handler) {
for (AmqpEndpoint ep : endpoints()) {
ep.registerLivenessChecks(handler);
}
Expand Down
Expand Up @@ -180,7 +180,7 @@ public final void onLinkAttach(final ProtonConnection con, final ProtonReceiver
* @param message The message.
*/
protected final void handleMessage(final ProtonConnection con, final ProtonReceiver receiver,
final ResourceIdentifier targetAddress, ProtonDelivery delivery, Message message) {
final ResourceIdentifier targetAddress, final ProtonDelivery delivery, final Message message) {

final Future<Void> formalCheck = Future.future();
if (passesFormalVerification(targetAddress, message)) {
Expand Down

0 comments on commit 236b153

Please sign in to comment.