ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hol...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional PropertyFile.java
Date Tue, 19 Feb 2002 02:52:54 GMT
holtdl      02/02/18 18:52:54

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional
                        PropertyFile.java
  Log:
  Fix the increment/decrement operations so they work whether or not
  a 'value' attr was specified. (And fix a tiny spacing nit :)
  
  Revision  Changes    Path
  1.13      +23 -3     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
  
  Index: PropertyFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PropertyFile.java	8 Jan 2002 22:26:32 -0000	1.12
  +++ PropertyFile.java	19 Feb 2002 02:52:54 -0000	1.13
  @@ -430,7 +430,7 @@
                   NOW_VALUE_.equals(m_default.toLowerCase()) &&
                   (m_operation == Operation.INCREMENT_OPER ||
                    m_operation == Operation.DECREMENT_OPER) ) {
  -                oldValue = null;
  +                 oldValue = null;
               }
   
               if (oldValue != null) {
  @@ -518,12 +518,14 @@
           {
               int value = 0;
               int newValue  = 0;
  +            int oldIntValue  = 0;
   
               DecimalFormat fmt = (m_pattern != null) ? new DecimalFormat(m_pattern)
                                                       : new DecimalFormat();
   
               if (oldValue != null) {
                   try {
  +                    oldIntValue = fmt.parse(oldValue).intValue();
                       value = fmt.parse(oldValue).intValue();
                   }
                   catch (NumberFormatException nfe) { /* swollow */ }
  @@ -548,10 +550,28 @@
                   newValue = value;
               }
               else if (m_operation == Operation.INCREMENT_OPER) {
  -                newValue = ++value;
  +                if (this.m_value == "") {
  +                    // No value attr was given, so just increment "value"
  +                    // (which is the old value from the prop file, 0 by
  +                    // assignment above, if none) by 1.
  +                    newValue = ++value;
  +                } else {
  +                    // A value attr was given, so add it to "value", which
  +                    // is the old value from the prop file (0, if none).
  +                    newValue = (oldIntValue + value) ;
  +                }
               }
               else if (m_operation == Operation.DECREMENT_OPER) {
  -                newValue = --value;
  +                if (this.m_value == "") {
  +                    // No value attr was given, so just decrement "value"
  +                    // (which is the old value from the prop file, 0 by
  +                    // assignment above, if none) by 1.
  +                    newValue = --value;
  +                } else {
  +                    // A value attr was given, so subtract from it "value",
  +                    // which is the old value from the prop file (0, if none).
  +                    newValue = (oldIntValue - value);
  +                }
               }
               m_value = fmt.format(newValue);
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message