Skip to content

Commit a31f9fe

Browse files
committed
Wrap up comments for code clarity.
1 parent 836fbe9 commit a31f9fe

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 6 additions & 4 deletions
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 android.os.Parcel;
1820
import android.os.Parcelable;
1921
import androidx.annotation.Keep;
@@ -209,7 +211,7 @@ public void start() {
209211
return;
210212
}
211213

212-
String err = PerfMetricValidator.validateTraceName(name);
214+
String err = validateTraceName(name);
213215

214216
if (err != null) {
215217
logger.error("Cannot start trace '%s'. Trace name is invalid.(%s)", name, err);
@@ -326,7 +328,7 @@ private Counter obtainOrCreateCounterByName(@NonNull String counterName) {
326328
*/
327329
@Keep
328330
public void incrementMetric(@NonNull String metricName, long incrementBy) {
329-
String err = PerfMetricValidator.validateMetricName(metricName);
331+
String err = validateMetricName(metricName);
330332
if (err != null) {
331333
logger.error("Cannot increment metric '%s'. Metric name is invalid.(%s)", metricName, err);
332334
return;
@@ -382,7 +384,7 @@ public long getLongMetric(@NonNull String metricName) {
382384
*/
383385
@Keep
384386
public void putMetric(@NonNull String metricName, long value) {
385-
String err = PerfMetricValidator.validateMetricName(metricName);
387+
String err = validateMetricName(metricName);
386388
if (err != null) {
387389
logger.error(
388390
"Cannot set value for metric '%s'. Metric name is invalid.(%s)", metricName, err);
@@ -639,7 +641,7 @@ private void checkAttribute(@NonNull String key, @NonNull String value) {
639641
"Exceeds max limit of number of attributes - %d",
640642
Constants.MAX_TRACE_CUSTOM_ATTRIBUTES));
641643
}
642-
PerfMetricValidator.validateAttribute(new AbstractMap.SimpleEntry<>(key, value));
644+
validateAttribute(new AbstractMap.SimpleEntry<>(key, value));
643645
}
644646

645647
/**

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,29 @@ public static void validateAttribute(@NonNull Map.Entry<String, String> attribut
145145
String value = attribute.getValue();
146146
if (key == null || key.length() == 0) {
147147
throw new IllegalArgumentException("Attribute key must not be null or empty");
148-
} else if (value == null || value.length() == 0) {
148+
}
149+
150+
if (value == null || value.length() == 0) {
149151
throw new IllegalArgumentException("Attribute value must not be null or empty");
150-
} else if (key.length() > Constants.MAX_ATTRIBUTE_KEY_LENGTH) {
152+
}
153+
154+
if (key.length() > Constants.MAX_ATTRIBUTE_KEY_LENGTH) {
151155
throw new IllegalArgumentException(
152156
String.format(
153157
Locale.US,
154158
"Attribute key length must not exceed %d characters",
155159
Constants.MAX_ATTRIBUTE_KEY_LENGTH));
156-
} else if (value.length() > Constants.MAX_ATTRIBUTE_VALUE_LENGTH) {
160+
}
161+
162+
if (value.length() > Constants.MAX_ATTRIBUTE_VALUE_LENGTH) {
157163
throw new IllegalArgumentException(
158164
String.format(
159165
Locale.US,
160166
"Attribute value length must not exceed %d characters",
161167
Constants.MAX_ATTRIBUTE_VALUE_LENGTH));
162-
} else if (!key.matches("^(?!(firebase_|google_|ga_))[A-Za-z][A-Za-z_0-9]*")) {
168+
}
169+
170+
if (!key.matches("^(?!(firebase_|google_|ga_))[A-Za-z][A-Za-z_0-9]*")) {
163171
throw new IllegalArgumentException(
164172
"Attribute key must start with letter, must only contain alphanumeric characters and"
165173
+ " underscore and must not start with \"firebase_\", \"google_\" and \"ga_");

0 commit comments

Comments
 (0)