public void testStringConverter_convertError() { try { Floats.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
@GwtIncompatible // SerializableTester public void testStringConverterSerialization() { SerializableTester.reserializeAndAssert(Floats.stringConverter()); }
public void testStringConverter_nullConversions() { assertNull(Floats.stringConverter().convert(null)); assertNull(Floats.stringConverter().reverse().convert(null)); }
@GwtIncompatible // NullPointerTester public void testStringConverter_nullPointerTester() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods(Floats.stringConverter()); }
@GwtIncompatible // Float.toString returns different value in GWT. public void testStringConverter_reverse() { Converter<String, Float> converter = Floats.stringConverter(); assertEquals("1.0", converter.reverse().convert(1.0f)); assertEquals("0.0", converter.reverse().convert(0.0f)); assertEquals("-1.0", converter.reverse().convert(-1.0f)); assertEquals("1000000.0", converter.reverse().convert(1e6f)); assertEquals("1.0E-6", converter.reverse().convert(1e-6f)); }
@GwtIncompatible // Float.toString returns different value in GWT. public void testStringConverter_convert() { Converter<String, Float> converter = Floats.stringConverter(); assertEquals((Float) 1.0f, converter.convert("1.0")); assertEquals((Float) 0.0f, converter.convert("0.0")); assertEquals((Float) (-1.0f), converter.convert("-1.0")); assertEquals((Float) 1.0f, converter.convert("1")); assertEquals((Float) 0.0f, converter.convert("0")); assertEquals((Float) (-1.0f), converter.convert("-1")); assertEquals((Float) 1e6f, converter.convert("1e6")); assertEquals((Float) 1e-6f, converter.convert("1e-6")); }
/** * Determine the primitive type's converter * @param type the primitive type * @return the primitive type's converter or null */ public static Converter<String, ?> determinePrimitiveConverter(Type type){ if (String.class.equals(type)){ return StringConverter.INSTANCE; } else if (Boolean.class.equals(type) || boolean.class.equals(type)){ return BooleanConverter.INSTANCE; } else if (Integer.class.equals(type) || int.class.equals(type)){ return Ints.stringConverter(); } else if (Long.class.equals(type) || long.class.equals(type)) { return Longs.stringConverter(); } else if (Short.class.equals(type) || short.class.equals(type)){ return Shorts.stringConverter(); } else if (Float.class.equals(type) || float.class.equals(type)){ return Floats.stringConverter(); } else if (Double.class.equals(type) || double.class.equals(type)){ return Doubles.stringConverter(); } return null; }
/** * Get stroke from the provided style. * @param style style object * @return stroke */ public static Stroke strokeOf(AttributeSet style) { float strokeWidth = style.getFloat(Styles.STROKE_WIDTH, 1f); String dashes = style.getString(Styles.STROKE_DASHES, null); if (!Strings.isNullOrEmpty(dashes)) { Iterable<String> sDashes = Splitter.on(",").trimResults().split(dashes); try { Iterable<Float> fDashes = Floats.stringConverter().convertAll(sDashes); float[] fArr = new float[Iterables.size(fDashes)]; int i = 0; for (Float f : fDashes) { fArr[i] = f == null ? 0f : f; i++; } return new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, fArr, 0.0f); } catch (NumberFormatException x) { Logger.getLogger(Styles.class.getName()).log(Level.WARNING, "Invalid dash pattern: "+dashes, x); } } return new BasicStroke(strokeWidth); }
public void testStringConverter_convertError() { try { Floats.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
@GwtIncompatible // SerializableTester public void testStringConverterSerialization() { SerializableTester.reserializeAndAssert(Floats.stringConverter()); }
public void testStringConverter_nullConversions() { assertNull(Floats.stringConverter().convert(null)); assertNull(Floats.stringConverter().reverse().convert(null)); }
@GwtIncompatible // NullPointerTester public void testStringConverter_nullPointerTester() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods(Floats.stringConverter()); }
@GwtIncompatible // Float.toString returns different value in GWT. public void testStringConverter_reverse() { Converter<String, Float> converter = Floats.stringConverter(); assertEquals("1.0", converter.reverse().convert(1.0f)); assertEquals("0.0", converter.reverse().convert(0.0f)); assertEquals("-1.0", converter.reverse().convert(-1.0f)); assertEquals("1000000.0", converter.reverse().convert(1e6f)); assertEquals("1.0E-6", converter.reverse().convert(1e-6f)); }
@GwtIncompatible // Float.toString returns different value in GWT. public void testStringConverter_convert() { Converter<String, Float> converter = Floats.stringConverter(); assertEquals((Float) 1.0f, converter.convert("1.0")); assertEquals((Float) 0.0f, converter.convert("0.0")); assertEquals((Float) (-1.0f), converter.convert("-1.0")); assertEquals((Float) 1.0f, converter.convert("1")); assertEquals((Float) 0.0f, converter.convert("0")); assertEquals((Float) (-1.0f), converter.convert("-1")); assertEquals((Float) 1e6f, converter.convert("1e6")); assertEquals((Float) 1e-6f, converter.convert("1e-6")); }