Skip to content

Commit

Permalink
add final for params, local variables, and fields (airbytehq#7084)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens authored Oct 15, 2021
1 parent 592f7fe commit ba44f70
Show file tree
Hide file tree
Showing 747 changed files with 5,815 additions and 5,580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ public class LoggingTrackingClient implements TrackingClient {

private final Function<UUID, TrackingIdentity> identityFetcher;

public LoggingTrackingClient(Function<UUID, TrackingIdentity> identityFetcher) {
public LoggingTrackingClient(final Function<UUID, TrackingIdentity> identityFetcher) {
this.identityFetcher = identityFetcher;
}

@Override
public void identify(UUID workspaceId) {
public void identify(final UUID workspaceId) {
LOGGER.info("identify. userId: {}", identityFetcher.apply(workspaceId).getCustomerId());
}

@Override
public void alias(UUID workspaceId, String previousCustomerId) {
public void alias(final UUID workspaceId, final String previousCustomerId) {
LOGGER.info("merge. userId: {} previousUserId: {}", identityFetcher.apply(workspaceId).getCustomerId(), previousCustomerId);
}

@Override
public void track(UUID workspaceId, String action) {
public void track(final UUID workspaceId, final String action) {
track(workspaceId, action, Collections.emptyMap());
}

@Override
public void track(UUID workspaceId, String action, Map<String, Object> metadata) {
public void track(final UUID workspaceId, final String action, final Map<String, Object> metadata) {
LOGGER.info("track. version: {}, userId: {}, action: {}, metadata: {}",
identityFetcher.apply(workspaceId).getAirbyteVersion(),
identityFetcher.apply(workspaceId).getCustomerId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SegmentTrackingClient(final Function<UUID, TrackingIdentity> identityFetc
}

@Override
public void identify(UUID workspaceId) {
public void identify(final UUID workspaceId) {
final TrackingIdentity trackingIdentity = identityFetcher.apply(workspaceId);
final Map<String, Object> identityMetadata = new HashMap<>();

Expand Down Expand Up @@ -75,17 +75,17 @@ public void identify(UUID workspaceId) {
}

@Override
public void alias(UUID workspaceId, String previousCustomerId) {
public void alias(final UUID workspaceId, final String previousCustomerId) {
analytics.enqueue(AliasMessage.builder(previousCustomerId).userId(identityFetcher.apply(workspaceId).getCustomerId().toString()));
}

@Override
public void track(UUID workspaceId, String action) {
public void track(final UUID workspaceId, final String action) {
track(workspaceId, action, Collections.emptyMap());
}

@Override
public void track(UUID workspaceId, String action, Map<String, Object> metadata) {
public void track(final UUID workspaceId, final String action, final Map<String, Object> metadata) {
final Map<String, Object> mapCopy = new HashMap<>(metadata);
final TrackingIdentity trackingIdentity = identityFetcher.apply(workspaceId);
mapCopy.put(AIRBYTE_VERSION_KEY, trackingIdentity.getAirbyteVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static TrackingClient get() {
}

@VisibleForTesting
static void initialize(TrackingClient trackingClient) {
static void initialize(final TrackingClient trackingClient) {
synchronized (lock) {
TrackingClientSingleton.trackingClient = trackingClient;
}
Expand All @@ -53,7 +53,7 @@ private static void initialize() {
}

@VisibleForTesting
static TrackingIdentity getTrackingIdentity(ConfigRepository configRepository, String airbyteVersion, UUID workspaceId) {
static TrackingIdentity getTrackingIdentity(final ConfigRepository configRepository, final String airbyteVersion, final UUID workspaceId) {
try {
final StandardWorkspace workspace = configRepository.getStandardWorkspace(workspaceId, true);
String email = null;
Expand All @@ -67,9 +67,9 @@ static TrackingIdentity getTrackingIdentity(ConfigRepository configRepository, S
workspace.getAnonymousDataCollection(),
workspace.getNews(),
workspace.getSecurityUpdates());
} catch (ConfigNotFoundException e) {
} catch (final ConfigNotFoundException e) {
throw new RuntimeException("could not find workspace with id: " + workspaceId, e);
} catch (JsonValidationException | IOException e) {
} catch (final JsonValidationException | IOException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public boolean isSecurityUpdates() {
}

@Override
public boolean equals(Object o) {
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TrackingIdentity that = (TrackingIdentity) o;
final TrackingIdentity that = (TrackingIdentity) o;
return anonymousDataCollection == that.anonymousDataCollection &&
news == that.news &&
securityUpdates == that.securityUpdates &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void setup() {
void testIdentify() {
// equals is not defined on MessageBuilder, so we need to use ArgumentCaptor to inspect each field
// manually.
ArgumentCaptor<IdentifyMessage.Builder> mockBuilder = ArgumentCaptor.forClass(IdentifyMessage.Builder.class);
final ArgumentCaptor<IdentifyMessage.Builder> mockBuilder = ArgumentCaptor.forClass(IdentifyMessage.Builder.class);

segmentTrackingClient.identify(WORKSPACE_ID);

Expand All @@ -74,7 +74,7 @@ void testIdentifyWithRole() {
segmentTrackingClient = new SegmentTrackingClient((workspaceId) -> IDENTITY, DEPLOYMENT, "role", analytics);
// equals is not defined on MessageBuilder, so we need to use ArgumentCaptor to inspect each field
// manually.
ArgumentCaptor<IdentifyMessage.Builder> mockBuilder = ArgumentCaptor.forClass(IdentifyMessage.Builder.class);
final ArgumentCaptor<IdentifyMessage.Builder> mockBuilder = ArgumentCaptor.forClass(IdentifyMessage.Builder.class);
when(roleSupplier.get()).thenReturn("role");

segmentTrackingClient.identify(WORKSPACE_ID);
Expand Down Expand Up @@ -104,7 +104,7 @@ void testTrack() {
segmentTrackingClient.track(WORKSPACE_ID, "jump");

verify(analytics).enqueue(mockBuilder.capture());
TrackMessage actual = mockBuilder.getValue().build();
final TrackMessage actual = mockBuilder.getValue().build();
assertEquals("jump", actual.event());
assertEquals(IDENTITY.getCustomerId().toString(), actual.userId());
assertEquals(metadata, actual.properties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void testCreateTrackingClientSegment() {

@Test
void testGet() {
TrackingClient client = mock(TrackingClient.class);
final TrackingClient client = mock(TrackingClient.class);
TrackingClientSingleton.initialize(client);
assertEquals(client, TrackingClientSingleton.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AirbyteApiClient {
private final HealthApi healthApi;
private final DbMigrationApi dbMigrationApi;

public AirbyteApiClient(ApiClient apiClient) {
public AirbyteApiClient(final ApiClient apiClient) {
connectionApi = new ConnectionApi(apiClient);
destinationDefinitionApi = new DestinationDefinitionApi(apiClient);
destinationApi = new DestinationApi(apiClient);
Expand Down
28 changes: 14 additions & 14 deletions airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PatchedLogsApi() {
this(new ApiClient());
}

public PatchedLogsApi(ApiClient apiClient) {
public PatchedLogsApi(final ApiClient apiClient) {
memberVarHttpClient = apiClient.getHttpClient();
memberVarObjectMapper = apiClient.getObjectMapper();
memberVarBaseUri = apiClient.getBaseUri();
Expand All @@ -54,8 +54,8 @@ public PatchedLogsApi(ApiClient apiClient) {
* @return File
* @throws ApiException if fails to make API call
*/
public File getLogs(LogsRequestBody logsRequestBody) throws ApiException {
ApiResponse<File> localVarResponse = getLogsWithHttpInfo(logsRequestBody);
public File getLogs(final LogsRequestBody logsRequestBody) throws ApiException {
final ApiResponse<File> localVarResponse = getLogsWithHttpInfo(logsRequestBody);
return localVarResponse.getData();
}

Expand All @@ -66,10 +66,10 @@ public File getLogs(LogsRequestBody logsRequestBody) throws ApiException {
* @return ApiResponse&lt;File&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<File> getLogsWithHttpInfo(LogsRequestBody logsRequestBody) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = getLogsRequestBuilder(logsRequestBody);
public ApiResponse<File> getLogsWithHttpInfo(final LogsRequestBody logsRequestBody) throws ApiException {
final HttpRequest.Builder localVarRequestBuilder = getLogsRequestBuilder(logsRequestBody);
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
final HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
Expand All @@ -82,7 +82,7 @@ public ApiResponse<File> getLogsWithHttpInfo(LogsRequestBody logsRequestBody) th
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
}

File tmpFile = File.createTempFile("patched-logs-api", "response"); // CHANGED
final File tmpFile = File.createTempFile("patched-logs-api", "response"); // CHANGED
tmpFile.deleteOnExit(); // CHANGED

FileUtils.copyInputStreamToFile(localVarResponse.body(), tmpFile); // CHANGED
Expand All @@ -92,23 +92,23 @@ public ApiResponse<File> getLogsWithHttpInfo(LogsRequestBody logsRequestBody) th
localVarResponse.headers().map(),
tmpFile // CHANGED
);
} catch (IOException e) {
} catch (final IOException e) {
throw new ApiException(e);
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}

private HttpRequest.Builder getLogsRequestBuilder(LogsRequestBody logsRequestBody) throws ApiException {
private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequestBody) throws ApiException {
// verify the required parameter 'logsRequestBody' is set
if (logsRequestBody == null) {
throw new ApiException(400, "Missing the required parameter 'logsRequestBody' when calling getLogs");
}

HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
final HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

String localVarPath = "/v1/logs/get";
final String localVarPath = "/v1/logs/get";

localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));

Expand All @@ -117,9 +117,9 @@ private HttpRequest.Builder getLogsRequestBuilder(LogsRequestBody logsRequestBod
localVarRequestBuilder.header("Accept", "text/plain"); // CHANGED

try {
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(logsRequestBody);
final byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(logsRequestBody);
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) {
} catch (final IOException e) {
throw new ApiException(e);
}
if (memberVarReadTimeout != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class DockerUtils {
.build();
private static final DockerClient DOCKER_CLIENT = DockerClientImpl.getInstance(CONFIG, HTTP_CLIENT);

public static String getTaggedImageName(String dockerRepository, String tag) {
public static String getTaggedImageName(final String dockerRepository, final String tag) {
return String.join(":", dockerRepository, tag);
}

public static String buildImage(String dockerFilePath, String tag) {
public static String buildImage(final String dockerFilePath, final String tag) {
return DOCKER_CLIENT.buildImageCmd()
.withDockerfile(new File(dockerFilePath))
.withTags(Set.of(tag))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class DockerUtilsTest {

@Test
void testGetTaggedImageName() {
String repository = "airbyte/repo";
String tag = "12.3";
final String repository = "airbyte/repo";
final String tag = "12.3";
assertEquals("airbyte/repo:12.3", DockerUtils.getTaggedImageName(repository, tag));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ public class GracefulShutdownHandler extends Thread {
private final Duration terminateWaitDuration;
private final ExecutorService[] threadPools;

public GracefulShutdownHandler(Duration terminateWaitDuration, final ExecutorService... threadPools) {
public GracefulShutdownHandler(final Duration terminateWaitDuration, final ExecutorService... threadPools) {
this.terminateWaitDuration = terminateWaitDuration;
this.threadPools = threadPools;
}

@Override
public void run() {
for (ExecutorService threadPool : threadPools) {
for (final ExecutorService threadPool : threadPools) {
threadPool.shutdown();

try {
if (!threadPool.awaitTermination(terminateWaitDuration.getSeconds(), TimeUnit.SECONDS)) {
LOGGER.error("Unable to kill threads by shutdown timeout.");
}
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
LOGGER.error("Wait for graceful thread shutdown interrupted.", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ public Builder(final Callable<T> callable) {
this.onFinish = () -> {};
}

public Builder<T> setOnStart(VoidCallable onStart) {
public Builder<T> setOnStart(final VoidCallable onStart) {
this.onStart = onStart;
return this;
}

public Builder<T> setOnSuccess(CheckedConsumer<T, Exception> onSuccess) {
public Builder<T> setOnSuccess(final CheckedConsumer<T, Exception> onSuccess) {
this.onSuccess = onSuccess;
return this;
}

public Builder<T> setOnException(CheckedConsumer<Exception, Exception> onException) {
public Builder<T> setOnException(final CheckedConsumer<Exception, Exception> onException) {
this.onException = onException;
return this;
}

public Builder<T> setOnFinish(VoidCallable onFinish) {
public Builder<T> setOnFinish(final VoidCallable onFinish) {
this.onFinish = onFinish;
return this;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ public T call() throws Exception {
final T result = execute();
onSuccess(result);
return result;
} catch (Exception e) {
} catch (final Exception e) {
onException(e);
throw e;
} finally {
Expand All @@ -95,11 +95,11 @@ private T execute() throws Exception {

}

private void onSuccess(T value) throws Exception {
private void onSuccess(final T value) throws Exception {
this.onSuccess.accept(value);
}

private void onException(Exception e) throws Exception {
private void onException(final Exception e) throws Exception {
this.onException.accept(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

public class Enums {

public static <T1 extends Enum<T1>, T2 extends Enum<T2>> T2 convertTo(T1 ie, Class<T2> oe) {
public static <T1 extends Enum<T1>, T2 extends Enum<T2>> T2 convertTo(final T1 ie, final Class<T2> oe) {
if (ie == null) {
return null;
}

return Enum.valueOf(oe, ie.name());
}

public static <T1 extends Enum<T1>, T2 extends Enum<T2>> List<T2> convertListTo(List<T1> ies, Class<T2> oe) {
public static <T1 extends Enum<T1>, T2 extends Enum<T2>> List<T2> convertListTo(final List<T1> ies, final Class<T2> oe) {
return ies
.stream()
.map(ie -> convertTo(ie, oe))
.collect(Collectors.toList());
}

public static <T1 extends Enum<T1>, T2 extends Enum<T2>> boolean isCompatible(Class<T1> c1,
Class<T2> c2) {
public static <T1 extends Enum<T1>, T2 extends Enum<T2>> boolean isCompatible(final Class<T1> c1,
final Class<T2> c2) {
Preconditions.checkArgument(c1.isEnum());
Preconditions.checkArgument(c2.isEnum());
return c1.getEnumConstants().length == c2.getEnumConstants().length
Expand All @@ -45,13 +45,13 @@ public static <T1 extends Enum<T1>, T2 extends Enum<T2>> boolean isCompatible(Cl
private static final Map<Class<?>, Map<String, ?>> NORMALIZED_ENUMS = Maps.newConcurrentMap();

@SuppressWarnings("unchecked")
public static <T extends Enum<T>> Optional<T> toEnum(final String value, Class<T> enumClass) {
public static <T extends Enum<T>> Optional<T> toEnum(final String value, final Class<T> enumClass) {
Preconditions.checkArgument(enumClass.isEnum());

if (!NORMALIZED_ENUMS.containsKey(enumClass)) {
T[] values = enumClass.getEnumConstants();
final T[] values = enumClass.getEnumConstants();
final Map<String, T> mappings = Maps.newHashMapWithExpectedSize(values.length);
for (T t : values) {
for (final T t : values) {
mappings.put(normalizeName(t.name()), t);
}
NORMALIZED_ENUMS.put(enumClass, mappings);
Expand All @@ -64,7 +64,7 @@ private static String normalizeName(final String name) {
return name.toLowerCase().replaceAll("[^a-zA-Z0-9]", "");
}

public static <T1 extends Enum<T1>> Set<String> valuesAsStrings(Class<T1> e) {
public static <T1 extends Enum<T1>> Set<String> valuesAsStrings(final Class<T1> e) {
Preconditions.checkArgument(e.isEnum());
return Arrays.stream(e.getEnumConstants()).map(Enum::name).collect(Collectors.toSet());
}
Expand Down
Loading

0 comments on commit ba44f70

Please sign in to comment.