aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/main
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2017-06-09 08:50:10 -0700
committerKristen Kozak <sebright@google.com>2017-06-09 08:58:36 -0700
commit453f93217f3561aeb9fc95984274bdc26751fbb7 (patch)
treee7ae80fda231520a97eb94a60fe7e7e105b069b4 /api/src/main
parentbeebb4e7b8948e9f5a7fb72d87538166980173c9 (diff)
downloadplatform_external_opencensus-java-453f93217f3561aeb9fc95984274bdc26751fbb7.tar.gz
platform_external_opencensus-java-453f93217f3561aeb9fc95984274bdc26751fbb7.tar.bz2
platform_external_opencensus-java-453f93217f3561aeb9fc95984274bdc26751fbb7.zip
Temporarily move "tags" package back to "core" directory.
The tags API isn't ready to be released, so it should be moved out of the "api" directory.
Diffstat (limited to 'api/src/main')
-rw-r--r--api/src/main/java/io/opencensus/tags/TagKey.java105
-rw-r--r--api/src/main/java/io/opencensus/tags/TagMap.java141
2 files changed, 0 insertions, 246 deletions
diff --git a/api/src/main/java/io/opencensus/tags/TagKey.java b/api/src/main/java/io/opencensus/tags/TagKey.java
deleted file mode 100644
index efd3e6e9..00000000
--- a/api/src/main/java/io/opencensus/tags/TagKey.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2017, Google Inc.
- * 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.base.Preconditions.checkArgument;
-import static io.opencensus.tags.TagKey.TagType.TAG_BOOLEAN;
-import static io.opencensus.tags.TagKey.TagType.TAG_LONG;
-import static io.opencensus.tags.TagKey.TagType.TAG_STRING;
-
-import com.google.auto.value.AutoValue;
-import io.opencensus.internal.StringUtil;
-import javax.annotation.concurrent.Immutable;
-
-/**
- * A key to a value stored in a {@link TagMap}.
- *
- * @param <TagValueT> The type of value that can be paired with this {@code TagKey}. {@code TagKey}s
- * can only be instantiated with types {@code String}, {@code Long}, and {@code Boolean}.
- */
-@Immutable
-@AutoValue
-public abstract class TagKey<TagValueT> {
- /** The maximum length for a tag key name. */
- public static final int MAX_LENGTH = StringUtil.MAX_LENGTH;
-
- enum TagType {
- TAG_STRING,
- TAG_LONG,
- TAG_BOOLEAN
- }
-
- TagKey() {}
-
- /**
- * Constructs a {@code TagKey<String>} with the given name.
- *
- * <p>The name 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 name the name of the key.
- * @return a {@code TagKey<String>} with the given name.
- * @throws IllegalArgumentException if the name is not valid.
- */
- public static TagKey<String> createStringKey(String name) {
- checkArgument(StringUtil.isValid(name));
- return new AutoValue_TagKey<String>(name, TAG_STRING);
- }
-
- /**
- * Constructs a {@code TagKey<Long>} with the given name.
- *
- * <p>The name 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 name the name of the key.
- * @throws IllegalArgumentException if the name is not valid.
- */
- // TODO(sebright): Make this public once we support types other than String.
- static TagKey<Long> createLongKey(String name) {
- checkArgument(StringUtil.isValid(name));
- return new AutoValue_TagKey<Long>(name, TAG_LONG);
- }
-
- /**
- * Constructs a {@code TagKey<Boolean>} with the given name.
- *
- * <p>The name 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 name the name of the key.
- * @throws IllegalArgumentException if the name is not valid.
- */
- // TODO(sebright): Make this public once we support types other than String.
- static TagKey<Boolean> createBooleanKey(String name) {
- checkArgument(StringUtil.isValid(name));
- return new AutoValue_TagKey<Boolean>(name, TAG_BOOLEAN);
- }
-
- abstract String getName();
-
- abstract TagType getTagType();
-}
diff --git a/api/src/main/java/io/opencensus/tags/TagMap.java b/api/src/main/java/io/opencensus/tags/TagMap.java
deleted file mode 100644
index 8edbda0d..00000000
--- a/api/src/main/java/io/opencensus/tags/TagMap.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2017, Google Inc.
- * 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.base.Preconditions.checkArgument;
-
-import io.opencensus.internal.StringUtil;
-import io.opencensus.tags.TagKey.TagType;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.concurrent.Immutable;
-
-/**
- * A map from keys to values that can be used to label anything that is associated with a specific
- * operation.
- *
- * <p>For example, {@code TagMap}s can be used to label stats, log messages, or debugging
- * information.
- */
-@Immutable
-public final class TagMap {
- /** The maximum length for a string tag value. */
- public static final int MAX_STRING_LENGTH = StringUtil.MAX_LENGTH;
-
- // The types of the TagKey and value must match for each entry.
- private final Map<TagKey<?>, Object> tags;
-
- TagMap(Map<TagKey<?>, Object> tags) {
- this.tags = Collections.unmodifiableMap(new HashMap<TagKey<?>, Object>(tags));
- }
-
- Map<TagKey<?>, Object> getTags() {
- return tags;
- }
-
- /**
- * Returns a builder based on this {@code TagMap}.
- *
- * @return a builder based on this {@code TagMap}.
- */
- public Builder toBuilder() {
- return new Builder(getTags());
- }
-
- /** Builder for the {@link TagMap} class. */
- public static final class Builder {
- private final Map<TagKey<?>, Object> tags;
-
- private Builder(Map<TagKey<?>, Object> tags) {
- this.tags = new HashMap<TagKey<?>, Object>(tags);
- }
-
- Builder() {
- this.tags = new HashMap<TagKey<?>, Object>();
- }
-
- /**
- * Adds the key/value pair regardless of whether the key is present.
- *
- * @param key the {@code TagKey} which will be set.
- * @param value the value to set for the given key.
- * @return this
- * @throws IllegalArgumentException if either argument is null, the key is the wrong type, or
- * the value contains unprintable characters or is longer than {@link
- * TagMap#MAX_STRING_LENGTH}.
- */
- public Builder set(TagKey<String> key, String value) {
- checkArgument(key.getTagType() == TagType.TAG_STRING);
-
- // TODO(sebright): Consider adding a TagValue class to avoid validating the String every time
- // it is set.
- checkArgument(StringUtil.isValid(value));
- return setInternal(key, value);
- }
-
- /**
- * Adds the key/value pair regardless of whether the key is present.
- *
- * @param key the {@code TagKey} which will be set.
- * @param value the value to set for the given key.
- * @return this
- * @throws IllegalArgumentException if the key is null or the key is the wrong type.
- */
- // TODO(sebright): Make this public once we support types other than String.
- Builder set(TagKey<Long> key, long value) {
- checkArgument(key.getTagType() == TagType.TAG_LONG);
- return setInternal(key, value);
- }
-
- /**
- * Adds the key/value pair regardless of whether the key is present.
- *
- * @param key the {@code TagKey} which will be set.
- * @param value the value to set for the given key.
- * @return this
- * @throws IllegalArgumentException if the key is null or the key is the wrong type.
- */
- // TODO(sebright): Make this public once we support types other than String.
- Builder set(TagKey<Boolean> key, boolean value) {
- checkArgument(key.getTagType() == TagType.TAG_BOOLEAN);
- return setInternal(key, value);
- }
-
- private <TagValueT> Builder setInternal(TagKey<TagValueT> key, TagValueT value) {
- tags.put(key, value);
- return this;
- }
-
- /**
- * Removes the key if it exists.
- *
- * @param key the {@code TagKey} which will be cleared.
- * @return this
- */
- public Builder clear(TagKey<?> key) {
- tags.remove(key);
- return this;
- }
-
- /**
- * Creates a {@code TagMap} from this builder.
- *
- * @return a {@code TagMap} with the same tags as this builder.
- */
- public TagMap build() {
- return new TagMap(new HashMap<TagKey<?>, Object>(tags));
- }
- }
-}