@Test void time() { Point point = Point.measurement("h2o") .addTag("location", "europe") .addField("level", 2) .time(123L, WritePrecision.S); Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe level=2i 123"); }
@Nonnull public Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision) { if (time == null) { return time((Long) null, precision); } BigInteger convertedTime; BigInteger nanos = BigInteger.valueOf(time.getEpochSecond()) .multiply(NANOS_PER_SECOND) .add(BigInteger.valueOf(time.getNano())); switch (precision) { case NS: convertedTime = nanos; break; case US: convertedTime = nanos.divide(MICRO_PER_NANOS); break; case MS: convertedTime = nanos.divide(MILLIS_PER_NANOS); break; case S: convertedTime = nanos.divide(SECONDS_PER_NANOS); break; default: throw new IllegalStateException("Unsupported precision: " + precision); } return time(convertedTime, precision); }
Point { @Nonnull public Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision) { if (time == null) { return time((Long) null, precision); } BigInteger convertedTime; BigInteger nanos = BigInteger.valueOf(time.getEpochSecond()) .multiply(NANOS_PER_SECOND) .add(BigInteger.valueOf(time.getNano())); switch (precision) { case NS: convertedTime = nanos; break; case US: convertedTime = nanos.divide(MICRO_PER_NANOS); break; case MS: convertedTime = nanos.divide(MILLIS_PER_NANOS); break; case S: convertedTime = nanos.divide(SECONDS_PER_NANOS); break; default: throw new IllegalStateException("Unsupported precision: " + precision); } return time(convertedTime, precision); } }
Point { @Nonnull public Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision) { if (time == null) { return time((Long) null, precision); } BigInteger convertedTime; BigInteger nanos = BigInteger.valueOf(time.getEpochSecond()) .multiply(NANOS_PER_SECOND) .add(BigInteger.valueOf(time.getNano())); switch (precision) { case NS: convertedTime = nanos; break; case US: convertedTime = nanos.divide(MICRO_PER_NANOS); break; case MS: convertedTime = nanos.divide(MILLIS_PER_NANOS); break; case S: convertedTime = nanos.divide(SECONDS_PER_NANOS); break; default: throw new IllegalStateException("Unsupported precision: " + precision); } return time(convertedTime, precision); } Point(@Nonnull final String measurementName); }
Point { @Nonnull public Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision) { if (time == null) { return time((Long) null, precision); } BigInteger convertedTime; BigInteger nanos = BigInteger.valueOf(time.getEpochSecond()) .multiply(NANOS_PER_SECOND) .add(BigInteger.valueOf(time.getNano())); switch (precision) { case NS: convertedTime = nanos; break; case US: convertedTime = nanos.divide(MICRO_PER_NANOS); break; case MS: convertedTime = nanos.divide(MILLIS_PER_NANOS); break; case S: convertedTime = nanos.divide(SECONDS_PER_NANOS); break; default: throw new IllegalStateException("Unsupported precision: " + precision); } return time(convertedTime, precision); } Point(@Nonnull final String measurementName); @Nonnull static Point measurement(@Nonnull final String measurementName); @Nonnull Point addTag(@Nonnull final String key, @Nullable final String value); @Nonnull Point addTags(@Nonnull final Map<String, String> tagsToAdd); @Nonnull Point addField(@Nonnull final String field, final boolean value); Point addField(@Nonnull final String field, final long value); @Nonnull Point addField(@Nonnull final String field, final double value); @Nonnull Point addField(@Nonnull final String field, @Nullable final Number value); @Nonnull Point addField(@Nonnull final String field, @Nullable final String value); @Nonnull Point addFields(@Nonnull final Map<String, Object> fieldsToAdd); @Nonnull Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision); @Nonnull Point time(@Nullable final Number time, @Nonnull final WritePrecision precision); @Nonnull Point time(@Nullable final Long time, @Nonnull final WritePrecision precision); @Nonnull WritePrecision getPrecision(); boolean hasFields(); @Nonnull String toLineProtocol(); @Nonnull String toLineProtocol(@Nullable final PointSettings pointSettings); }
Point { @Nonnull public Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision) { if (time == null) { return time((Long) null, precision); } BigInteger convertedTime; BigInteger nanos = BigInteger.valueOf(time.getEpochSecond()) .multiply(NANOS_PER_SECOND) .add(BigInteger.valueOf(time.getNano())); switch (precision) { case NS: convertedTime = nanos; break; case US: convertedTime = nanos.divide(MICRO_PER_NANOS); break; case MS: convertedTime = nanos.divide(MILLIS_PER_NANOS); break; case S: convertedTime = nanos.divide(SECONDS_PER_NANOS); break; default: throw new IllegalStateException("Unsupported precision: " + precision); } return time(convertedTime, precision); } Point(@Nonnull final String measurementName); @Nonnull static Point measurement(@Nonnull final String measurementName); @Nonnull Point addTag(@Nonnull final String key, @Nullable final String value); @Nonnull Point addTags(@Nonnull final Map<String, String> tagsToAdd); @Nonnull Point addField(@Nonnull final String field, final boolean value); Point addField(@Nonnull final String field, final long value); @Nonnull Point addField(@Nonnull final String field, final double value); @Nonnull Point addField(@Nonnull final String field, @Nullable final Number value); @Nonnull Point addField(@Nonnull final String field, @Nullable final String value); @Nonnull Point addFields(@Nonnull final Map<String, Object> fieldsToAdd); @Nonnull Point time(@Nullable final Instant time, @Nonnull final WritePrecision precision); @Nonnull Point time(@Nullable final Number time, @Nonnull final WritePrecision precision); @Nonnull Point time(@Nullable final Long time, @Nonnull final WritePrecision precision); @Nonnull WritePrecision getPrecision(); boolean hasFields(); @Nonnull String toLineProtocol(); @Nonnull String toLineProtocol(@Nullable final PointSettings pointSettings);  }