Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
- fixing codereview influxdata#521
Browse files Browse the repository at this point in the history
  • Loading branch information
rhajek committed Sep 21, 2018
1 parent 56fcc8f commit fd729f6
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/main/java/org/influxdb/dto/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,25 +320,25 @@ public String lineProtocol() {
return lineProtocol(null);
}

/**
* Calculate the lineprotocol entry for a single point, using a specific {@link TimeUnit} for the timestamp.
* @param precision the time precision unit for this point
* @return the String without newLine
*/
public String lineProtocol(final TimeUnit precision) {
final StringBuilder sb = CACHED_STRINGBUILDERS.get();
sb.setLength(0);

escapeKey(sb, measurement);
concatenatedTags(sb);
concatenatedFields(sb);
if (precision != null) {
formatedTime(sb, precision);
} else {
formatedTime(sb);
}
return sb.toString();
}
/**
* Calculate the lineprotocol entry for a single point, using a specific {@link TimeUnit} for the timestamp.
* @param precision the time precision unit for this point
* @return the String without newLine
*/
public String lineProtocol(final TimeUnit precision) {

// setLength(0) is used for reusing cached StringBuilder instance per thread
// it reduces GC activity and performs better then new StringBuilder()
StringBuilder sb = CACHED_STRINGBUILDERS.get();
sb.setLength(0);

escapeKey(sb, measurement);
concatenatedTags(sb);
concatenatedFields(sb);
formatedTime(sb, precision);

return sb.toString();
}

private void concatenatedTags(final StringBuilder sb) {
for (Entry<String, String> tag : this.tags.entrySet()) {
Expand Down Expand Up @@ -408,18 +408,14 @@ static void escapeField(final StringBuilder sb, final String field) {
}
}

private void formatedTime(final StringBuilder sb) {
if (this.time == null || this.precision == null) {
private void formatedTime(final StringBuilder sb, final TimeUnit precision) {
if (this.time == null) {
return;
}
sb.append(' ').append(TimeUnit.NANOSECONDS.convert(this.time, this.precision));
}

private StringBuilder formatedTime(final StringBuilder sb, final TimeUnit precision) {
if (this.time == null || this.precision == null) {
return sb;
if (precision == null) {
sb.append(" ").append(TimeUnit.NANOSECONDS.convert(this.time, this.precision));
return;
}
sb.append(" ").append(precision.convert(this.time, this.precision));
return sb;
}
}

0 comments on commit fd729f6

Please sign in to comment.