-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
api/all/src/main/java/io/opentelemetry/api/common/ValueBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.api.common; | ||
|
||
public interface ValueBuilder { | ||
|
||
default ValueBuilder put(String key, String value) { | ||
put(key, Value.of(value)); | ||
return this; | ||
} | ||
|
||
default ValueBuilder put(String key, long value) { | ||
put(key, Value.of(value)); | ||
return this; | ||
} | ||
|
||
default ValueBuilder put(String key, double value) { | ||
put(key, Value.of(value)); | ||
return this; | ||
} | ||
|
||
default ValueBuilder put(String key, boolean value) { | ||
put(key, Value.of(value)); | ||
return this; | ||
} | ||
|
||
ValueBuilder put(String key, Value<?> value); | ||
|
||
Value<?> build(); | ||
} |
25 changes: 25 additions & 0 deletions
25
api/all/src/main/java/io/opentelemetry/api/common/ValueBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.api.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
class ValueBuilderImpl implements ValueBuilder { | ||
|
||
private final List<KeyValue> keyValues = new ArrayList<>(); | ||
|
||
@Override | ||
public ValueBuilder put(String key, Value<?> value) { | ||
keyValues.add(KeyValue.of(key, value)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Value<?> build() { | ||
return Value.of(keyValues.toArray(new KeyValue[0])); | ||
} | ||
} |