Skip to content

Commit ba42bb2

Browse files
committed
Make the attribute functions more compact and easily understandable.
1 parent a31f9fe commit ba42bb2

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerformance.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.perf;
1616

17+
import static com.google.firebase.perf.metrics.validator.PerfMetricValidator.*;
18+
1719
import android.content.Context;
1820
import android.content.pm.ApplicationInfo;
1921
import android.content.pm.PackageManager;
@@ -364,7 +366,7 @@ private void checkAttribute(@Nullable String key, @Nullable String value) {
364366
Constants.MAX_TRACE_CUSTOM_ATTRIBUTES));
365367
}
366368

367-
PerfMetricValidator.validateAttribute(new AbstractMap.SimpleEntry<>(key, value));
369+
validateAttribute(key, value);
368370
}
369371

370372
/**

firebase-perf/src/main/java/com/google/firebase/perf/metrics/HttpMetric.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.perf.metrics;
1616

17+
import static com.google.firebase.perf.metrics.validator.PerfMetricValidator.*;
18+
1719
import androidx.annotation.NonNull;
1820
import androidx.annotation.Nullable;
1921
import com.google.firebase.perf.FirebasePerformance.HttpMethod;
@@ -195,7 +197,7 @@ private void checkAttribute(@NonNull String key, @NonNull String value) {
195197
"Exceeds max limit of number of attributes - %d",
196198
Constants.MAX_TRACE_CUSTOM_ATTRIBUTES));
197199
}
198-
PerfMetricValidator.validateAttribute(new AbstractMap.SimpleEntry<>(key, value));
200+
validateAttribute(key, value);
199201
}
200202

201203
/**

firebase-perf/src/main/java/com/google/firebase/perf/metrics/Trace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ private void checkAttribute(@NonNull String key, @NonNull String value) {
641641
"Exceeds max limit of number of attributes - %d",
642642
Constants.MAX_TRACE_CUSTOM_ATTRIBUTES));
643643
}
644-
validateAttribute(new AbstractMap.SimpleEntry<>(key, value));
644+
validateAttribute(key, value);
645645
}
646646

647647
/**

firebase-perf/src/main/java/com/google/firebase/perf/metrics/validator/FirebasePerfTraceValidator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.perf.metrics.validator;
1616

17+
import static com.google.firebase.perf.metrics.validator.PerfMetricValidator.*;
18+
1719
import androidx.annotation.NonNull;
1820
import androidx.annotation.Nullable;
1921
import com.google.firebase.perf.logging.AndroidLogger;
@@ -144,7 +146,7 @@ private boolean isValidTrace(@Nullable TraceMetric trace, int deep) {
144146
return false;
145147
}
146148
}
147-
if (!hasValidAttributes(trace.getCustomAttributesMap())) {
149+
if (!areAllAttributesValid(trace.getCustomAttributesMap())) {
148150
return false;
149151
}
150152
return true;
@@ -178,10 +180,10 @@ private boolean isValidCounterId(@Nullable String counterId) {
178180
return true;
179181
}
180182

181-
private boolean hasValidAttributes(Map<String, String> customAttributes) {
183+
private boolean areAllAttributesValid(Map<String, String> customAttributes) {
182184
for (Map.Entry<String, String> entry : customAttributes.entrySet()) {
183185
try {
184-
PerfMetricValidator.validateAttribute(entry);
186+
validateAttribute(entry.getKey(), entry.getValue());
185187
} catch (IllegalArgumentException exception) {
186188
logger.warn(exception.getLocalizedMessage());
187189
return false;

firebase-perf/src/main/java/com/google/firebase/perf/metrics/validator/PerfMetricValidator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,13 @@ public static String validateMetricName(@Nullable String str) {
135135
/**
136136
* Checks whether the given map entry fits key/value constraints for a Trace Attribute.
137137
*
138-
* @param attribute A key/value pair for an Attribute
138+
* @param key Key for the Attribute
139+
* @param value Value for the Attribute
139140
* @return null if the entry can be used as an Attribute, if not, an error string explaining why
140141
* it can't be used.
141142
*/
142143
@Nullable
143-
public static void validateAttribute(@NonNull Map.Entry<String, String> attribute) {
144-
String key = attribute.getKey();
145-
String value = attribute.getValue();
144+
public static void validateAttribute(@NonNull String key, @NonNull String value) {
146145
if (key == null || key.length() == 0) {
147146
throw new IllegalArgumentException("Attribute key must not be null or empty");
148147
}

0 commit comments

Comments
 (0)