diff options
author | Mayur Kale <mayurkale@google.com> | 2018-10-10 12:31:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 12:31:51 -0700 |
commit | 9c4df3dbe085a70850cc466849d33d90ffa846f4 (patch) | |
tree | f36c626bae1ec48ac2209be310d4e30d929db7b6 /api/src/main/java/io/opencensus | |
parent | e3b2074a090836985307123517fd2d361c4b503c (diff) | |
download | opencensus-java-9c4df3dbe085a70850cc466849d33d90ffa846f4.tar.gz |
Metrics/TimeSeries: Add createWithOnePoint method to accept only one … (#1486)
* Metrics/TimeSeries: Add createWithOnePoint method to accept only one point
* Fix reviews
* Minor Fix
Diffstat (limited to 'api/src/main/java/io/opencensus')
-rw-r--r-- | api/src/main/java/io/opencensus/metrics/export/TimeSeries.java | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/api/src/main/java/io/opencensus/metrics/export/TimeSeries.java b/api/src/main/java/io/opencensus/metrics/export/TimeSeries.java index 959f55ba..bfaeae98 100644 --- a/api/src/main/java/io/opencensus/metrics/export/TimeSeries.java +++ b/api/src/main/java/io/opencensus/metrics/export/TimeSeries.java @@ -52,14 +52,45 @@ public abstract class TimeSeries { */ public static TimeSeries create( List<LabelValue> labelValues, List<Point> points, @Nullable Timestamp startTimestamp) { + Utils.checkNotNull(points, "points"); + Utils.checkListElementNotNull(points, "point"); + return createInternal( + labelValues, Collections.unmodifiableList(new ArrayList<Point>(points)), startTimestamp); + } + + /** + * Creates a {@link TimeSeries}. + * + * @param labelValues the {@code LabelValue}s that uniquely identify this {@code TimeSeries}. + * @param point the single data {@code Point} of this {@code TimeSeries}. + * @param startTimestamp the start {@code Timestamp} of this {@code TimeSeries}. Must be non-null + * for cumulative {@code Point}s. + * @return a {@code TimeSeries}. + * @since 0.17 + */ + public static TimeSeries createWithOnePoint( + List<LabelValue> labelValues, Point point, @Nullable Timestamp startTimestamp) { + Utils.checkNotNull(point, "point"); + return createInternal(labelValues, Collections.singletonList(point), startTimestamp); + } + + /** + * Creates a {@link TimeSeries}. + * + * @param labelValues the {@code LabelValue}s that uniquely identify this {@code TimeSeries}. + * @param points the data {@code Point}s of this {@code TimeSeries}. + * @param startTimestamp the start {@code Timestamp} of this {@code TimeSeries}. Must be non-null + * for cumulative {@code Point}s. + * @return a {@code TimeSeries}. + */ + private static TimeSeries createInternal( + List<LabelValue> labelValues, List<Point> points, @Nullable Timestamp startTimestamp) { // Fail fast on null lists to prevent NullPointerException when copying the lists. Utils.checkNotNull(labelValues, "labelValues"); - Utils.checkNotNull(points, "points"); Utils.checkListElementNotNull(labelValues, "labelValue"); - Utils.checkListElementNotNull(points, "point"); return new AutoValue_TimeSeries( Collections.unmodifiableList(new ArrayList<LabelValue>(labelValues)), - Collections.unmodifiableList(new ArrayList<Point>(points)), + points, startTimestamp); } |