Skip to content

Commit

Permalink
Apply Google style recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Creech committed Sep 8, 2022
1 parent 79e9d8d commit 56eab75
Show file tree
Hide file tree
Showing 17 changed files with 499 additions and 453 deletions.
4 changes: 4 additions & 0 deletions google-cloud-logging/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<differenceType>3003</differenceType>
<className>com/google/cloud/logging/Instrumentation</className>
</difference>
<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/logging/MonitoredResourceUtil$Label</className>
</difference>
<difference>
<differenceType>7009</differenceType>
<className>com/google/cloud/logging/Instrumentation</className>
Expand Down
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

0 comments on commit 56eab75

Please sign in to comment.