aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java/io/opencensus
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2018-08-27 15:40:12 -0700
committerGitHub <noreply@github.com>2018-08-27 15:40:12 -0700
commit8901e4eb583785efaa2c3adea882d850662d93fc (patch)
tree313ebea77d5fabad42082dd059acd0f418a03242 /api/src/main/java/io/opencensus
parent217a1e86dd1082296b7278253f5f51633191fb06 (diff)
downloadopencensus-java-8901e4eb583785efaa2c3adea882d850662d93fc.tar.gz
Add get/from{Byte} methods on TraceOptions and deprecate get/from{Bytes}. (#1392)
* Add get/from{Byte} methods on TraceOptions and deprecate get/from{Bytes}. * Update changelog.
Diffstat (limited to 'api/src/main/java/io/opencensus')
-rw-r--r--api/src/main/java/io/opencensus/trace/TraceOptions.java36
1 files changed, 32 insertions, 4 deletions
diff --git a/api/src/main/java/io/opencensus/trace/TraceOptions.java b/api/src/main/java/io/opencensus/trace/TraceOptions.java
index f34ba190..86379f1e 100644
--- a/api/src/main/java/io/opencensus/trace/TraceOptions.java
+++ b/api/src/main/java/io/opencensus/trace/TraceOptions.java
@@ -48,7 +48,7 @@ public final class TraceOptions {
*
* @since 0.5
*/
- public static final TraceOptions DEFAULT = new TraceOptions(DEFAULT_OPTIONS);
+ public static final TraceOptions DEFAULT = fromByte(DEFAULT_OPTIONS);
// The set of enabled features is determined by all the enabled bits.
private final byte options;
@@ -72,13 +72,15 @@ public final class TraceOptions {
* @throws NullPointerException if {@code buffer} is null.
* @throws IllegalArgumentException if {@code buffer.length} is not {@link TraceOptions#SIZE}.
* @since 0.5
+ * @deprecated use {@link #fromByte(byte)}.
*/
+ @Deprecated
public static TraceOptions fromBytes(byte[] buffer) {
Utils.checkNotNull(buffer, "buffer");
Utils.checkArgument(
buffer.length == SIZE,
String.format("Invalid size: expected %s, got %s", SIZE, buffer.length));
- return new TraceOptions(buffer[0]);
+ return fromByte(buffer[0]);
}
/**
@@ -93,10 +95,34 @@ public final class TraceOptions {
* @throws IndexOutOfBoundsException if {@code srcOffset+TraceOptions.SIZE} is greater than {@code
* src.length}.
* @since 0.5
+ * @deprecated use {@link #fromByte(byte)}.
*/
+ @Deprecated
public static TraceOptions fromBytes(byte[] src, int srcOffset) {
Utils.checkIndex(srcOffset, src.length);
- return new TraceOptions(src[srcOffset]);
+ return fromByte(src[srcOffset]);
+ }
+
+ /**
+ * Returns a {@code TraceOptions} whose representation is {@code src}.
+ *
+ * @param src the byte representation of the {@code TraceOptions}.
+ * @return a {@code TraceOptions} whose representation is {@code src}.
+ * @since 0.16
+ */
+ public static TraceOptions fromByte(byte src) {
+ // TODO(bdrutu): OPTIMIZATION: Cache all the 256 possible objects and return from the cache.
+ return new TraceOptions(src);
+ }
+
+ /**
+ * Returns the one byte representation of the {@code TraceOptions}.
+ *
+ * @return the one byte representation of the {@code TraceOptions}.
+ * @since 0.16
+ */
+ public byte getByte() {
+ return options;
}
/**
@@ -104,7 +130,9 @@ public final class TraceOptions {
*
* @return the 1-byte array representation of the {@code TraceOptions}.
* @since 0.5
+ * @deprecated use {@link #getByte()}.
*/
+ @Deprecated
public byte[] getBytes() {
byte[] bytes = new byte[SIZE];
bytes[0] = options;
@@ -237,7 +265,7 @@ public final class TraceOptions {
* @since 0.5
*/
public TraceOptions build() {
- return new TraceOptions(options);
+ return fromByte(options);
}
}