@Test(expected = IllegalArgumentException.class) public void unrecognizedNumberType() { MetricValue.fromNumberValue(new Number() { @Override public int intValue() { fail("May not invoke extraction methods on unrecognized number type."); return 0; } @Override public long longValue() { fail("May not invoke extraction methods on unrecognized number type."); return 0; } @Override public float floatValue() { fail("May not invoke extraction methods on unrecognized number type."); return 0; } @Override public double doubleValue() { fail("May not invoke extraction methods on unrecognized number type."); return 0; } }); }
public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } }
MetricValue implements Comparable<MetricValue>, Serializable { public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } } }
MetricValue implements Comparable<MetricValue>, Serializable { public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } } private  MetricValue(); }
MetricValue implements Comparable<MetricValue>, Serializable { public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } } private  MetricValue(); static MetricValue fromBoolean(boolean b); static MetricValue fromIntValue(long int_value); static MetricValue fromDblValue(double flt_value); static MetricValue fromStrValue(String str_value); static MetricValue fromHistValue(Histogram hist_value); static MetricValue fromNumberValue(Number number); @Override abstract int compareTo(MetricValue o); abstract Optional<Number> value(); abstract Optional<Boolean> asBool(); abstract Optional<String> asString(); Optional<String> stringValue(); Optional<Histogram> histogram(); Boolean getBoolValue(); Long getIntValue(); Double getFltValue(); String getStrValue(); Histogram getHistValue(); abstract String configString(); @Override String toString(); @Override abstract boolean equals(Object o); @Override abstract int hashCode(); boolean isPresent(); boolean isInfinite(); boolean isNaN(); boolean isInfiniteOrNaN(); }
MetricValue implements Comparable<MetricValue>, Serializable { public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } } private  MetricValue(); static MetricValue fromBoolean(boolean b); static MetricValue fromIntValue(long int_value); static MetricValue fromDblValue(double flt_value); static MetricValue fromStrValue(String str_value); static MetricValue fromHistValue(Histogram hist_value); static MetricValue fromNumberValue(Number number); @Override abstract int compareTo(MetricValue o); abstract Optional<Number> value(); abstract Optional<Boolean> asBool(); abstract Optional<String> asString(); Optional<String> stringValue(); Optional<Histogram> histogram(); Boolean getBoolValue(); Long getIntValue(); Double getFltValue(); String getStrValue(); Histogram getHistValue(); abstract String configString(); @Override String toString(); @Override abstract boolean equals(Object o); @Override abstract int hashCode(); boolean isPresent(); boolean isInfinite(); boolean isNaN(); boolean isInfiniteOrNaN(); static final MetricValue TRUE; static final MetricValue FALSE; static final Optional<MetricValue> OPTIONAL_TRUE; static final Optional<MetricValue> OPTIONAL_FALSE; static MetricValue EMPTY; }