@Test public void testMandatedPrecision() { Display display = newDisplay(Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE, "", NumberFormats.format(3), Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE); Display displayInt = newDisplay(Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE, "", NumberFormats.format(0), Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE); ValueFormat f = new SimpleValueFormat(3); f.setNumberFormat(NumberFormats.format(2)); assertThat(f.format(newVDouble(1234.5678, display)), equalTo("1234.57")); assertThat(f.format(newVIntArray(new ArrayInt(1, 2, 3), alarmNone(), timeNow(), displayInt)), equalTo("[1.00, 2.00, 3.00]")); assertThat(f.format(newVIntArray(new ArrayInt(1), alarmNone(), timeNow(), displayInt)), equalTo("[1.00]")); assertThat(f.format(newVIntArray(new ArrayInt(1, 2, 3, 4, 5), alarmNone(), timeNow(), displayInt)), equalTo("[1.00, 2.00, 3.00, ...]")); assertThat(f.format(newVFloatArray(new ArrayFloat(new float[] {1, 2, 3}), alarmNone(), timeNow(), display)), equalTo("[1.00, 2.00, 3.00]")); assertThat(f.format(newVFloatArray(new ArrayFloat(new float[] {1}), alarmNone(), timeNow(), display)), equalTo("[1.00]")); assertThat(f.format(newVFloatArray(new ArrayFloat(new float[] {1, 2, 3, 4, 5}), alarmNone(), timeNow(), display)), equalTo("[1.00, 2.00, 3.00, ...]")); assertThat(f.format(newVDoubleArray(new ArrayDouble(1, 2, 3), alarmNone(), timeNow(), display)), equalTo("[1.00, 2.00, 3.00]")); assertThat(f.format(newVDoubleArray(new ArrayDouble(1), alarmNone(), timeNow(), display)), equalTo("[1.00]")); assertThat(f.format(newVDoubleArray(new ArrayDouble(1, 2, 3, 4, 5), alarmNone(), timeNow(), display)), equalTo("[1.00, 2.00, 3.00, ...]")); assertThat(f.format(newVStringArray(Arrays.asList("A", "B", "C"), alarmNone(), timeNow())), equalTo("[A, B, C]")); assertThat(f.format(newVStringArray(Arrays.asList("A"), alarmNone(), timeNow())), equalTo("[A]")); assertThat(f.format(newVStringArray(Arrays.asList("A", "B", "C", "D", "E"), alarmNone(), timeNow())), equalTo("[A, B, C, ...]")); }
@Override protected StringBuffer format(Scalar scalar, StringBuffer toAppendTo, FieldPosition pos) { if (scalar == null || scalar.getValue() == null) { return toAppendTo; } if (scalar instanceof Display && nf(scalar) != null) { NumberFormat f = nf(scalar); return f.format(scalar.getValue(), toAppendTo, pos); } toAppendTo.append(scalar.getValue()); return toAppendTo; }
SimpleValueFormat extends ValueFormat { @Override protected StringBuffer format(Scalar scalar, StringBuffer toAppendTo, FieldPosition pos) { if (scalar == null || scalar.getValue() == null) { return toAppendTo; } if (scalar instanceof Display && nf(scalar) != null) { NumberFormat f = nf(scalar); return f.format(scalar.getValue(), toAppendTo, pos); } toAppendTo.append(scalar.getValue()); return toAppendTo; } }
SimpleValueFormat extends ValueFormat { @Override protected StringBuffer format(Scalar scalar, StringBuffer toAppendTo, FieldPosition pos) { if (scalar == null || scalar.getValue() == null) { return toAppendTo; } if (scalar instanceof Display && nf(scalar) != null) { NumberFormat f = nf(scalar); return f.format(scalar.getValue(), toAppendTo, pos); } toAppendTo.append(scalar.getValue()); return toAppendTo; } SimpleValueFormat(int maxElements); }
SimpleValueFormat extends ValueFormat { @Override protected StringBuffer format(Scalar scalar, StringBuffer toAppendTo, FieldPosition pos) { if (scalar == null || scalar.getValue() == null) { return toAppendTo; } if (scalar instanceof Display && nf(scalar) != null) { NumberFormat f = nf(scalar); return f.format(scalar.getValue(), toAppendTo, pos); } toAppendTo.append(scalar.getValue()); return toAppendTo; } SimpleValueFormat(int maxElements);  }
SimpleValueFormat extends ValueFormat { @Override protected StringBuffer format(Scalar scalar, StringBuffer toAppendTo, FieldPosition pos) { if (scalar == null || scalar.getValue() == null) { return toAppendTo; } if (scalar instanceof Display && nf(scalar) != null) { NumberFormat f = nf(scalar); return f.format(scalar.getValue(), toAppendTo, pos); } toAppendTo.append(scalar.getValue()); return toAppendTo; } SimpleValueFormat(int maxElements);   }