Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java @ 8996:fb9430250899
Work on uinfo
author | gernotbelger |
---|---|
date | Thu, 12 Apr 2018 19:13:39 +0200 |
parents | 322b0e6298ea |
children | 7134a4c7d1b6 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Thu Apr 12 19:11:11 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Thu Apr 12 19:13:39 2018 +0200 @@ -18,7 +18,6 @@ import org.dive4elements.artifacts.CallMeta; import org.dive4elements.river.artifacts.resources.Resources; - /** Helper to access static i18n Formatters. */ public final class Formatter { @@ -29,18 +28,16 @@ // WATERLEVEL FORMATTER CONSTANTS public static final int WATERLEVEL_KM_MIN_DIGITS = 3; public static final int WATERLEVEL_KM_MAX_DIGITS = 3; - public static final int WATERLEVEL_W_MIN_DIGITS = 0; - public static final int WATERLEVEL_W_MAX_DIGITS = 2; - public static final int WATERLEVEL_Q_MIN_DIGITS = 0; - public static final int WATERLEVEL_Q_MAX_DIGITS = 2; - + public static final int WATERLEVEL_W_MIN_DIGITS = 0; + public static final int WATERLEVEL_W_MAX_DIGITS = 2; + public static final int WATERLEVEL_Q_MIN_DIGITS = 0; + public static final int WATERLEVEL_Q_MAX_DIGITS = 2; // COMPUTED DISCHARGE CURVE FORMATTER CONSTANTS - public static final int COMPUTED_DISCHARGE_W_MIN_DIGITS = 2; - public static final int COMPUTED_DISCHARGE_W_MAX_DIGITS = 2; - public static final int COMPUTED_DISCHARGE_Q_MIN_DIGITS = 0; - public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 2; - + public static final int COMPUTED_DISCHARGE_W_MIN_DIGITS = 2; + public static final int COMPUTED_DISCHARGE_W_MAX_DIGITS = 2; + public static final int COMPUTED_DISCHARGE_Q_MIN_DIGITS = 0; + public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 2; // HISTORICAL DISCHARGE CURVE FORMATTER CONSTANTS public static final int HISTORICAL_DISCHARGE_W_MIN_DIGITS = 0; @@ -48,7 +45,6 @@ public static final int HISTORICAL_DISCHARGE_Q_MIN_DIGITS = 0; public static final int HISTORICAL_DISCHARGE_Q_MAX_DIGITS = 2; - // DURATION CURVE FORMATTER CONSTANTS public static final int DURATION_W_MIN_DIGITS = 0; public static final int DURATION_W_MAX_DIGITS = 2; @@ -57,36 +53,34 @@ public static final int DURATION_D_MIN_DIGITS = 0; public static final int DURATION_D_MAX_DIGITS = 0; - // FLOW VELOCITY FORMATTER CONSTANTS - public static final int FLOW_VELOCITY_KM_MIN_DIGITS = 3; - public static final int FLOW_VELOCITY_KM_MAX_DIGITS = 3; + public static final int FLOW_VELOCITY_KM_MIN_DIGITS = 3; + public static final int FLOW_VELOCITY_KM_MAX_DIGITS = 3; public static final int FLOW_VELOCITY_VALUES_MIN_DIGITS = 2; public static final int FLOW_VELOCITY_VALUES_MAX_DIGITS = 2; - public static final int FLOW_VELOCITY_Q_MIN_DIGITS = 0; - public static final int FLOW_VELOCITY_Q_MAX_DIGITS = 2; - + public static final int FLOW_VELOCITY_Q_MIN_DIGITS = 0; + public static final int FLOW_VELOCITY_Q_MAX_DIGITS = 2; // MIDDLE BED HEIGHT FORMATTER CONSTANTS - public static final int MIDDLE_BED_HEIGHT_KM_MIN_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_KM_MAX_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS = 2; - public static final int MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS = 2; + public static final int MIDDLE_BED_HEIGHT_KM_MIN_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_KM_MAX_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS = 2; + public static final int MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS = 2; public static final int MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS = 0; public static final int MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS = 0; - public static final int MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS = 3; - public static final int MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS = 3; + public static final int MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS = 3; public static final int FIX_DELTA_W_KM_MIN_DIGITS = 3; public static final int FIX_DELTA_W_KM_MAX_DIGITS = 3; public static final int FIX_DELTA_W_DELTA_W_MIN_DIGITS = 3; public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3; - public static final int FIX_DELTA_W_DELTA_Q_MIN_DIGITS = 0; - public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2; + public static final int FIX_DELTA_W_DELTA_Q_MIN_DIGITS = 0; + public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2; public static final int VARIANCE_MIN_DIGITS = 3; public static final int VARIANCE_MAX_DIGITS = 3; @@ -94,26 +88,30 @@ // SQ Relation public static final int SQ_RELATION_KM_MIN_DIGITS = 2; public static final int SQ_RELATION_KM_MAX_DIGITS = 2; - public static final int SQ_RELATION_A_MAX_DIGITS = 2; - public static final int SQ_RELATION_A_MIN_DIGITS = 2; - public static final int SQ_RELATION_B_MAX_DIGITS = 3; - public static final int SQ_RELATION_B_MIN_DIGITS = 3; + public static final int SQ_RELATION_A_MAX_DIGITS = 2; + public static final int SQ_RELATION_A_MIN_DIGITS = 2; + public static final int SQ_RELATION_B_MAX_DIGITS = 3; + public static final int SQ_RELATION_B_MIN_DIGITS = 3; // OTHER - public static final int CSV_DIAGRAM_DATA_MAX_DIGITS = 3; - public static final int CSV_DIAGRAM_DATA_MIN_DIGITS = 3; + public static final int CSV_DIAGRAM_DATA_MAX_DIGITS = 3; + public static final int CSV_DIAGRAM_DATA_MIN_DIGITS = 3; /** * Creates a localized NumberFormatter with given range of decimal digits. - * @param m CallMeta to find the locale. - * @param min minimum number of decimal ("fraction") digits. - * @param max maximum number of decimal ("fraction") digits. + * + * @param m + * CallMeta to find the locale. + * @param min + * minimum number of decimal ("fraction") digits. + * @param max + * maximum number of decimal ("fraction") digits. * @return A NumberFormat. Use #format(NUMBER) to get String representation * of NUMBER. */ - public static NumberFormat getFormatter(final CallMeta m, final int min, final int max){ - final Locale locale = Resources.getLocale(m); - final NumberFormat nf = NumberFormat.getInstance(locale); + public static NumberFormat getFormatter(final CallMeta m, final int min, final int max) { + final Locale locale = Resources.getLocale(m); + final NumberFormat nf = NumberFormat.getInstance(locale); nf.setMaximumFractionDigits(max); nf.setMinimumFractionDigits(min); @@ -121,15 +119,15 @@ return nf; } - public static NumberFormat getFormatter(final CallContext c, final int min, final int max){ + public static NumberFormat getFormatter(final CallContext c, final int min, final int max) { return getFormatter(c.getMeta(), min, max); } - /** * Returns a number formatter with no max or min digits set. * - * @param c The CallContext. + * @param c + * The CallContext. * * @return a number formatter. */ @@ -144,7 +142,7 @@ public static NumberFormat getEngFormatter(final CallContext c) { final NumberFormat nf = getRawFormatter(c); if (nf instanceof DecimalFormat) { - final DecimalFormat df = (DecimalFormat)nf; + final DecimalFormat df = (DecimalFormat) nf; df.applyPattern("##0.#####E0"); } return nf; @@ -153,14 +151,10 @@ /** * Returns a number formatter that uses an exponent after max digits. */ - public static NumberFormat getScientificFormater( - final CallContext c, - final int min, - final int max - ) { + public static NumberFormat getScientificFormater(final CallContext c, final int min, final int max) { final NumberFormat nf = getRawFormatter(c); if (nf instanceof DecimalFormat) { - final DecimalFormat df = (DecimalFormat)nf; + final DecimalFormat df = (DecimalFormat) nf; df.applyPattern("0.0E0"); df.setMaximumFractionDigits(max); df.setMinimumFractionDigits(min); @@ -168,7 +162,6 @@ return nf; } - /** * Returns a date formatter with SHORT style. */ @@ -177,7 +170,6 @@ return DateFormat.getDateInstance(DateFormat.SHORT, locale); } - /** * Returns a date formatter with MEDIUM style. */ @@ -186,17 +178,13 @@ return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); } - /** * Returns the number formatter for kilometer values in waterlevel exports. * * @return the number formatter for kilometer values. */ public static NumberFormat getWaterlevelKM(final CallContext context) { - return getFormatter( - context, - WATERLEVEL_KM_MIN_DIGITS, - WATERLEVEL_KM_MAX_DIGITS); + return getFormatter(context, WATERLEVEL_KM_MIN_DIGITS, WATERLEVEL_KM_MAX_DIGITS); } /** @@ -206,51 +194,33 @@ * @return the number formatter for csv data from diagra. */ public static NumberFormat getCSVFormatter(final CallContext context) { - return getFormatter( - context, - CSV_DIAGRAM_DATA_MIN_DIGITS, - CSV_DIAGRAM_DATA_MAX_DIGITS); + return getFormatter(context, CSV_DIAGRAM_DATA_MIN_DIGITS, CSV_DIAGRAM_DATA_MAX_DIGITS); } public static NumberFormat getWaterlevelW(final CallMeta meta) { - return getFormatter( - meta, - WATERLEVEL_W_MIN_DIGITS, - WATERLEVEL_W_MAX_DIGITS); + return getFormatter(meta, WATERLEVEL_W_MIN_DIGITS, WATERLEVEL_W_MAX_DIGITS); } - /** * Returns the number formatter for W values in waterlevel exports. * * @return the number formatter for W values. */ public static NumberFormat getWaterlevelW(final CallContext context) { - return getFormatter( - context, - WATERLEVEL_W_MIN_DIGITS, - WATERLEVEL_W_MAX_DIGITS); + return getFormatter(context, WATERLEVEL_W_MIN_DIGITS, WATERLEVEL_W_MAX_DIGITS); } - /** * Returns the number formatter for Q values in waterlevel exports. * * @return the number formatter for Q values. */ public static NumberFormat getWaterlevelQ(final CallContext context) { - return getFormatter( - context, - WATERLEVEL_Q_MIN_DIGITS, - WATERLEVEL_Q_MAX_DIGITS); + return getFormatter(context, WATERLEVEL_Q_MIN_DIGITS, WATERLEVEL_Q_MAX_DIGITS); } - public static NumberFormat getWaterlevelQ(final CallMeta meta) { - return getFormatter( - meta, - WATERLEVEL_Q_MIN_DIGITS, - WATERLEVEL_Q_MAX_DIGITS); + return getFormatter(meta, WATERLEVEL_Q_MIN_DIGITS, WATERLEVEL_Q_MAX_DIGITS); } /** @@ -260,13 +230,9 @@ * @return the number formatter for W values. */ public static NumberFormat getComputedDischargeW(final CallContext context) { - return getFormatter( - context, - COMPUTED_DISCHARGE_W_MIN_DIGITS, - COMPUTED_DISCHARGE_W_MAX_DIGITS); + return getFormatter(context, COMPUTED_DISCHARGE_W_MIN_DIGITS, COMPUTED_DISCHARGE_W_MAX_DIGITS); } - /** * Returns the number formatter for Q values in exports of computed * discharge curves. @@ -274,13 +240,9 @@ * @return the number formatter for Q values. */ public static NumberFormat getComputedDischargeQ(final CallContext context) { - return getFormatter( - context, - COMPUTED_DISCHARGE_Q_MIN_DIGITS, - COMPUTED_DISCHARGE_Q_MAX_DIGITS); + return getFormatter(context, COMPUTED_DISCHARGE_Q_MIN_DIGITS, COMPUTED_DISCHARGE_Q_MAX_DIGITS); } - /** * Returns the number formatter for W values in exports of historical * discharge curves. @@ -288,13 +250,9 @@ * @return the number formatter for W values. */ public static NumberFormat getHistoricalDischargeW(final CallContext context) { - return getFormatter( - context, - HISTORICAL_DISCHARGE_W_MIN_DIGITS, - HISTORICAL_DISCHARGE_W_MAX_DIGITS); + return getFormatter(context, HISTORICAL_DISCHARGE_W_MIN_DIGITS, HISTORICAL_DISCHARGE_W_MAX_DIGITS); } - /** * Returns the number formatter for Q values in exports of historical * discharge curves. @@ -302,186 +260,106 @@ * @return the number formatter for Q values. */ public static NumberFormat getHistoricalDischargeQ(final CallContext context) { - return getFormatter( - context, - HISTORICAL_DISCHARGE_Q_MIN_DIGITS, - HISTORICAL_DISCHARGE_Q_MAX_DIGITS); + return getFormatter(context, HISTORICAL_DISCHARGE_Q_MIN_DIGITS, HISTORICAL_DISCHARGE_Q_MAX_DIGITS); } - /** * Returns the number formatter for W values in duration curve exports. * * @return the number formatter for W values. */ public static NumberFormat getDurationW(final CallContext context) { - return getFormatter( - context, - DURATION_W_MIN_DIGITS, - DURATION_W_MAX_DIGITS); + return getFormatter(context, DURATION_W_MIN_DIGITS, DURATION_W_MAX_DIGITS); } - /** * Returns the number formatter for Q values in duration curve exports. * * @return the number formatter for W values. */ public static NumberFormat getDurationQ(final CallContext context) { - return getFormatter( - context, - DURATION_Q_MIN_DIGITS, - DURATION_Q_MAX_DIGITS); + return getFormatter(context, DURATION_Q_MIN_DIGITS, DURATION_Q_MAX_DIGITS); } - /** * Returns the number formatter for D values in duration curve exports. * * @return the number formatter for W values. */ public static NumberFormat getDurationD(final CallContext context) { - return getFormatter( - context, - DURATION_D_MIN_DIGITS, - DURATION_D_MAX_DIGITS); + return getFormatter(context, DURATION_D_MIN_DIGITS, DURATION_D_MAX_DIGITS); } public static NumberFormat getCalculationKm(final CallMeta meta) { - return getFormatter( - meta, - CALCULATION_REPORT_KM_MIN_DIGITS, - CALCULATION_REPORT_KM_MAX_DIGITS); - } - - - public static NumberFormat getFlowVelocityKM(final CallContext context) { - return getFormatter( - context, - FLOW_VELOCITY_KM_MIN_DIGITS, - FLOW_VELOCITY_KM_MAX_DIGITS); - } - - - public static NumberFormat getFlowVelocityValues(final CallContext context) { - return getFormatter( - context, - FLOW_VELOCITY_VALUES_MIN_DIGITS, - FLOW_VELOCITY_VALUES_MAX_DIGITS); - } - - - public static NumberFormat getFlowVelocityQ(final CallContext context) { - return getFormatter( - context, - FLOW_VELOCITY_Q_MIN_DIGITS, - FLOW_VELOCITY_Q_MAX_DIGITS); - } - - - public static NumberFormat getMiddleBedHeightKM(final CallContext context) { - return getFormatter( - context, - MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, - MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); + return getFormatter(meta, CALCULATION_REPORT_KM_MIN_DIGITS, CALCULATION_REPORT_KM_MAX_DIGITS); } - - public static NumberFormat getMiddleBedHeightHeight(final CallContext context) { - return getFormatter( - context, - MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, - MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); + public static NumberFormat getFlowVelocityKM(final CallContext context) { + return getFormatter(context, FLOW_VELOCITY_KM_MIN_DIGITS, FLOW_VELOCITY_KM_MAX_DIGITS); } + public static NumberFormat getFlowVelocityValues(final CallContext context) { + return getFormatter(context, FLOW_VELOCITY_VALUES_MIN_DIGITS, FLOW_VELOCITY_VALUES_MAX_DIGITS); + } + + public static NumberFormat getFlowVelocityQ(final CallContext context) { + return getFormatter(context, FLOW_VELOCITY_Q_MIN_DIGITS, FLOW_VELOCITY_Q_MAX_DIGITS); + } + + public static NumberFormat getMiddleBedHeightKM(final CallContext context) { + return getFormatter(context, MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); + } + + public static NumberFormat getMiddleBedHeightHeight(final CallContext context) { + return getFormatter(context, MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); + } public static NumberFormat getMiddleBedHeightUncert(final CallContext context) { - return getFormatter( - context, - MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, - MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); + return getFormatter(context, MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); } - public static NumberFormat getMiddleBedHeightDataGap(final CallContext context) { - return getFormatter( - context, - MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, - MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); + return getFormatter(context, MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); } - - public static NumberFormat getMiddleBedHeightSounding( - final CallContext context - ) { - return getFormatter( - context, - MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, - MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); + public static NumberFormat getMiddleBedHeightSounding(final CallContext context) { + return getFormatter(context, MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); } - public static NumberFormat getFixDeltaWKM(final CallContext context) { - return getFormatter( - context, - FIX_DELTA_W_KM_MIN_DIGITS, - FIX_DELTA_W_KM_MAX_DIGITS); + return getFormatter(context, FIX_DELTA_W_KM_MIN_DIGITS, FIX_DELTA_W_KM_MAX_DIGITS); } public static NumberFormat getFixDeltaWDeltaW(final CallContext context) { - return getFormatter( - context, - FIX_DELTA_W_DELTA_W_MIN_DIGITS, - FIX_DELTA_W_DELTA_W_MAX_DIGITS); + return getFormatter(context, FIX_DELTA_W_DELTA_W_MIN_DIGITS, FIX_DELTA_W_DELTA_W_MAX_DIGITS); } public static NumberFormat getFixDeltaWQ(final CallContext context) { - return getFormatter( - context, - FIX_DELTA_W_DELTA_Q_MIN_DIGITS, - FIX_DELTA_W_DELTA_Q_MAX_DIGITS); + return getFormatter(context, FIX_DELTA_W_DELTA_Q_MIN_DIGITS, FIX_DELTA_W_DELTA_Q_MAX_DIGITS); } public static NumberFormat getFixDeltaWW(final CallContext context) { - return getFormatter( - context, - FIX_DELTA_W_DELTA_W_MIN_DIGITS, - FIX_DELTA_W_DELTA_W_MAX_DIGITS); + return getFormatter(context, FIX_DELTA_W_DELTA_W_MIN_DIGITS, FIX_DELTA_W_DELTA_W_MAX_DIGITS); } public static NumberFormat getVariance(final CallContext context) { - return getFormatter( - context, - VARIANCE_MIN_DIGITS, - VARIANCE_MAX_DIGITS); + return getFormatter(context, VARIANCE_MIN_DIGITS, VARIANCE_MAX_DIGITS); } public static NumberFormat getSQRelationA(final CallContext context) { - return getScientificFormater( - context, - SQ_RELATION_A_MIN_DIGITS, - SQ_RELATION_A_MAX_DIGITS); + return getScientificFormater(context, SQ_RELATION_A_MIN_DIGITS, SQ_RELATION_A_MAX_DIGITS); } public static NumberFormat getSQRelationB(final CallContext context) { - return getFormatter( - context, - SQ_RELATION_B_MIN_DIGITS, - SQ_RELATION_B_MAX_DIGITS); + return getFormatter(context, SQ_RELATION_B_MIN_DIGITS, SQ_RELATION_B_MAX_DIGITS); } public static NumberFormat getSQRelationKM(final CallContext context) { - return getFormatter( - context, - SQ_RELATION_KM_MIN_DIGITS, - SQ_RELATION_KM_MAX_DIGITS); + return getFormatter(context, SQ_RELATION_KM_MIN_DIGITS, SQ_RELATION_KM_MAX_DIGITS); } public static NumberFormat getMeterFormat(final CallContext context) { - return getFormatter( - context, - 0, - 2); + return getFormatter(context, 0, 2); } @@ -510,10 +388,14 @@ * Another waterlevel formatter with fixed digits (always 2) */ public static NumberFormat getWaterlevelW2(final CallMeta meta) { - return getFormatter( meta, 2, 2); + return getFormatter(meta, 2, 2); } public static NumberFormat getFlowDepthDevelopmentPerYear(final CallContext context) { return getFormatter(context.getMeta(), 2, 2); } + + public static NumberFormat getSalixLine(final CallContext context) { + return Formatter.getFormatter(context, 2, 2); + } } \ No newline at end of file