com.lightstep.tracer.metrics.ValueAdapter Maven / Gradle / Ivy
package com.lightstep.tracer.metrics;
import java.util.HashMap;
import com.lightstep.tracer.grpc.MetricPoint;
abstract class ValueAdapter {
private static final HashMap,ValueAdapter>> instances = new HashMap<>();
static final ValueAdapter LONG = new ValueAdapter(Long.class) {
@Override
long toLong(final Long value) {
return value;
}
@Override
Long toT(final long value) {
return value;
}
@Override
Long diff(final long current, final long previous) {
return current - previous;
}
@Override
void setValue(final MetricPoint.Builder builder, final Long value) {
builder.setUint64Value(value);
}
};
static final ValueAdapter DOUBLE = new ValueAdapter(Double.class) {
@Override
long toLong(final Double value) {
return Double.doubleToLongBits(value);
}
@Override
Double toT(final long value) {
return Double.longBitsToDouble(value);
}
@Override
Double diff(final long current, final long previous) {
return toT(current) - toT(previous);
}
@Override
void setValue(final MetricPoint.Builder builder, final Double value) {
builder.setDoubleValue(value);
}
};
abstract V diff(long current, long previous);
abstract long toLong(V value);
abstract V toT(long value);
abstract void setValue(MetricPoint.Builder builder, V value);
private ValueAdapter(final Class type) {
instances.put(type, this);
}
@SuppressWarnings("unchecked")
static ValueAdapter get(final Class type) {
return (ValueAdapter)instances.get(type);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy