Merge "allow clearing fields for LogMaker reuse"
This commit is contained in:
committed by
Android (Google) Code Review
commit
325026dd5c
@@ -26109,6 +26109,7 @@ package android.metrics {
|
||||
ctor public LogMaker(int);
|
||||
ctor public LogMaker(java.lang.Object[]);
|
||||
method public android.metrics.LogMaker addTaggedData(int, java.lang.Object);
|
||||
method public android.metrics.LogMaker clearTaggedData(int);
|
||||
method public void deserialize(java.lang.Object[]);
|
||||
method public int getCategory();
|
||||
method public long getCounterBucket();
|
||||
|
||||
@@ -102,10 +102,13 @@ public class LogMaker {
|
||||
|
||||
/**
|
||||
* @param tag From your MetricsEvent enum.
|
||||
* @param value One of Integer, Long, Float, String
|
||||
* @return
|
||||
* @param value One of Integer, Long, Float, or String; or null to clear the tag.
|
||||
* @return modified LogMaker
|
||||
*/
|
||||
public LogMaker addTaggedData(int tag, Object value) {
|
||||
if (value == null) {
|
||||
return clearTaggedData(tag);
|
||||
}
|
||||
if (!isValidValue(value)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value must be loggable type - int, long, float, String");
|
||||
@@ -118,11 +121,21 @@ public class LogMaker {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a value from the LogMaker.
|
||||
*
|
||||
* @param tag From your MetricsEvent enum.
|
||||
* @return modified LogMaker
|
||||
*/
|
||||
public LogMaker clearTaggedData(int tag) {
|
||||
entries.delete(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this object may be added to a LogMaker as a value.
|
||||
*/
|
||||
public boolean isValidValue(Object value) {
|
||||
if (value == null) {
|
||||
Log.i("LogBuilder", "Logging a null value.");
|
||||
return true;
|
||||
}
|
||||
return value instanceof Integer ||
|
||||
value instanceof String ||
|
||||
value instanceof Long ||
|
||||
|
||||
@@ -115,6 +115,13 @@ public class LogMakerTest extends TestCase {
|
||||
assertEquals(10, out[1]);
|
||||
}
|
||||
|
||||
public void testClearData() {
|
||||
LogMaker builder = new LogMaker(0);
|
||||
builder.addTaggedData(1, "onetwothree");
|
||||
builder.clearTaggedData(1);
|
||||
assertEquals(null, builder.getTaggedData(1));
|
||||
}
|
||||
|
||||
public void testGiantLogOmitted() {
|
||||
LogMaker badBuilder = new LogMaker(0);
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user