@Test public void testCreateLabel() { String degree = NonSI.DEGREE_ANGLE.toString(); assertEquals( "100000 m", GridUtils.createLabel(100000, "m", null)); assertEquals( "100000 m", GridUtils.createLabel(100000.12345, "m", null)); assertEquals( "49.123457 " + degree, GridUtils.createLabel(49.12345678, degree, null)); assertEquals( "100,000 m", GridUtils.createLabel(100000, "m", new GridLabelFormat.Simple("%,1.0f %s"))); assertEquals( "100,000 m", GridUtils .createLabel(100000, "m", new GridLabelFormat.Detailed("###,###", null, null, null))); assertEquals( "100'000 m", GridUtils.createLabel(100000, "m", new GridLabelFormat.Detailed("###,###", null, null, "'"))); assertEquals( "100,000 m", GridUtils.createLabel(100000.123, "m", new GridLabelFormat.Detailed("###,###", null, null, null))); assertEquals( "100'000,12 m", GridUtils.createLabel(100000.123, "m", new GridLabelFormat.Detailed("###,###.##", null, ",", "'"))); }
public static String createLabel(final double value, final String unit, final GridLabelFormat format) { final double zero = 0.000000001; if (format != null) { return format.format(value, unit); } else { if (Math.abs(value - Math.round(value)) < zero) { return String.format("%d %s", Math.round(value), unit); } else if ("m".equals(unit)) { return String.format("%1.0f %s", value, unit); } else if (NonSI.DEGREE_ANGLE.toString().equals(unit)) { return String.format("%1.6f %s", value, unit); } else { return String.format("%f %s", value, unit); } } }
GridUtils { public static String createLabel(final double value, final String unit, final GridLabelFormat format) { final double zero = 0.000000001; if (format != null) { return format.format(value, unit); } else { if (Math.abs(value - Math.round(value)) < zero) { return String.format("%d %s", Math.round(value), unit); } else if ("m".equals(unit)) { return String.format("%1.0f %s", value, unit); } else if (NonSI.DEGREE_ANGLE.toString().equals(unit)) { return String.format("%1.6f %s", value, unit); } else { return String.format("%f %s", value, unit); } } } }
GridUtils { public static String createLabel(final double value, final String unit, final GridLabelFormat format) { final double zero = 0.000000001; if (format != null) { return format.format(value, unit); } else { if (Math.abs(value - Math.round(value)) < zero) { return String.format("%d %s", Math.round(value), unit); } else if ("m".equals(unit)) { return String.format("%1.0f %s", value, unit); } else if (NonSI.DEGREE_ANGLE.toString().equals(unit)) { return String.format("%1.6f %s", value, unit); } else { return String.format("%f %s", value, unit); } } } private  GridUtils(); }
GridUtils { public static String createLabel(final double value, final String unit, final GridLabelFormat format) { final double zero = 0.000000001; if (format != null) { return format.format(value, unit); } else { if (Math.abs(value - Math.round(value)) < zero) { return String.format("%d %s", Math.round(value), unit); } else if ("m".equals(unit)) { return String.format("%1.0f %s", value, unit); } else if (NonSI.DEGREE_ANGLE.toString().equals(unit)) { return String.format("%1.6f %s", value, unit); } else { return String.format("%f %s", value, unit); } } } private  GridUtils(); static Polygon calculateBounds(final MapfishMapContext context); static double calculateFirstLine(
            final ReferencedEnvelope bounds,
            final GridParam layerData,
            final int ordinal); static SimpleFeatureType createGridFeatureType(
            @Nonnull final MapfishMapContext mapContext,
            @Nonnull final Class<? extends Geometry> geomClass); static String createLabel(final double value, final String unit, final GridLabelFormat format); static AffineTransform getWorldToScreenTransform(final MapfishMapContext mapContext); static void topBorderLabel(
            final LabelPositionCollector labels, final GeometryFactory geometryFactory,
            final Polygon rotatedBounds, final String unit, final double x,
            final AffineTransform worldToScreenTransform,
            final MathTransform toLabelProjection,
            final GridLabelFormat labelFormat); static void bottomBorderLabel(
            final LabelPositionCollector labels, final GeometryFactory geometryFactory,
            final Polygon rotatedBounds, final String unit, final double x,
            final AffineTransform worldToScreenTransform,
            final MathTransform toLabelProjection,
            final GridLabelFormat labelFormat); static void rightBorderLabel(
            final LabelPositionCollector labels, final GeometryFactory geometryFactory,
            final Polygon rotatedBounds, final String unit, final double y,
            final AffineTransform worldToScreenTransform,
            final MathTransform toLabelProjection,
            final GridLabelFormat labelFormat); }
GridUtils { public static String createLabel(final double value, final String unit, final GridLabelFormat format) { final double zero = 0.000000001; if (format != null) { return format.format(value, unit); } else { if (Math.abs(value - Math.round(value)) < zero) { return String.format("%d %s", Math.round(value), unit); } else if ("m".equals(unit)) { return String.format("%1.0f %s", value, unit); } else if (NonSI.DEGREE_ANGLE.toString().equals(unit)) { return String.format("%1.6f %s", value, unit); } else { return String.format("%f %s", value, unit); } } } private  GridUtils(); static Polygon calculateBounds(final MapfishMapContext context); static double calculateFirstLine(
            final ReferencedEnvelope bounds,
            final GridParam layerData,
            final int ordinal); static SimpleFeatureType createGridFeatureType(
            @Nonnull final MapfishMapContext mapContext,
            @Nonnull final Class<? extends Geometry> geomClass); static String createLabel(final double value, final String unit, final GridLabelFormat format); static AffineTransform getWorldToScreenTransform(final MapfishMapContext mapContext); static void topBorderLabel(
            final LabelPositionCollector labels, final GeometryFactory geometryFactory,
            final Polygon rotatedBounds, final String unit, final double x,
            final AffineTransform worldToScreenTransform,
            final MathTransform toLabelProjection,
            final GridLabelFormat labelFormat); static void bottomBorderLabel(
            final LabelPositionCollector labels, final GeometryFactory geometryFactory,
            final Polygon rotatedBounds, final String unit, final double x,
            final AffineTransform worldToScreenTransform,
            final MathTransform toLabelProjection,
            final GridLabelFormat labelFormat); static void rightBorderLabel(
            final LabelPositionCollector labels, final GeometryFactory geometryFactory,
            final Polygon rotatedBounds, final String unit, final double y,
            final AffineTransform worldToScreenTransform,
            final MathTransform toLabelProjection,
            final GridLabelFormat labelFormat);  }