← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19899: minor fix, add ValueType.isNumeric

 

------------------------------------------------------------
revno: 19899
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-08-31 14:23:07 +0700
message:
  minor fix, add ValueType.isNumeric
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.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/common/ValueType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-08-31 05:16:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-08-31 07:23:07 +0000
@@ -81,6 +81,11 @@
         return this == INTEGER || this == INTEGER_POSITIVE || this == INTEGER_NEGATIVE || this == INTEGER_ZERO_OR_POSITIVE;
     }
 
+    public boolean isNumeric()
+    {
+        return this.isInteger() || this == NUMBER;
+    }
+
     public boolean isText()
     {
         return this == TEXT || this == LONG_TEXT;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java	2015-02-19 09:18:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java	2015-08-31 07:23:07 +0000
@@ -28,10 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.Serializable;
-import java.util.Date;
-import java.util.regex.Pattern;
-
 import org.apache.commons.lang3.StringUtils;
 import org.hisp.dhis.common.ImportableObject;
 import org.hisp.dhis.dataelement.DataElement;
@@ -39,6 +35,10 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 
+import java.io.Serializable;
+import java.util.Date;
+import java.util.regex.Pattern;
+
 /**
  * @author Kristian Nordal
  * @version $Id: DataValue.java 4638 2008-02-25 10:06:47Z larshelg $
@@ -52,7 +52,7 @@
     private static final long serialVersionUID = 6269303850789110610L;
 
     private static final Pattern ZERO_PATTERN = Pattern.compile( "^0(\\.0*)?$" );
-    
+
     public static final String TRUE = "true";
     public static final String FALSE = "false";
 
@@ -102,12 +102,12 @@
     }
 
     /**
-     * @param dataElement the data element.
-     * @param period the period.
-     * @param source the organisation unit.
+     * @param dataElement         the data element.
+     * @param period              the period.
+     * @param source              the organisation unit.
      * @param categoryOptionCombo the category option combo.
      */
-    public DataValue( DataElement dataElement, Period period, OrganisationUnit source, 
+    public DataValue( DataElement dataElement, Period period, OrganisationUnit source,
         DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo )
     {
         this.dataElement = dataElement;
@@ -119,17 +119,17 @@
     }
 
     /**
-     * @param dataElement the data element.
-     * @param period the period.
-     * @param source the organisation unit.
-     * @param categoryOptionCombo the category option combo.
+     * @param dataElement          the data element.
+     * @param period               the period.
+     * @param source               the organisation unit.
+     * @param categoryOptionCombo  the category option combo.
      * @param attributeOptionCombo the attribute option combo.
-     * @param value the value.
-     * @param storedBy the user that stored this data value.
-     * @param lastUpdated the time of the last update to this data value.
-     * @param comment the comment.
+     * @param value                the value.
+     * @param storedBy             the user that stored this data value.
+     * @param lastUpdated          the time of the last update to this data value.
+     * @param comment              the comment.
      */
-    public DataValue( DataElement dataElement, Period period, OrganisationUnit source, DataElementCategoryOptionCombo categoryOptionCombo, 
+    public DataValue( DataElement dataElement, Period period, OrganisationUnit source, DataElementCategoryOptionCombo categoryOptionCombo,
         DataElementCategoryOptionCombo attributeOptionCombo, String value, String storedBy, Date lastUpdated, String comment )
     {
         this.dataElement = dataElement;
@@ -165,14 +165,13 @@
     {
         return getCategoryOptionCombo();
     }
-    
+
     /**
      * Indicates whether the value is a zero.
      */
     public boolean isZero()
     {
-        return dataElement != null && dataElement.getType().equals( DataElement.VALUE_TYPE_INT )
-            && value != null && ZERO_PATTERN.matcher( value ).find();
+        return dataElement != null && dataElement.getValueType().isNumeric() && value != null && ZERO_PATTERN.matcher( value ).find();
     }
 
     /**
@@ -192,7 +191,7 @@
     {
         return comment != null && !comment.isEmpty();
     }
-    
+
     public void toggleFollowUp()
     {
         if ( this.followup == null )
@@ -204,7 +203,7 @@
             this.followup = !this.followup;
         }
     }
-    
+
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------
@@ -229,12 +228,12 @@
 
         final DataValue other = (DataValue) o;
 
-        return 
-            dataElement.equals( other.getDataElement() ) && 
-            period.equals( other.getPeriod() ) && 
-            source.equals( other.getSource() ) &&
-            categoryOptionCombo.equals( other.getCategoryOptionCombo() ) &&
-            attributeOptionCombo.equals( other.getAttributeOptionCombo() );
+        return
+            dataElement.equals( other.getDataElement() ) &&
+                period.equals( other.getPeriod() ) &&
+                source.equals( other.getSource() ) &&
+                categoryOptionCombo.equals( other.getCategoryOptionCombo() ) &&
+                attributeOptionCombo.equals( other.getAttributeOptionCombo() );
     }
 
     @Override
@@ -251,7 +250,7 @@
 
         return result;
     }
-    
+
     @Override
     public String toString()
     {
@@ -363,7 +362,7 @@
     {
         this.lastUpdated = lastUpdated;
     }
-    
+
     public String getComment()
     {
         return comment;