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

feat: Apply Google style recommendations #1057

Merged
merged 1 commit into from
Sep 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public final class Instrumentation {
public static Tuple<Boolean, Iterable<LogEntry>> populateInstrumentationInfo(
Iterable<LogEntry> logEntries) {
boolean isWritten = setInstrumentationStatus(true);
if (isWritten) return Tuple.of(false, logEntries);
if (isWritten) {
return Tuple.of(false, logEntries);
}
List<LogEntry> entries = new ArrayList<>();

for (LogEntry logEntry : logEntries) {
Expand Down Expand Up @@ -97,7 +99,9 @@ public static Tuple<Boolean, Iterable<LogEntry>> populateInstrumentationInfo(
* true
*/
public static WriteOption @Nullable [] addPartialSuccessOption(WriteOption[] options) {
if (options == null) return options;
if (options == null) {
return options;
}
List<WriteOption> writeOptions = new ArrayList<>();
Collections.addAll(writeOptions, options);
// Make sure we remove all partial success flags if any exist
Expand Down Expand Up @@ -146,8 +150,9 @@ private static LogEntry createDiagnosticEntry(

private static ListValue generateLibrariesList(
String libraryName, String libraryVersion, ListValue existingLibraryList) {
if (Strings.isNullOrEmpty(libraryName) || !libraryName.startsWith(JAVA_LIBRARY_NAME_PREFIX))
if (Strings.isNullOrEmpty(libraryName) || !libraryName.startsWith(JAVA_LIBRARY_NAME_PREFIX)) {
libraryName = JAVA_LIBRARY_NAME_PREFIX;
}
if (Strings.isNullOrEmpty(libraryVersion)) {
libraryVersion = getLibraryVersion(Instrumentation.class);
}
Expand All @@ -161,14 +166,21 @@ private static ListValue generateLibrariesList(
try {
String name =
val.getStructValue().getFieldsOrThrow(INSTRUMENTATION_NAME_KEY).getStringValue();
if (Strings.isNullOrEmpty(name) || !name.startsWith(JAVA_LIBRARY_NAME_PREFIX)) continue;
if (Strings.isNullOrEmpty(name) || !name.startsWith(JAVA_LIBRARY_NAME_PREFIX)) {
continue;
}
String version =
val.getStructValue().getFieldsOrThrow(INSTRUMENTATION_VERSION_KEY).getStringValue();
if (Strings.isNullOrEmpty(version)) continue;
if (Strings.isNullOrEmpty(version)) {
continue;
}
libraryList.addValues(
Value.newBuilder().setStructValue(createInfoStruct(name, version)).build());
if (libraryList.getValuesCount() == MAX_DIAGNOSTIC_ENTIES) break;
if (libraryList.getValuesCount() == MAX_DIAGNOSTIC_ENTIES) {
break;
}
} catch (RuntimeException ex) {
System.err.println("ERROR: unexpected exception in generateLibrariesList: " + ex);
}
}
}
Expand All @@ -194,7 +206,9 @@ private static Struct createInfoStruct(String libraryName, String libraryVersion
* @return The value of the flag before it was set.
*/
static boolean setInstrumentationStatus(boolean value) {
if (instrumentationAdded == value) return instrumentationAdded;
if (instrumentationAdded == value) {
return instrumentationAdded;
}
synchronized (instrumentationLock) {
boolean current = instrumentationAdded;
instrumentationAdded = value;
Expand All @@ -211,12 +225,16 @@ static boolean setInstrumentationStatus(boolean value) {
*/
public static String getLibraryVersion(Class<?> libraryClass) {
String libraryVersion = GaxProperties.getLibraryVersion(libraryClass);
if (Strings.isNullOrEmpty(libraryVersion)) libraryVersion = DEFAULT_INSTRUMENTATION_VERSION;
if (Strings.isNullOrEmpty(libraryVersion)) {
libraryVersion = DEFAULT_INSTRUMENTATION_VERSION;
}
return libraryVersion;
}

private static String truncateValue(String value) {
if (Strings.isNullOrEmpty(value) || value.length() < MAX_DIAGNOSTIC_VALUE_LENGTH) return value;
if (Strings.isNullOrEmpty(value) || value.length() < MAX_DIAGNOSTIC_VALUE_LENGTH) {
return value;
}
return value.substring(0, MAX_DIAGNOSTIC_VALUE_LENGTH) + "*";
}

Expand Down