Skip to content

Commit

Permalink
feat: Apply Google style recommendations (#1057)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Creech <bpcreech@google.com>
  • Loading branch information
bpcreech and Ben Creech committed Sep 14, 2022
1 parent ca095f0 commit bfef3d1
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 399 deletions.
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
Loading

0 comments on commit bfef3d1

Please sign in to comment.