Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java @ 8951:322b0e6298ea
Work on SINFO FlowDepth-Development
author | gernotbelger |
---|---|
date | Fri, 16 Mar 2018 18:08:38 +0100 |
parents | 5b5bdce5a216 |
children | fb9430250899 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Thu Mar 15 17:22:28 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Fri Mar 16 18:08:38 2018 +0100 @@ -9,9 +9,9 @@ package org.dive4elements.river.utils; import java.text.DateFormat; +import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; -import java.text.DecimalFormat; import java.util.Locale; import org.dive4elements.artifacts.CallContext; @@ -111,9 +111,9 @@ * @return A NumberFormat. Use #format(NUMBER) to get String representation * of NUMBER. */ - public static NumberFormat getFormatter(CallMeta m, int min, int max){ - Locale locale = Resources.getLocale(m); - 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,7 +121,7 @@ return nf; } - public static NumberFormat getFormatter(CallContext c, int min, int max){ + public static NumberFormat getFormatter(final CallContext c, final int min, final int max){ return getFormatter(c.getMeta(), min, max); } @@ -133,18 +133,18 @@ * * @return a number formatter. */ - public static NumberFormat getRawFormatter(CallContext c) { - Locale locale = Resources.getLocale(c.getMeta()); + public static NumberFormat getRawFormatter(final CallContext c) { + final Locale locale = Resources.getLocale(c.getMeta()); return NumberFormat.getInstance(locale); } /** * Returns a formatter in engineering notation. */ - public static NumberFormat getEngFormatter(CallContext c) { - NumberFormat nf = getRawFormatter(c); + public static NumberFormat getEngFormatter(final CallContext c) { + final NumberFormat nf = getRawFormatter(c); if (nf instanceof DecimalFormat) { - DecimalFormat df = (DecimalFormat)nf; + final DecimalFormat df = (DecimalFormat)nf; df.applyPattern("##0.#####E0"); } return nf; @@ -154,13 +154,13 @@ * Returns a number formatter that uses an exponent after max digits. */ public static NumberFormat getScientificFormater( - CallContext c, - int min, - int max - ) { - NumberFormat nf = getRawFormatter(c); + final CallContext c, + final int min, + final int max + ) { + final NumberFormat nf = getRawFormatter(c); if (nf instanceof DecimalFormat) { - DecimalFormat df = (DecimalFormat)nf; + final DecimalFormat df = (DecimalFormat)nf; df.applyPattern("0.0E0"); df.setMaximumFractionDigits(max); df.setMinimumFractionDigits(min); @@ -172,8 +172,8 @@ /** * Returns a date formatter with SHORT style. */ - public static DateFormat getShortDateFormat(CallContext cc) { - Locale locale = Resources.getLocale(cc.getMeta()); + public static DateFormat getShortDateFormat(final CallContext cc) { + final Locale locale = Resources.getLocale(cc.getMeta()); return DateFormat.getDateInstance(DateFormat.SHORT, locale); } @@ -181,8 +181,8 @@ /** * Returns a date formatter with MEDIUM style. */ - public static DateFormat getMediumDateFormat(CallContext cc) { - Locale locale = Resources.getLocale(cc.getMeta()); + public static DateFormat getMediumDateFormat(final CallContext cc) { + final Locale locale = Resources.getLocale(cc.getMeta()); return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); } @@ -192,7 +192,7 @@ * * @return the number formatter for kilometer values. */ - public static NumberFormat getWaterlevelKM(CallContext context) { + public static NumberFormat getWaterlevelKM(final CallContext context) { return getFormatter( context, WATERLEVEL_KM_MIN_DIGITS, @@ -205,14 +205,14 @@ * * @return the number formatter for csv data from diagra. */ - public static NumberFormat getCSVFormatter(CallContext context) { + public static NumberFormat getCSVFormatter(final CallContext context) { return getFormatter( context, CSV_DIAGRAM_DATA_MIN_DIGITS, CSV_DIAGRAM_DATA_MAX_DIGITS); } - public static NumberFormat getWaterlevelW(CallMeta meta) { + public static NumberFormat getWaterlevelW(final CallMeta meta) { return getFormatter( meta, WATERLEVEL_W_MIN_DIGITS, @@ -225,7 +225,7 @@ * * @return the number formatter for W values. */ - public static NumberFormat getWaterlevelW(CallContext context) { + public static NumberFormat getWaterlevelW(final CallContext context) { return getFormatter( context, WATERLEVEL_W_MIN_DIGITS, @@ -238,7 +238,7 @@ * * @return the number formatter for Q values. */ - public static NumberFormat getWaterlevelQ(CallContext context) { + public static NumberFormat getWaterlevelQ(final CallContext context) { return getFormatter( context, WATERLEVEL_Q_MIN_DIGITS, @@ -246,7 +246,7 @@ } - public static NumberFormat getWaterlevelQ(CallMeta meta) { + public static NumberFormat getWaterlevelQ(final CallMeta meta) { return getFormatter( meta, WATERLEVEL_Q_MIN_DIGITS, @@ -259,7 +259,7 @@ * * @return the number formatter for W values. */ - public static NumberFormat getComputedDischargeW(CallContext context) { + public static NumberFormat getComputedDischargeW(final CallContext context) { return getFormatter( context, COMPUTED_DISCHARGE_W_MIN_DIGITS, @@ -273,7 +273,7 @@ * * @return the number formatter for Q values. */ - public static NumberFormat getComputedDischargeQ(CallContext context) { + public static NumberFormat getComputedDischargeQ(final CallContext context) { return getFormatter( context, COMPUTED_DISCHARGE_Q_MIN_DIGITS, @@ -287,7 +287,7 @@ * * @return the number formatter for W values. */ - public static NumberFormat getHistoricalDischargeW(CallContext context) { + public static NumberFormat getHistoricalDischargeW(final CallContext context) { return getFormatter( context, HISTORICAL_DISCHARGE_W_MIN_DIGITS, @@ -301,7 +301,7 @@ * * @return the number formatter for Q values. */ - public static NumberFormat getHistoricalDischargeQ(CallContext context) { + public static NumberFormat getHistoricalDischargeQ(final CallContext context) { return getFormatter( context, HISTORICAL_DISCHARGE_Q_MIN_DIGITS, @@ -314,7 +314,7 @@ * * @return the number formatter for W values. */ - public static NumberFormat getDurationW(CallContext context) { + public static NumberFormat getDurationW(final CallContext context) { return getFormatter( context, DURATION_W_MIN_DIGITS, @@ -327,7 +327,7 @@ * * @return the number formatter for W values. */ - public static NumberFormat getDurationQ(CallContext context) { + public static NumberFormat getDurationQ(final CallContext context) { return getFormatter( context, DURATION_Q_MIN_DIGITS, @@ -340,14 +340,14 @@ * * @return the number formatter for W values. */ - public static NumberFormat getDurationD(CallContext context) { + public static NumberFormat getDurationD(final CallContext context) { return getFormatter( context, DURATION_D_MIN_DIGITS, DURATION_D_MAX_DIGITS); } - public static NumberFormat getCalculationKm(CallMeta meta) { + public static NumberFormat getCalculationKm(final CallMeta meta) { return getFormatter( meta, CALCULATION_REPORT_KM_MIN_DIGITS, @@ -355,7 +355,7 @@ } - public static NumberFormat getFlowVelocityKM(CallContext context) { + public static NumberFormat getFlowVelocityKM(final CallContext context) { return getFormatter( context, FLOW_VELOCITY_KM_MIN_DIGITS, @@ -363,7 +363,7 @@ } - public static NumberFormat getFlowVelocityValues(CallContext context) { + public static NumberFormat getFlowVelocityValues(final CallContext context) { return getFormatter( context, FLOW_VELOCITY_VALUES_MIN_DIGITS, @@ -371,7 +371,7 @@ } - public static NumberFormat getFlowVelocityQ(CallContext context) { + public static NumberFormat getFlowVelocityQ(final CallContext context) { return getFormatter( context, FLOW_VELOCITY_Q_MIN_DIGITS, @@ -379,7 +379,7 @@ } - public static NumberFormat getMiddleBedHeightKM(CallContext context) { + public static NumberFormat getMiddleBedHeightKM(final CallContext context) { return getFormatter( context, MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, @@ -387,7 +387,7 @@ } - public static NumberFormat getMiddleBedHeightHeight(CallContext context) { + public static NumberFormat getMiddleBedHeightHeight(final CallContext context) { return getFormatter( context, MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, @@ -395,7 +395,7 @@ } - public static NumberFormat getMiddleBedHeightUncert(CallContext context) { + public static NumberFormat getMiddleBedHeightUncert(final CallContext context) { return getFormatter( context, MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, @@ -403,7 +403,7 @@ } - public static NumberFormat getMiddleBedHeightDataGap(CallContext context) { + public static NumberFormat getMiddleBedHeightDataGap(final CallContext context) { return getFormatter( context, MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, @@ -412,8 +412,8 @@ public static NumberFormat getMiddleBedHeightSounding( - CallContext context - ) { + final CallContext context + ) { return getFormatter( context, MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, @@ -421,63 +421,63 @@ } - public static NumberFormat getFixDeltaWKM(CallContext context) { + public static NumberFormat getFixDeltaWKM(final CallContext context) { return getFormatter( context, FIX_DELTA_W_KM_MIN_DIGITS, FIX_DELTA_W_KM_MAX_DIGITS); } - public static NumberFormat getFixDeltaWDeltaW(CallContext context) { - return getFormatter( - context, - FIX_DELTA_W_DELTA_W_MIN_DIGITS, - FIX_DELTA_W_DELTA_W_MAX_DIGITS); - } - - public static NumberFormat getFixDeltaWQ(CallContext context) { - return getFormatter( - context, - FIX_DELTA_W_DELTA_Q_MIN_DIGITS, - FIX_DELTA_W_DELTA_Q_MAX_DIGITS); - } - - public static NumberFormat getFixDeltaWW(CallContext context) { + public static NumberFormat getFixDeltaWDeltaW(final CallContext context) { return getFormatter( context, FIX_DELTA_W_DELTA_W_MIN_DIGITS, FIX_DELTA_W_DELTA_W_MAX_DIGITS); } - public static NumberFormat getVariance(CallContext context) { + public static NumberFormat getFixDeltaWQ(final CallContext context) { + 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); + } + + public static NumberFormat getVariance(final CallContext context) { return getFormatter( context, VARIANCE_MIN_DIGITS, VARIANCE_MAX_DIGITS); } - public static NumberFormat getSQRelationA(CallContext context) { + public static NumberFormat getSQRelationA(final CallContext context) { return getScientificFormater( context, SQ_RELATION_A_MIN_DIGITS, SQ_RELATION_A_MAX_DIGITS); } - public static NumberFormat getSQRelationB(CallContext context) { + public static NumberFormat getSQRelationB(final CallContext context) { return getFormatter( context, SQ_RELATION_B_MIN_DIGITS, SQ_RELATION_B_MAX_DIGITS); } - public static NumberFormat getSQRelationKM(CallContext context) { + public static NumberFormat getSQRelationKM(final CallContext context) { return getFormatter( context, SQ_RELATION_KM_MIN_DIGITS, SQ_RELATION_KM_MAX_DIGITS); } - public static NumberFormat getMeterFormat(CallContext context) { + public static NumberFormat getMeterFormat(final CallContext context) { return getFormatter( context, 0, @@ -485,32 +485,35 @@ } - public static DateFormat getDateFormatter(CallMeta m, String pattern) { - Locale locale = Resources.getLocale(m); + public static DateFormat getDateFormatter(final CallMeta m, final String pattern) { + final Locale locale = Resources.getLocale(m); return new SimpleDateFormat(pattern, locale); } - public static NumberFormat getMeanBedHeight(CallContext context) { + public static NumberFormat getMeanBedHeight(final CallContext context) { return Formatter.getFormatter(context, 2, 2); } - public static NumberFormat getTkh(CallContext context) { + public static NumberFormat getTkh(final CallContext context) { return Formatter.getFormatter(context, 1, 1); } - public static NumberFormat getFlowDepth(CallContext context) { + public static NumberFormat getFlowDepth(final CallContext context) { return Formatter.getFormatter(context, 2, 2); } - public static NumberFormat getW(CallContext context) { + public static NumberFormat getW(final CallContext context) { return Formatter.getFormatter(context, 2, 2); } /** * Another waterlevel formatter with fixed digits (always 2) */ - public static NumberFormat getWaterlevelW2(CallMeta meta) { + public static NumberFormat getWaterlevelW2(final CallMeta meta) { return getFormatter( meta, 2, 2); } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : + + public static NumberFormat getFlowDepthDevelopmentPerYear(final CallContext context) { + return getFormatter(context.getMeta(), 2, 2); + } +} \ No newline at end of file