← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17338: Removed method I18nFormat.formatValue

 

------------------------------------------------------------
revno: 17338
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-11-02 17:24:35 -0500
message:
  Removed method I18nFormat.formatValue
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java	2014-09-22 05:21:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java	2014-11-02 22:24:35 +0000
@@ -28,19 +28,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.calendar.DateTimeUnit;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.period.WeeklyPeriodType;
-
 import java.text.DateFormat;
 import java.text.DateFormatSymbols;
-import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.ResourceBundle;
 
+import org.hisp.dhis.calendar.DateTimeUnit;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.WeeklyPeriodType;
+
 /**
  * @author Pham Thi Thuy
  * @author Nguyen Dang Quang
@@ -48,9 +47,6 @@
  */
 public class I18nFormat
 {
-    private static final DecimalFormat FORMAT_VALUE = new DecimalFormat( "#.#" ); // Fixed for now
-    private static final String EMPTY = "";
-    private static final String NAN = "NaN";
     private static final String INVALID_DATE = "Invalid date format";
 
     public static final String FORMAT_DATE = "yyyy-MM-dd";
@@ -268,29 +264,6 @@
         }
     }
 
-    /**
-     * Formats value. Returns empty string if value is null. Returns NaN if value
-     * is not a number.
-     *
-     * @param value the value to format.
-     */
-    public String formatValue( Object value )
-    {
-        if ( value == null )
-        {
-            return EMPTY;
-        }
-
-        try
-        {
-            return FORMAT_VALUE.format( value );
-        }
-        catch ( IllegalArgumentException ex )
-        {
-            return NAN;
-        }
-    }
-
     // -------------------------------------------------------------------------
     // Support methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java	2014-10-28 10:29:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java	2014-11-02 22:24:35 +0000
@@ -28,11 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.apache.commons.lang.StringUtils.trimToEmpty;
 import static org.hisp.dhis.dataentryform.DataEntryFormService.DATAELEMENT_TOTAL_PATTERN;
 import static org.hisp.dhis.dataentryform.DataEntryFormService.IDENTIFIER_PATTERN;
 import static org.hisp.dhis.dataentryform.DataEntryFormService.INDICATOR_PATTERN;
 import static org.hisp.dhis.dataentryform.DataEntryFormService.INPUT_PATTERN;
 import static org.hisp.dhis.datasetreport.DataSetReportStore.SEPARATOR;
+import static org.hisp.dhis.system.util.MathUtils.getRoundedObject;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -321,7 +323,7 @@
 
                 Double dataValue = dataValues.get( dataElementId + SEPARATOR + optionComboId );
 
-                String value = "<span class=\"val\" data-de=\"" + dataElementId + "\" data-co=\"" + optionComboId + "\">" + format.formatValue( dataValue ) + "</span>";
+                String value = "<span class=\"val\" data-de=\"" + dataElementId + "\" data-co=\"" + optionComboId + "\">" + trimToEmpty( String.valueOf( getRoundedObject( dataValue ) ) ) + "</span>";
                 
                 inputMatcher.appendReplacement( buffer, value );
             }
@@ -331,7 +333,7 @@
                 
                 Double dataValue = dataValues.get( dataElementId );
 
-                inputMatcher.appendReplacement( buffer, format.formatValue( dataValue ) );
+                inputMatcher.appendReplacement( buffer, trimToEmpty( String.valueOf( getRoundedObject( dataValue ) ) ) );
             }
             else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
             {
@@ -339,7 +341,7 @@
 
                 Double indicatorValue = indicatorValues.get( indicatorId );
 
-                inputMatcher.appendReplacement( buffer, format.formatValue( indicatorValue ) );
+                inputMatcher.appendReplacement( buffer, trimToEmpty( String.valueOf( getRoundedObject( indicatorValue ) ) ) );
             }
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2014-11-02 22:24:35 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.sms.SmsServiceException;
 import org.hisp.dhis.sms.outbound.OutboundSms;
 import org.hisp.dhis.system.grid.ListGrid;
+import org.hisp.dhis.system.util.MathUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminderService;
@@ -221,7 +222,7 @@
                 ProgramInstance.STATUS_ACTIVE );
             percent = (stageCompleted + 0.0) / totalCompleted;
         }
-        grid.addValue( format.formatValue( percent ) ).addEmptyValues( 6 );
+        grid.addValue( MathUtils.getRounded( percent ) ).addEmptyValues( 6 );
 
         // Add empty row
 
@@ -269,7 +270,7 @@
             {
                 percent = (totalVisit + 0.0) * 100 / totalAll;
             }
-            grid.addValue( format.formatValue( percent ) + "%" );
+            grid.addValue( MathUtils.getRounded( percent ) + "%" );
 
             // Forms completed (#) = Program stage instances where the user has
             // clicked complete.
@@ -281,7 +282,7 @@
             {
                 percent = (totalCompletedEvent + 0.0) * 100 / totalAll;
             }
-            grid.addValue( format.formatValue( percent ) + "%" );
+            grid.addValue( MathUtils.getRounded( percent ) + "%" );
 
             // Visits overdue (#)
             int overdue = programStageInstanceStore.getOverDueCount( programStage, orgunitIds, startDate, endDate );
@@ -294,7 +295,7 @@
             {
                 percent = (overdue + 0.0) * 100 / totalAll;
             }
-            grid.addValue( format.formatValue( percent ) + "%" );
+            grid.addValue( MathUtils.getRounded( percent ) + "%" );
         }
 
         return grid;