private static Object valueAsString(Value value) { switch (value.getType()) { case STRING: return value.stringValue(); case LONG: return value.longValue(); case DOUBLE: return value.doubleValue(); default: throw new IllegalStateException("simplemetrics impl is out of sync with itself, please file a ticket."); } }
/** * Set a named dimension to a string value. * * @param dimensionName the name of the dimension to set * @param dimensionValue to value for the given dimension * @return this, to facilitate chaining */ public PointBuilder set(String dimensionName, String dimensionValue) { return set(dimensionName, Value.of(dimensionValue)); }
/** * Set a named dimension to a floating point value. * * @param dimensionName the name of the dimension to set * @param dimensionValue to value for the given dimension * @return this, to facilitate chaining */ public PointBuilder set(String dimensionName, double dimensionValue) { return set(dimensionName, Value.of(dimensionValue)); }
private void serializeSingleDimension(StringBuilder buffer, final String dimensionName, Value dimensionValue) { buffer.append('"'); escape(dimensionName, buffer); buffer.append("\": "); switch (dimensionValue.getType()) { case LONG: buffer.append(Long.toString(dimensionValue.longValue())); break; case DOUBLE: buffer.append(Double.toString(dimensionValue.doubleValue())); break; case STRING: buffer.append('"'); escape(dimensionValue.stringValue(), buffer); buffer.append('"'); break; default: buffer.append("\"Unknown type for this dimension, this is a bug.\""); break; } }
/** * Set a named dimension to an integer value. * * @param dimensionName the name of the dimension to set * @param dimensionValue to value for the given dimension * @return this, to facilitate chaining */ public PointBuilder set(String dimensionName, long dimensionValue) { return set(dimensionName, Value.of(dimensionValue)); }
private static Tuple2<String[], Value[]> buildParameters(Map<String, ?> properties) { String[] dimensions = properties.keySet().toArray(new String[0]); Arrays.sort(dimensions); Value[] location = new Value[dimensions.length]; for (int i = 0; i < dimensions.length; ++i) { location[i] = Value.of(String.valueOf(properties.get(dimensions[i]))); } return new Tuple2<>(dimensions, location); }