aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebright <sebright@google.com>2017-08-29 12:04:58 -0700
committerGitHub <noreply@github.com>2017-08-29 12:04:58 -0700
commitb58a599882ddb0727d72bcc02c50f87d10b25ea3 (patch)
treee22d0cfae2f1d3e87a1700f62dd6e69ec1eb890d
parentb1a7bdf8e09ac59e797a5e47c9d55064bb4b7af8 (diff)
parent078c7f1d469cd1d5e4fc556a1448f67eb4051412 (diff)
downloadplatform_external_opencensus-java-b58a599882ddb0727d72bcc02c50f87d10b25ea3.tar.gz
platform_external_opencensus-java-b58a599882ddb0727d72bcc02c50f87d10b25ea3.tar.bz2
platform_external_opencensus-java-b58a599882ddb0727d72bcc02c50f87d10b25ea3.zip
Merge pull request #564 from sebright/tag-value-class
Add a TagValue class.
-rw-r--r--core/src/main/java/io/opencensus/stats/ViewData.java15
-rw-r--r--core/src/main/java/io/opencensus/tags/Tag.java38
-rw-r--r--core/src/main/java/io/opencensus/tags/TagContext.java1
-rw-r--r--core/src/main/java/io/opencensus/tags/TagContextBuilder.java11
-rw-r--r--core/src/main/java/io/opencensus/tags/TagKey.java1
-rw-r--r--core/src/main/java/io/opencensus/tags/TagValue.java182
-rw-r--r--core/src/main/java/io/opencensus/tags/TagValueString.java72
-rw-r--r--core/src/test/java/io/opencensus/stats/NoopStatsRecorderTest.java2
-rw-r--r--core/src/test/java/io/opencensus/stats/StatsRecorderTest.java2
-rw-r--r--core/src/test/java/io/opencensus/stats/ViewDataTest.java5
-rw-r--r--core/src/test/java/io/opencensus/tags/CurrentTagContextUtilsTest.java1
-rw-r--r--core/src/test/java/io/opencensus/tags/ScopedTagContextsTest.java7
-rw-r--r--core/src/test/java/io/opencensus/tags/TagTest.java32
-rw-r--r--core/src/test/java/io/opencensus/tags/TagValueStringTest.java58
-rw-r--r--core/src/test/java/io/opencensus/tags/TagValueTest.java154
-rw-r--r--core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java41
-rw-r--r--core_impl/src/main/java/io/opencensus/implcore/tags/SerializationUtils.java5
-rw-r--r--core_impl/src/main/java/io/opencensus/implcore/tags/TagContextBuilderImpl.java19
-rw-r--r--core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java39
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java2
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java7
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java2
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/tags/TagContextDeserializationTest.java2
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/tags/TagContextImplTest.java12
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/tags/TagContextRoundtripTest.java2
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/tags/TagContextSerializationTest.java2
-rw-r--r--core_impl/src/test/java/io/opencensus/implcore/tags/TagContextsImplTest.java22
-rw-r--r--examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java2
28 files changed, 486 insertions, 252 deletions
diff --git a/core/src/main/java/io/opencensus/stats/ViewData.java b/core/src/main/java/io/opencensus/stats/ViewData.java
index 39138f59..9f4a4d1b 100644
--- a/core/src/main/java/io/opencensus/stats/ViewData.java
+++ b/core/src/main/java/io/opencensus/stats/ViewData.java
@@ -20,7 +20,7 @@ import com.google.auto.value.AutoValue;
import io.opencensus.common.Function;
import io.opencensus.common.Functions;
import io.opencensus.common.Timestamp;
-
+import io.opencensus.tags.TagValue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -45,8 +45,7 @@ public abstract class ViewData {
* The {@link AggregationData}s grouped by combination of tag values, associated with this
* {@link ViewData}.
*/
- // TODO(sebright): Create a TagValue class.
- public abstract Map<List<Object>, List<AggregationData>> getAggregationMap();
+ public abstract Map<List<TagValue>, List<AggregationData>> getAggregationMap();
/**
* Returns the {@link WindowData} associated with this {@link ViewData}.
@@ -58,7 +57,7 @@ public abstract class ViewData {
/** Constructs a new {@link ViewData}. */
public static ViewData create(
View view,
- Map<? extends List<? extends Object>, List<AggregationData>> map,
+ Map<? extends List<? extends TagValue>, List<AggregationData>> map,
final WindowData windowData) {
view.getWindow()
.match(
@@ -92,11 +91,11 @@ public abstract class ViewData {
},
Functions.<Void>throwIllegalArgumentException());
- Map<List<Object>, List<AggregationData>> deepCopy =
- new HashMap<List<Object>, List<AggregationData>>();
- for (Entry<? extends List<? extends Object>, List<AggregationData>> entry : map.entrySet()) {
+ Map<List<TagValue>, List<AggregationData>> deepCopy =
+ new HashMap<List<TagValue>, List<AggregationData>>();
+ for (Entry<? extends List<? extends TagValue>, List<AggregationData>> entry : map.entrySet()) {
deepCopy.put(
- Collections.unmodifiableList(new ArrayList<Object>(entry.getKey())),
+ Collections.unmodifiableList(new ArrayList<TagValue>(entry.getKey())),
Collections.unmodifiableList(new ArrayList<AggregationData>(entry.getValue())));
}
diff --git a/core/src/main/java/io/opencensus/tags/Tag.java b/core/src/main/java/io/opencensus/tags/Tag.java
index 3450fb58..a53cd838 100644
--- a/core/src/main/java/io/opencensus/tags/Tag.java
+++ b/core/src/main/java/io/opencensus/tags/Tag.java
@@ -21,6 +21,9 @@ import io.opencensus.common.Function;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import javax.annotation.concurrent.Immutable;
/** {@link TagKey} paired with a value. */
@@ -35,6 +38,15 @@ public abstract class Tag {
public abstract TagKey getKey();
/**
+ * Returns the associated tag value.
+ *
+ * @return the associated tag value.
+ */
+ public abstract TagValue getValue();
+
+ Tag() {}
+
+ /**
* Applies a function to the tag's key and value. The function that is called depends on the type
* of the tag. This is similar to the visitor pattern. {@code match} also takes a function to
* handle the default case, for backwards compatibility when tag types are added. For example,
@@ -115,11 +127,7 @@ public abstract class Tag {
@Override
public abstract TagKeyString getKey();
- /**
- * Returns the associated tag value.
- *
- * @return the associated tag value.
- */
+ @Override
public abstract TagValueString getValue();
@Override
@@ -145,19 +153,15 @@ public abstract class Tag {
* @param value the tag value.
* @return a {@code TagLong} with the given key and value.
*/
- public static TagLong create(TagKeyLong key, long value) {
+ public static TagLong create(TagKeyLong key, TagValueLong value) {
return new AutoValue_Tag_TagLong(key, value);
}
@Override
public abstract TagKeyLong getKey();
- /**
- * Returns the associated tag value.
- *
- * @return the associated tag value.
- */
- public abstract long getValue();
+ @Override
+ public abstract TagValueLong getValue();
@Override
public final <T> T match(
@@ -182,19 +186,15 @@ public abstract class Tag {
* @param value the tag value.
* @return a {@code TagBoolean} with the given key and value.
*/
- public static TagBoolean create(TagKeyBoolean key, boolean value) {
+ public static TagBoolean create(TagKeyBoolean key, TagValueBoolean value) {
return new AutoValue_Tag_TagBoolean(key, value);
}
@Override
public abstract TagKeyBoolean getKey();
- /**
- * Returns the associated tag value.
- *
- * @return the associated tag value.
- */
- public abstract boolean getValue();
+ @Override
+ public abstract TagValueBoolean getValue();
@Override
public final <T> T match(
diff --git a/core/src/main/java/io/opencensus/tags/TagContext.java b/core/src/main/java/io/opencensus/tags/TagContext.java
index 5f40bee4..5743701a 100644
--- a/core/src/main/java/io/opencensus/tags/TagContext.java
+++ b/core/src/main/java/io/opencensus/tags/TagContext.java
@@ -16,6 +16,7 @@
package io.opencensus.tags;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.Collections;
import java.util.Iterator;
import javax.annotation.concurrent.Immutable;
diff --git a/core/src/main/java/io/opencensus/tags/TagContextBuilder.java b/core/src/main/java/io/opencensus/tags/TagContextBuilder.java
index 56efd210..f86d10b3 100644
--- a/core/src/main/java/io/opencensus/tags/TagContextBuilder.java
+++ b/core/src/main/java/io/opencensus/tags/TagContextBuilder.java
@@ -20,6 +20,9 @@ import io.opencensus.common.Scope;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import javax.annotation.concurrent.Immutable;
/** Builder for the {@link TagContext} class. */
@@ -44,7 +47,7 @@ public abstract class TagContextBuilder {
* @param value the value to set for the given key.
* @return this
*/
- public abstract TagContextBuilder set(TagKeyLong key, long value);
+ public abstract TagContextBuilder set(TagKeyLong key, TagValueLong value);
/**
* Adds the key/value pair regardless of whether the key is present.
@@ -53,7 +56,7 @@ public abstract class TagContextBuilder {
* @param value the value to set for the given key.
* @return this
*/
- public abstract TagContextBuilder set(TagKeyBoolean key, boolean value);
+ public abstract TagContextBuilder set(TagKeyBoolean key, TagValueBoolean value);
/**
* Removes the key if it exists.
@@ -100,12 +103,12 @@ public abstract class TagContextBuilder {
}
@Override
- public TagContextBuilder set(TagKeyLong key, long value) {
+ public TagContextBuilder set(TagKeyLong key, TagValueLong value) {
return this;
}
@Override
- public TagContextBuilder set(TagKeyBoolean key, boolean value) {
+ public TagContextBuilder set(TagKeyBoolean key, TagValueBoolean value) {
return this;
}
diff --git a/core/src/main/java/io/opencensus/tags/TagKey.java b/core/src/main/java/io/opencensus/tags/TagKey.java
index aa125bf3..943f12d7 100644
--- a/core/src/main/java/io/opencensus/tags/TagKey.java
+++ b/core/src/main/java/io/opencensus/tags/TagKey.java
@@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.auto.value.AutoValue;
import io.opencensus.common.Function;
import io.opencensus.internal.StringUtil;
+import io.opencensus.tags.TagValue.TagValueString;
import javax.annotation.concurrent.Immutable;
/**
diff --git a/core/src/main/java/io/opencensus/tags/TagValue.java b/core/src/main/java/io/opencensus/tags/TagValue.java
new file mode 100644
index 00000000..7da713c5
--- /dev/null
+++ b/core/src/main/java/io/opencensus/tags/TagValue.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2017, OpenCensus Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.tags;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.base.Preconditions;
+import io.opencensus.common.Function;
+import io.opencensus.internal.StringUtil;
+import io.opencensus.tags.TagKey.TagKeyBoolean;
+import io.opencensus.tags.TagKey.TagKeyLong;
+import io.opencensus.tags.TagKey.TagKeyString;
+import javax.annotation.concurrent.Immutable;
+
+/** A validated tag value. */
+@Immutable
+public abstract class TagValue {
+
+ TagValue() {}
+
+ /**
+ * Applies a function to a tag value. The function that is called depends on the type of the
+ * value. This is similar to the visitor pattern. {@code match} also takes a function to handle
+ * the default case, for backwards compatibility when tag types are added.
+ *
+ * @param stringFunction the function to call when the tag value has type {@code String}.
+ * @param longFunction the function to call when the tag value has type {@code long}.
+ * @param booleanFunction the function to call when the tag value has type {@code boolean}.
+ * @param defaultFunction the function to call when the tag value has a type other than {@code
+ * String}, {@code long}, or {@code boolean}.
+ * @param <T> The result type of the function.
+ * @return The result of calling the function that matches the tag value's type.
+ */
+ public abstract <T> T match(
+ Function<? super TagValueString, T> stringFunction,
+ Function<? super TagValueLong, T> longFunction,
+ Function<? super TagValueBoolean, T> booleanFunction,
+ Function<? super TagValue, T> defaultFunction);
+
+ /**
+ * A validated tag value associated with a {@link TagKeyString}.
+ *
+ * <p>Validation ensures that the {@code String} has a maximum length of {@link #MAX_LENGTH} and
+ * contains only printable ASCII characters.
+ */
+ @Immutable
+ @AutoValue
+ public abstract static class TagValueString extends TagValue {
+ /** The maximum length for a {@code String} tag value. The value is {@value #MAX_LENGTH}. */
+ public static final int MAX_LENGTH = 256;
+
+ TagValueString() {}
+
+ /**
+ * Constructs a {@code TagValueString} from the given string. The string must meet the following
+ * requirements:
+ *
+ * <ol>
+ * <li>It cannot be longer than {@link #MAX_LENGTH}.
+ * <li>It can only contain printable ASCII characters.
+ * </ol>
+ *
+ * @param value the tag value.
+ * @throws IllegalArgumentException if the {@code String} is not valid.
+ */
+ public static TagValueString create(String value) {
+ Preconditions.checkArgument(isValid(value));
+ return new AutoValue_TagValue_TagValueString(value);
+ }
+
+ @Override
+ public final <T> T match(
+ Function<? super TagValueString, T> stringFunction,
+ Function<? super TagValueLong, T> longFunction,
+ Function<? super TagValueBoolean, T> booleanFunction,
+ Function<? super TagValue, T> defaultFunction) {
+ return stringFunction.apply(this);
+ }
+
+ /**
+ * Returns the tag value as a {@code String}.
+ *
+ * @return the tag value as a {@code String}.
+ */
+ public abstract String asString();
+
+ /**
+ * Determines whether the given {@code String} is a valid tag value.
+ *
+ * @param value the tag value to be validated.
+ * @return whether the value is valid.
+ */
+ private static boolean isValid(String value) {
+ return value.length() <= MAX_LENGTH && StringUtil.isPrintableString(value);
+ }
+ }
+
+ /** A tag value associated with a {@link TagKeyLong}. */
+ @Immutable
+ @AutoValue
+ public abstract static class TagValueLong extends TagValue {
+
+ TagValueLong() {}
+
+ /**
+ * Constructs a {@code TagValueLong} from the given {@code long}.
+ *
+ * @param value the tag value.
+ */
+ public static TagValueLong create(long value) {
+ return new AutoValue_TagValue_TagValueLong(value);
+ }
+
+ @Override
+ public final <T> T match(
+ Function<? super TagValueString, T> stringFunction,
+ Function<? super TagValueLong, T> longFunction,
+ Function<? super TagValueBoolean, T> booleanFunction,
+ Function<? super TagValue, T> defaultFunction) {
+ return longFunction.apply(this);
+ }
+
+ /**
+ * Returns the tag value as a {@code long}.
+ *
+ * @return the tag value as a {@code long}.
+ */
+ public abstract long asLong();
+ }
+
+ /** A tag value associated with a {@link TagKeyBoolean}. */
+ @Immutable
+ @AutoValue
+ public abstract static class TagValueBoolean extends TagValue {
+ private static final TagValueBoolean TRUE_VALUE = createInternal(true);
+ private static final TagValueBoolean FALSE_VALUE = createInternal(false);
+
+ TagValueBoolean() {}
+
+ /**
+ * Constructs a {@code TagValueBoolean} from the given {@code boolean}.
+ *
+ * @param value the tag value.
+ */
+ public static TagValueBoolean create(boolean value) {
+ return value ? TRUE_VALUE : FALSE_VALUE;
+ }
+
+ private static TagValueBoolean createInternal(boolean value) {
+ return new AutoValue_TagValue_TagValueBoolean(value);
+ }
+
+ @Override
+ public final <T> T match(
+ Function<? super TagValueString, T> stringFunction,
+ Function<? super TagValueLong, T> longFunction,
+ Function<? super TagValueBoolean, T> booleanFunction,
+ Function<? super TagValue, T> defaultFunction) {
+ return booleanFunction.apply(this);
+ }
+
+ /**
+ * Returns the tag value as a {@code boolean}.
+ *
+ * @return the tag value as a {@code boolean}.
+ */
+ public abstract boolean asBoolean();
+ }
+}
diff --git a/core/src/main/java/io/opencensus/tags/TagValueString.java b/core/src/main/java/io/opencensus/tags/TagValueString.java
deleted file mode 100644
index 96d14d8f..00000000
--- a/core/src/main/java/io/opencensus/tags/TagValueString.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2017, OpenCensus Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.opencensus.tags;
-
-import com.google.auto.value.AutoValue;
-import com.google.common.base.Preconditions;
-import io.opencensus.internal.StringUtil;
-import io.opencensus.tags.TagKey.TagKeyString;
-import javax.annotation.concurrent.Immutable;
-
-/**
- * A validated tag value associated with a {@link TagKeyString}.
- *
- * <p>Validation ensures that the {@code String} has a maximum length of {@link #MAX_LENGTH} and
- * contains only printable ASCII characters.
- */
-@Immutable
-@AutoValue
-public abstract class TagValueString {
- /** The maximum length for a {@code String} tag value. The value is {@value #MAX_LENGTH}. */
- public static final int MAX_LENGTH = 255;
-
- TagValueString() {}
-
- /**
- * Constructs a {@code TagValueString} from the given string. The string must meet the following
- * requirements:
- *
- * <ol>
- * <li>It cannot be longer than {@link #MAX_LENGTH}.
- * <li>It can only contain printable ASCII characters.
- * </ol>
- *
- * @param value the tag value.
- * @throws IllegalArgumentException if the {@code String} is not valid.
- */
- public static TagValueString create(String value) {
- Preconditions.checkArgument(isValid(value));
- return new AutoValue_TagValueString(value);
- }
-
- /**
- * Returns the tag value as a {@code String}.
- *
- * @return the tag value as a {@code String}.
- */
- public abstract String asString();
-
- /**
- * Determines whether the given {@code String} is a valid tag value.
- *
- * @param name the tag value to be validated.
- * @return whether the value is valid.
- */
- private static boolean isValid(String name) {
- return name.length() <= MAX_LENGTH && StringUtil.isPrintableString(name);
- }
-}
diff --git a/core/src/test/java/io/opencensus/stats/NoopStatsRecorderTest.java b/core/src/test/java/io/opencensus/stats/NoopStatsRecorderTest.java
index 9e008755..9f92f3f9 100644
--- a/core/src/test/java/io/opencensus/stats/NoopStatsRecorderTest.java
+++ b/core/src/test/java/io/opencensus/stats/NoopStatsRecorderTest.java
@@ -21,7 +21,7 @@ import io.opencensus.tags.Tag;
import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.Collections;
import java.util.Iterator;
import org.junit.Rule;
diff --git a/core/src/test/java/io/opencensus/stats/StatsRecorderTest.java b/core/src/test/java/io/opencensus/stats/StatsRecorderTest.java
index fd9b1d18..8835bf32 100644
--- a/core/src/test/java/io/opencensus/stats/StatsRecorderTest.java
+++ b/core/src/test/java/io/opencensus/stats/StatsRecorderTest.java
@@ -25,7 +25,7 @@ import io.opencensus.tags.Tag;
import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.tags.unsafe.ContextUtils;
import java.util.Collections;
import java.util.Iterator;
diff --git a/core/src/test/java/io/opencensus/stats/ViewDataTest.java b/core/src/test/java/io/opencensus/stats/ViewDataTest.java
index ab7b9917..e39b80e4 100644
--- a/core/src/test/java/io/opencensus/stats/ViewDataTest.java
+++ b/core/src/test/java/io/opencensus/stats/ViewDataTest.java
@@ -44,7 +44,8 @@ import io.opencensus.stats.ViewData.WindowData;
import io.opencensus.stats.ViewData.WindowData.CumulativeData;
import io.opencensus.stats.ViewData.WindowData.IntervalData;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -119,7 +120,7 @@ public final class ViewDataTest {
IntervalData.create(Timestamp.fromMillis(2000))))
.addEqualityGroup(
ViewData.create(
- intervalView, Collections.<List<Object>, List<AggregationData>>emptyMap(),
+ intervalView, Collections.<List<TagValue>, List<AggregationData>>emptyMap(),
IntervalData.create(Timestamp.fromMillis(2000))))
.testEquals();
}
diff --git a/core/src/test/java/io/opencensus/tags/CurrentTagContextUtilsTest.java b/core/src/test/java/io/opencensus/tags/CurrentTagContextUtilsTest.java
index 560c9e87..36b502d6 100644
--- a/core/src/test/java/io/opencensus/tags/CurrentTagContextUtilsTest.java
+++ b/core/src/test/java/io/opencensus/tags/CurrentTagContextUtilsTest.java
@@ -24,6 +24,7 @@ import io.grpc.Context;
import io.opencensus.common.Scope;
import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.tags.unsafe.ContextUtils;
import java.util.Iterator;
import java.util.List;
diff --git a/core/src/test/java/io/opencensus/tags/ScopedTagContextsTest.java b/core/src/test/java/io/opencensus/tags/ScopedTagContextsTest.java
index d9d25fb1..5adbcfec 100644
--- a/core/src/test/java/io/opencensus/tags/ScopedTagContextsTest.java
+++ b/core/src/test/java/io/opencensus/tags/ScopedTagContextsTest.java
@@ -26,6 +26,9 @@ import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -151,12 +154,12 @@ public class ScopedTagContextsTest {
}
@Override
- public TagContextBuilder set(TagKeyLong key, long value) {
+ public TagContextBuilder set(TagKeyLong key, TagValueLong value) {
throw new UnsupportedOperationException();
}
@Override
- public TagContextBuilder set(TagKeyBoolean key, boolean value) {
+ public TagContextBuilder set(TagKeyBoolean key, TagValueBoolean value) {
throw new UnsupportedOperationException();
}
diff --git a/core/src/test/java/io/opencensus/tags/TagTest.java b/core/src/test/java/io/opencensus/tags/TagTest.java
index db2fd927..79b2eb4d 100644
--- a/core/src/test/java/io/opencensus/tags/TagTest.java
+++ b/core/src/test/java/io/opencensus/tags/TagTest.java
@@ -27,6 +27,9 @@ import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -37,20 +40,19 @@ public final class TagTest {
@Test
public void testGetStringKey() {
- assertThat(
- TagString.create(TagKeyString.create("k"), TagValueString.create("v")).getKey())
+ assertThat(TagString.create(TagKeyString.create("k"), TagValueString.create("v")).getKey())
.isEqualTo(TagKeyString.create("k"));
}
@Test
public void testGetLongKey() {
- assertThat(TagLong.create(TagKeyLong.create("k"), 2L).getKey())
+ assertThat(TagLong.create(TagKeyLong.create("k"), TagValueLong.create(2L)).getKey())
.isEqualTo(TagKeyLong.create("k"));
}
@Test
public void testGetBooleanKey() {
- assertThat(TagBoolean.create(TagKeyBoolean.create("k"), false).getKey())
+ assertThat(TagBoolean.create(TagKeyBoolean.create("k"), TagValueBoolean.create(false)).getKey())
.isEqualTo(TagKeyBoolean.create("k"));
}
@@ -84,7 +86,7 @@ public final class TagTest {
@Test
public void testMatchLong() {
assertThat(
- TagLong.create(TagKeyLong.create("k2"), 3L)
+ TagLong.create(TagKeyLong.create("k2"), TagValueLong.create(3L))
.match(
new Function<TagString, Long>() {
@Override
@@ -95,7 +97,7 @@ public final class TagTest {
new Function<TagLong, Long>() {
@Override
public Long apply(TagLong tag) {
- return tag.getValue();
+ return tag.getValue().asLong();
}
},
new Function<TagBoolean, Long>() {
@@ -111,7 +113,7 @@ public final class TagTest {
@Test
public void testMatchBoolean() {
assertThat(
- TagBoolean.create(TagKeyBoolean.create("k3"), false)
+ TagBoolean.create(TagKeyBoolean.create("k3"), TagValueBoolean.create(false))
.match(
new Function<TagString, Boolean>() {
@Override
@@ -128,7 +130,7 @@ public final class TagTest {
new Function<TagBoolean, Boolean>() {
@Override
public Boolean apply(TagBoolean tag) {
- return tag.getValue();
+ return tag.getValue().asBoolean();
}
},
Functions.<Boolean>throwIllegalArgumentException()))
@@ -142,13 +144,15 @@ public final class TagTest {
TagString.create(TagKeyString.create("Key1"), TagValueString.create("foo")),
TagString.create(TagKeyString.create("Key1"), TagValueString.create("foo")))
.addEqualityGroup(
- TagLong.create(TagKeyLong.create("Key1"), 100L),
- TagLong.create(TagKeyLong.create("Key1"), 100L))
+ TagLong.create(TagKeyLong.create("Key1"), TagValueLong.create(100L)),
+ TagLong.create(TagKeyLong.create("Key1"), TagValueLong.create(100L)))
+ .addEqualityGroup(
+ TagBoolean.create(TagKeyBoolean.create("Key1"), TagValueBoolean.create(true)),
+ TagBoolean.create(TagKeyBoolean.create("Key1"), TagValueBoolean.create(true)))
+ .addEqualityGroup(
+ TagBoolean.create(TagKeyBoolean.create("Key2"), TagValueBoolean.create(true)))
.addEqualityGroup(
- TagBoolean.create(TagKeyBoolean.create("Key1"), true),
- TagBoolean.create(TagKeyBoolean.create("Key1"), true))
- .addEqualityGroup(TagBoolean.create(TagKeyBoolean.create("Key2"), true))
- .addEqualityGroup(TagBoolean.create(TagKeyBoolean.create("Key1"), false))
+ TagBoolean.create(TagKeyBoolean.create("Key1"), TagValueBoolean.create(false)))
.testEquals();
}
}
diff --git a/core/src/test/java/io/opencensus/tags/TagValueStringTest.java b/core/src/test/java/io/opencensus/tags/TagValueStringTest.java
deleted file mode 100644
index fb997790..00000000
--- a/core/src/test/java/io/opencensus/tags/TagValueStringTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2017, OpenCensus Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.opencensus.tags;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import io.opencensus.tags.TagValueString;
-import java.util.Arrays;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for {@link TagValueString}. */
-@RunWith(JUnit4.class)
-public class TagValueStringTest {
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void allowStringTagValueWithMaxLength() {
- char[] chars = new char[TagValueString.MAX_LENGTH];
- Arrays.fill(chars, 'v');
- String value = new String(chars);
- assertThat(TagValueString.create(value).asString()).isEqualTo(value);
- }
-
- @Test
- public void disallowStringTagValueOverMaxLength() {
- char[] chars = new char[TagValueString.MAX_LENGTH + 1];
- Arrays.fill(chars, 'v');
- String value = new String(chars);
- thrown.expect(IllegalArgumentException.class);
- TagValueString.create(value);
- }
-
- @Test
- public void disallowStringTagValueWithUnprintableChars() {
- String value = "\2ab\3cd";
- thrown.expect(IllegalArgumentException.class);
- TagValueString.create(value);
- }
-}
diff --git a/core/src/test/java/io/opencensus/tags/TagValueTest.java b/core/src/test/java/io/opencensus/tags/TagValueTest.java
new file mode 100644
index 00000000..b1382312
--- /dev/null
+++ b/core/src/test/java/io/opencensus/tags/TagValueTest.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2017, OpenCensus Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.tags;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.testing.EqualsTester;
+import io.opencensus.common.Function;
+import io.opencensus.common.Functions;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
+import java.util.Arrays;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link TagValue}. */
+@RunWith(JUnit4.class)
+public final class TagValueTest {
+
+ @Rule public final ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testMatchStringValue() {
+ assertThat(
+ TagValueString.create("value")
+ .match(
+ new Function<TagValueString, String>() {
+ @Override
+ public String apply(TagValueString tag) {
+ return tag.asString();
+ }
+ },
+ new Function<TagValueLong, String>() {
+ @Override
+ public String apply(TagValueLong tag) {
+ throw new AssertionError();
+ }
+ },
+ new Function<TagValueBoolean, String>() {
+ @Override
+ public String apply(TagValueBoolean tag) {
+ throw new AssertionError();
+ }
+ },
+ Functions.<String>throwIllegalArgumentException()))
+ .isEqualTo("value");
+ }
+
+ @Test
+ public void testMatchLongValue() {
+ assertThat(
+ TagValueLong.create(1234)
+ .match(
+ new Function<TagValueString, Long>() {
+ @Override
+ public Long apply(TagValueString tag) {
+ throw new AssertionError();
+ }
+ },
+ new Function<TagValueLong, Long>() {
+ @Override
+ public Long apply(TagValueLong tag) {
+ return tag.asLong();
+ }
+ },
+ new Function<TagValueBoolean, Long>() {
+ @Override
+ public Long apply(TagValueBoolean tag) {
+ throw new AssertionError();
+ }
+ },
+ Functions.<Long>throwIllegalArgumentException()))
+ .isEqualTo(1234);
+ }
+
+ @Test
+ public void testMatchBooleanValue() {
+ assertThat(
+ TagValueBoolean.create(false)
+ .match(
+ new Function<TagValueString, Boolean>() {
+ @Override
+ public Boolean apply(TagValueString tag) {
+ throw new AssertionError();
+ }
+ },
+ new Function<TagValueLong, Boolean>() {
+ @Override
+ public Boolean apply(TagValueLong tag) {
+ throw new AssertionError();
+ }
+ },
+ new Function<TagValueBoolean, Boolean>() {
+ @Override
+ public Boolean apply(TagValueBoolean tag) {
+ return tag.asBoolean();
+ }
+ },
+ Functions.<Boolean>throwIllegalArgumentException()))
+ .isEqualTo(false);
+ }
+
+ @Test
+ public void allowStringTagValueWithMaxLength() {
+ char[] chars = new char[TagValueString.MAX_LENGTH];
+ Arrays.fill(chars, 'v');
+ String value = new String(chars);
+ assertThat(TagValueString.create(value).asString()).isEqualTo(value);
+ }
+
+ @Test
+ public void disallowStringTagValueOverMaxLength() {
+ char[] chars = new char[TagValueString.MAX_LENGTH + 1];
+ Arrays.fill(chars, 'v');
+ String value = new String(chars);
+ thrown.expect(IllegalArgumentException.class);
+ TagValueString.create(value);
+ }
+
+ @Test
+ public void disallowStringTagValueWithUnprintableChars() {
+ String value = "\2ab\3cd";
+ thrown.expect(IllegalArgumentException.class);
+ TagValueString.create(value);
+ }
+
+ @Test
+ public void testTagValueEquals() {
+ new EqualsTester()
+ .addEqualityGroup(TagValueString.create("foo"), TagValueString.create("foo"))
+ .addEqualityGroup(TagValueLong.create(2))
+ .addEqualityGroup(TagValueBoolean.create(true))
+ .addEqualityGroup(TagValueString.create("bar"))
+ .testEquals();
+ }
+}
diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java b/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
index 8fcc9a42..aeefd498 100644
--- a/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
+++ b/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
@@ -55,6 +55,7 @@ import io.opencensus.tags.Tag.TagLong;
import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagKey;
+import io.opencensus.tags.TagValue;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -67,36 +68,36 @@ import javax.annotation.Nullable;
*/
final class MutableViewData {
- private static final Function<TagString, Object> GET_STRING_TAG_VALUE =
- new Function<TagString, Object>() {
+ private static final Function<TagString, TagValue> GET_STRING_TAG_VALUE =
+ new Function<TagString, TagValue>() {
@Override
- public Object apply(TagString tag) {
+ public TagValue apply(TagString tag) {
return tag.getValue();
}
};
- private static final Function<TagLong, Object> GET_LONG_TAG_VALUE =
- new Function<TagLong, Object>() {
+ private static final Function<TagLong, TagValue> GET_LONG_TAG_VALUE =
+ new Function<TagLong, TagValue>() {
@Override
- public Object apply(TagLong tag) {
+ public TagValue apply(TagLong tag) {
return tag.getValue();
}
};
- private static final Function<TagBoolean, Object> GET_BOOLEAN_TAG_VALUE =
- new Function<TagBoolean, Object>() {
+ private static final Function<TagBoolean, TagValue> GET_BOOLEAN_TAG_VALUE =
+ new Function<TagBoolean, TagValue>() {
@Override
- public Object apply(TagBoolean tag) {
+ public TagValue apply(TagBoolean tag) {
return tag.getValue();
}
};
// TODO(sebright): Change this field to type TagValue once we have a TagValue class.
@VisibleForTesting
- static final Object UNKNOWN_TAG_VALUE = null;
+ static final TagValue UNKNOWN_TAG_VALUE = null;
private final View view;
- private final Map<List<Object>, List<MutableAggregation>> tagValueAggregationMap =
+ private final Map<List<TagValue>, List<MutableAggregation>> tagValueAggregationMap =
Maps.newHashMap();
@Nullable private final Timestamp start;
@@ -141,7 +142,7 @@ final class MutableViewData {
* Record double stats with the given tags.
*/
void record(TagContext context, double value) {
- List<Object> tagValues = getTagValues(getTagMap(context), view.getColumns());
+ List<TagValue> tagValues = getTagValues(getTagMap(context), view.getColumns());
if (!tagValueAggregationMap.containsKey(tagValues)) {
List<MutableAggregation> aggregations = Lists.newArrayList();
for (Aggregation aggregation : view.getAggregations()) {
@@ -162,11 +163,11 @@ final class MutableViewData {
throw new UnsupportedOperationException("Not implemented.");
}
- private static Map<TagKey, Object> getTagMap(TagContext ctx) {
+ private static Map<TagKey, TagValue> getTagMap(TagContext ctx) {
if (ctx instanceof TagContextImpl) {
return ((TagContextImpl) ctx).getTags();
} else {
- Map<TagKey, Object> tags = Maps.newHashMap();
+ Map<TagKey, TagValue> tags = Maps.newHashMap();
for (Iterator<Tag> i = ctx.unsafeGetIterator(); i.hasNext(); ) {
Tag tag = i.next();
tags.put(
@@ -175,7 +176,7 @@ final class MutableViewData {
GET_STRING_TAG_VALUE,
GET_LONG_TAG_VALUE,
GET_BOOLEAN_TAG_VALUE,
- Functions.throwAssertionError()));
+ Functions.<TagValue>throwAssertionError()));
}
return tags;
}
@@ -185,8 +186,8 @@ final class MutableViewData {
* Convert this {@link MutableViewData} to {@link ViewData}.
*/
ViewData toViewData(Clock clock) {
- Map<List<Object>, List<AggregationData>> map = Maps.newHashMap();
- for (Entry<List<Object>, List<MutableAggregation>> entry :
+ Map<List<TagValue>, List<AggregationData>> map = Maps.newHashMap();
+ for (Entry<List<TagValue>, List<MutableAggregation>> entry :
tagValueAggregationMap.entrySet()) {
List<AggregationData> aggregates = Lists.newArrayList();
for (MutableAggregation aggregation : entry.getValue()) {
@@ -206,9 +207,9 @@ final class MutableViewData {
}
@VisibleForTesting
- static List<Object> getTagValues(
- Map<? extends TagKey, ? extends Object> tags, List<? extends TagKey> columns) {
- List<Object> tagValues = new ArrayList<Object>(columns.size());
+ static List<TagValue> getTagValues(
+ Map<? extends TagKey, ? extends TagValue> tags, List<? extends TagKey> columns) {
+ List<TagValue> tagValues = new ArrayList<TagValue>(columns.size());
// Record all the measures in a "Greedy" way.
// Every view aggregates every measure. This is similar to doing a GROUPBY view’s keys.
for (int i = 0; i < columns.size(); ++i) {
diff --git a/core_impl/src/main/java/io/opencensus/implcore/tags/SerializationUtils.java b/core_impl/src/main/java/io/opencensus/implcore/tags/SerializationUtils.java
index 7b648f1e..d43cc5d3 100644
--- a/core_impl/src/main/java/io/opencensus/implcore/tags/SerializationUtils.java
+++ b/core_impl/src/main/java/io/opencensus/implcore/tags/SerializationUtils.java
@@ -28,7 +28,8 @@ import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue;
+import io.opencensus.tags.TagValue.TagValueString;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -137,7 +138,7 @@ final class SerializationUtils {
static TagContextImpl deserializeBinary(InputStream input) throws IOException {
try {
byte[] bytes = ByteStreams.toByteArray(input);
- HashMap<TagKey, Object> tags = new HashMap<TagKey, Object>();
+ HashMap<TagKey, TagValue> tags = new HashMap<TagKey, TagValue>();
if (bytes.length == 0) {
// Does not allow empty byte array.
throw new IOException("Input byte stream can not be empty.");
diff --git a/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextBuilderImpl.java b/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextBuilderImpl.java
index f456fa3d..d22b1c49 100644
--- a/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextBuilderImpl.java
+++ b/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextBuilderImpl.java
@@ -23,19 +23,22 @@ import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.HashMap;
import java.util.Map;
final class TagContextBuilderImpl extends TagContextBuilder {
- private final Map<TagKey, Object> tags;
+ private final Map<TagKey, TagValue> tags;
- TagContextBuilderImpl(Map<TagKey, Object> tags) {
- this.tags = new HashMap<TagKey, Object>(tags);
+ TagContextBuilderImpl(Map<TagKey, TagValue> tags) {
+ this.tags = new HashMap<TagKey, TagValue>(tags);
}
TagContextBuilderImpl() {
- this.tags = new HashMap<TagKey, Object>();
+ this.tags = new HashMap<TagKey, TagValue>();
}
@Override
@@ -44,16 +47,16 @@ final class TagContextBuilderImpl extends TagContextBuilder {
}
@Override
- public TagContextBuilderImpl set(TagKeyLong key, long value) {
+ public TagContextBuilderImpl set(TagKeyLong key, TagValueLong value) {
return setInternal(key, value);
}
@Override
- public TagContextBuilderImpl set(TagKeyBoolean key, boolean value) {
+ public TagContextBuilderImpl set(TagKeyBoolean key, TagValueBoolean value) {
return setInternal(key, value);
}
- private TagContextBuilderImpl setInternal(TagKey key, Object value) {
+ private TagContextBuilderImpl setInternal(TagKey key, TagValue value) {
tags.put(checkNotNull(key), value);
return this;
}
diff --git a/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java b/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java
index 36a7383b..780b7c02 100644
--- a/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java
+++ b/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java
@@ -27,7 +27,10 @@ import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -38,16 +41,16 @@ import javax.annotation.concurrent.Immutable;
@Immutable
public final class TagContextImpl extends TagContext {
- static final TagContextImpl EMPTY = new TagContextImpl(Collections.<TagKey, Object>emptyMap());
+ static final TagContextImpl EMPTY = new TagContextImpl(Collections.<TagKey, TagValue>emptyMap());
// The types of the TagKey and value must match for each entry.
- private final Map<TagKey, Object> tags;
+ private final Map<TagKey, TagValue> tags;
- TagContextImpl(Map<? extends TagKey, ?> tags) {
- this.tags = Collections.unmodifiableMap(new HashMap<TagKey, Object>(tags));
+ TagContextImpl(Map<? extends TagKey, ? extends TagValue> tags) {
+ this.tags = Collections.unmodifiableMap(new HashMap<TagKey, TagValue>(tags));
}
- public Map<TagKey, Object> getTags() {
+ public Map<TagKey, TagValue> getTags() {
return tags;
}
@@ -57,9 +60,9 @@ public final class TagContextImpl extends TagContext {
}
private static final class TagIterator implements Iterator<Tag> {
- Iterator<Map.Entry<TagKey, Object>> iterator;
+ Iterator<Map.Entry<TagKey, TagValue>> iterator;
- TagIterator(Map<TagKey, Object> tags) {
+ TagIterator(Map<TagKey, TagValue> tags) {
iterator = tags.entrySet().iterator();
}
@@ -70,8 +73,8 @@ public final class TagContextImpl extends TagContext {
@Override
public Tag next() {
- final Entry<TagKey, Object> next = iterator.next();
- Object value = next.getValue();
+ final Entry<TagKey, TagValue> next = iterator.next();
+ TagValue value = next.getValue();
return next.getKey()
.match(
new NewTagString(value),
@@ -86,9 +89,9 @@ public final class TagContextImpl extends TagContext {
}
private static class NewTagString implements Function<TagKeyString, Tag> {
- private final Object value;
+ private final TagValue value;
- NewTagString(Object value) {
+ NewTagString(TagValue value) {
this.value = value;
}
@@ -99,28 +102,28 @@ public final class TagContextImpl extends TagContext {
}
private static class NewTagLong implements Function<TagKeyLong, Tag> {
- private final Object value;
+ private final TagValue value;
- NewTagLong(Object value) {
+ NewTagLong(TagValue value) {
this.value = value;
}
@Override
public Tag apply(TagKeyLong key) {
- return TagLong.create(key, (Long) value);
+ return TagLong.create(key, (TagValueLong) value);
}
}
private static class NewTagBoolean implements Function<TagKeyBoolean, Tag> {
- private final Object value;
+ private final TagValue value;
- NewTagBoolean(Object value) {
+ NewTagBoolean(TagValue value) {
this.value = value;
}
@Override
public Tag apply(TagKeyBoolean key) {
- return TagBoolean.create(key, (Boolean) value);
+ return TagBoolean.create(key, (TagValueBoolean) value);
}
}
}
diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java
index f6e7c318..d4259ccd 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java
@@ -38,7 +38,7 @@ import io.opencensus.stats.AggregationData.SumData;
import io.opencensus.stats.BucketBoundaries;
import io.opencensus.stats.UnreleasedApiAccessor;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java b/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java
index 14bdaa5e..1ce8dc18 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java
@@ -29,6 +29,7 @@ import io.opencensus.stats.AggregationData.MeanData;
import io.opencensus.stats.AggregationData.RangeData;
import io.opencensus.stats.AggregationData.StdDevData;
import io.opencensus.stats.AggregationData.SumData;
+import io.opencensus.tags.TagValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -68,11 +69,11 @@ final class StatsTestUtil {
* @param tolerance the tolerance used for {@code double} comparison.
*/
static void assertAggregationMapEquals(
- Map<? extends List<? extends Object>, List<AggregationData>> actual,
- Map<? extends List<? extends Object>, List<AggregationData>> expected,
+ Map<? extends List<? extends TagValue>, List<AggregationData>> actual,
+ Map<? extends List<? extends TagValue>, List<AggregationData>> expected,
double tolerance) {
assertThat(actual.keySet()).containsExactlyElementsIn(expected.keySet());
- for (List<? extends Object> tagValues : actual.keySet()) {
+ for (List<? extends TagValue> tagValues : actual.keySet()) {
assertAggregationDataListEquals(expected.get(tagValues), actual.get(tagValues), tolerance);
}
}
diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java
index 52b445ca..d38f0597 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java
@@ -43,7 +43,7 @@ import io.opencensus.stats.ViewData.WindowData.CumulativeData;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.testing.common.TestClock;
import java.util.Arrays;
import java.util.Collections;
diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextDeserializationTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextDeserializationTest.java
index 5b43f5e1..e9da5c87 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextDeserializationTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextDeserializationTest.java
@@ -24,7 +24,7 @@ import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagContextBinarySerializer;
import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextImplTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextImplTest.java
index 3afefd00..f609a393 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextImplTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextImplTest.java
@@ -30,7 +30,9 @@ import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.tags.UnreleasedApiAccessor;
import java.util.Arrays;
import java.util.Iterator;
@@ -66,13 +68,13 @@ public class TagContextImplTest {
tagContexts
.emptyBuilder()
.set(stringKey, TagValueString.create("value"))
- .set(longKey, 123)
- .set(boolKey, true)
+ .set(longKey, TagValueLong.create(123))
+ .set(boolKey, TagValueBoolean.create(true))
.build()))
.containsExactly(
TagString.create(stringKey, TagValueString.create("value")),
- TagLong.create(longKey, 123L),
- TagBoolean.create(boolKey, true));
+ TagLong.create(longKey, TagValueLong.create(123L)),
+ TagBoolean.create(boolKey, TagValueBoolean.create(true)));
}
@Test
diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextRoundtripTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextRoundtripTest.java
index 4f9b8622..e8a6dfde 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextRoundtripTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextRoundtripTest.java
@@ -23,7 +23,7 @@ import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagContextBinarySerializer;
import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.junit.Test;
diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextSerializationTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextSerializationTest.java
index 25b4ca35..f21c40af 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextSerializationTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextSerializationTest.java
@@ -25,7 +25,7 @@ import io.opencensus.tags.TagContextBinarySerializer;
import io.opencensus.tags.TagContextBuilder;
import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextsImplTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextsImplTest.java
index 1924264f..fb78287e 100644
--- a/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextsImplTest.java
+++ b/core_impl/src/test/java/io/opencensus/implcore/tags/TagContextsImplTest.java
@@ -28,7 +28,9 @@ import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyBoolean;
import io.opencensus.tags.TagKey.TagKeyLong;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueBoolean;
+import io.opencensus.tags.TagValue.TagValueLong;
+import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.tags.UnreleasedApiAccessor;
import java.util.Collections;
import java.util.Iterator;
@@ -48,8 +50,10 @@ public class TagContextsImplTest {
private static final TagKeyLong KL = UnreleasedApiAccessor.createTagKeyLong("kl");
private static final TagKeyBoolean KB = UnreleasedApiAccessor.createTagKeyBoolean("kb");
- private static final TagValueString V1 = TagValueString.create("v1");
- private static final TagValueString V2 = TagValueString.create("v2");
+ private static final TagValueString VS1 = TagValueString.create("v1");
+ private static final TagValueString VS2 = TagValueString.create("v2");
+ private static final TagValueLong VL = TagValueLong.create(10L);
+ private static final TagValueBoolean VB = TagValueBoolean.create(false);
@Rule public final ExpectedException thrown = ExpectedException.none();
@@ -65,9 +69,9 @@ public class TagContextsImplTest {
@Test
public void toBuilder_ConvertUnknownTagContextToTagContextImpl() {
- Tag tag1 = TagString.create(KS, V1);
- Tag tag2 = TagLong.create(KL, 10L);
- Tag tag3 = TagBoolean.create(KB, false);
+ Tag tag1 = TagString.create(KS, VS1);
+ Tag tag2 = TagLong.create(KL, VL);
+ Tag tag3 = TagBoolean.create(KB, VB);
TagContext unknownTagContext = new SimpleTagContext(tag1, tag2, tag3);
TagContext newTagContext = tagContexts.toBuilder(unknownTagContext).build();
assertThat(asList(newTagContext)).containsExactly(tag1, tag2, tag3);
@@ -76,8 +80,8 @@ public class TagContextsImplTest {
@Test
public void toBuilder_RemoveDuplicatesFromUnknownTagContext() {
- Tag tag1 = TagString.create(KS, V1);
- Tag tag2 = TagString.create(KS, V2);
+ Tag tag1 = TagString.create(KS, VS1);
+ Tag tag2 = TagString.create(KS, VS2);
TagContext unknownTagContext = new SimpleTagContext(tag1, tag2);
TagContext newTagContext = tagContexts.toBuilder(unknownTagContext).build();
assertThat(asList(newTagContext)).containsExactly(tag2);
@@ -86,7 +90,7 @@ public class TagContextsImplTest {
@Test
public void toBuilder_HandleNullTag() {
TagContext unknownTagContext =
- new SimpleTagContext(TagString.create(KS, V2), null, TagLong.create(KL, 5L));
+ new SimpleTagContext(TagString.create(KS, VS2), null, TagLong.create(KL, VL));
thrown.expect(NullPointerException.class);
tagContexts.toBuilder(unknownTagContext).build();
}
diff --git a/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java b/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java
index 1301af00..95fff962 100644
--- a/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java
+++ b/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java
@@ -24,7 +24,7 @@ import io.opencensus.stats.StatsRecorder;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagContexts;
import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValueString;
+import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.tags.Tags;
/** Simple program that uses Stats contexts. */