You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2010/02/17 18:23:40 UTC

svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Author: doogie
Date: Wed Feb 17 17:23:39 2010
New Revision: 911089

URL: http://svn.apache.org/viewvc?rev=911089&view=rev
Log:
Rename millis parameters everywhere to milliseconds.  Also rename the
millis method.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/TimeDurationTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java?rev=911089&r1=911088&r2=911089&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/TimeDuration.java Wed Feb 17 17:23:39 2010
@@ -27,7 +27,7 @@
     /** A <code>TimeDuration</code> instance that represents a zero time duration. */
     public static final TimeDuration ZeroTimeDuration = new NullDuration();
 
-    protected final int millis;
+    protected final int milliseconds;
     protected final int seconds;
     protected final int minutes;
     protected final int hours;
@@ -42,10 +42,10 @@
      * @param hours The number of hours in this duration
      * @param minutes The number of minutes in this duration
      * @param seconds The number of years in this duration
-     * @param millis The number of milliseconds in this duration
+     * @param milliseconds The number of milliseconds in this duration
      */
-    public TimeDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis) {
-        this.millis = millis;
+    public TimeDuration(int years, int months, int days, int hours, int minutes, int seconds, int milliseconds) {
+        this.milliseconds = milliseconds;
         this.seconds = seconds;
         this.minutes = minutes;
         this.hours = hours;
@@ -84,7 +84,7 @@
 
         // shortcut for equal dates
         if (deltaMillis == 0) {
-            this.years = this.months = this.days = this.hours = this.minutes = this.seconds = this.millis = 0;
+            this.years = this.months = this.days = this.hours = this.minutes = this.seconds = this.milliseconds = 0;
             return;
         }
 
@@ -120,7 +120,7 @@
         this.seconds = factor * advanceCalendar(calStart, calEnd, (int) units, Calendar.SECOND);
         deltaMillis = computeDeltaMillis(calStart.getTimeInMillis(), targetMillis);
 
-        this.millis = factor * (int) deltaMillis;
+        this.milliseconds = factor * (int) deltaMillis;
     }
 
     private static long computeDeltaMillis(long start, long end) {
@@ -172,7 +172,7 @@
             TimeDuration that = (TimeDuration) obj;
             return this.years == that.years && this.months == that.months && this.days == that.days
             && this.hours == that.hours && this.minutes == that.minutes && this.seconds == that.seconds
-            && this.millis == that.millis;
+            && this.milliseconds == that.milliseconds;
         } catch (Exception e) {}
         return false;
     }
@@ -182,9 +182,10 @@
      */
     @Override
     public String toString() {
-        return this.years + ":" + this.months + ":" + this.days + ":" + this.hours + ":" + this.minutes + ":" + this.seconds + ":" + this.millis;
+        return this.years + ":" + this.months + ":" + this.days + ":" + this.hours + ":" + this.minutes + ":" + this.seconds + ":" + this.milliseconds;
     }
 
+    @Override
     public int compareTo(TimeDuration arg0) {
         if (this == arg0) {
             return 0;
@@ -213,7 +214,7 @@
         if (r != 0) {
             return r;
         }
-        return this.millis - arg0.millis;
+        return this.milliseconds - arg0.milliseconds;
     }
 
     /** Returns <code>true</code> if this duration is negative.
@@ -221,7 +222,7 @@
      * @return <code>true</code> if this duration is negative
      */
     public boolean isNegative() {
-        return years < 0 || months < 0  || days < 0 || hours < 0 || minutes < 0 || seconds < 0 || millis < 0;
+        return years < 0 || months < 0  || days < 0 || hours < 0 || minutes < 0 || seconds < 0 || milliseconds < 0;
     }
 
     /** Returns <code>true</code> if this duration is zero.
@@ -229,14 +230,14 @@
      * @return <code>true</code> if this duration is zero
      */
     public boolean isZero() {
-        return this.millis == 0 && this.seconds == 0 &&
+        return this.milliseconds == 0 && this.seconds == 0 &&
                 this.minutes == 0 && this.hours == 0 && this.days == 0 &&
                 this.months == 0 && this.years == 0;
     }
 
     /** Returns the milliseconds in this time duration. */
-    public int millis() {
-        return this.millis;
+    public int milliseconds() {
+        return this.milliseconds;
     }
 
     /** Returns the seconds in this time duration. */
@@ -275,7 +276,7 @@
      * @return <code>cal</code>
      */
     public Calendar addToCalendar(Calendar cal) {
-        cal.add(Calendar.MILLISECOND, this.millis);
+        cal.add(Calendar.MILLISECOND, this.milliseconds);
         cal.add(Calendar.SECOND, this.seconds);
         cal.add(Calendar.MINUTE, this.minutes);
         cal.add(Calendar.HOUR, this.hours);
@@ -292,32 +293,32 @@
      * method should not be used to calculate elapsed time - use the elapsed
      * time constructor instead.</p>
      *
-     * @param millis A millisecond value
+     * @param milliseconds A millisecond value
      * @return A <code>TimeDuration</code> instance
      */
-    public static TimeDuration fromLong(long millis) {
-        if (millis == 0) {
+    public static TimeDuration fromLong(long milliseconds) {
+        if (milliseconds == 0) {
             return ZeroTimeDuration;
         }
-        long units = millis / 0x757B12C00L;
+        long units = milliseconds / 0x757B12C00L;
         int years = (int) units;
-        millis -= 0x757B12C00L * (long) years;
-        units = millis / 0x9CA41900L;
+        milliseconds -= 0x757B12C00L * (long) years;
+        units = milliseconds / 0x9CA41900L;
         int months = (int) units;
-        millis -= 0x9CA41900L * (long) months;
-        units = millis / 86400000;
+        milliseconds -= 0x9CA41900L * (long) months;
+        units = milliseconds / 86400000;
         int days = (int) units;
-        millis -= 86400000 * (long) days;
-        units = millis / 3600000;
+        milliseconds -= 86400000 * (long) days;
+        units = milliseconds / 3600000;
         int hours = (int) units;
-        millis -= 3600000 * (long) hours;
-        units = millis / 60000;
+        milliseconds -= 3600000 * (long) hours;
+        units = milliseconds / 60000;
         int minutes = (int) units;
-        millis -= 60000 * (long) minutes;
-        units = millis / 1000;
+        milliseconds -= 60000 * (long) minutes;
+        units = milliseconds / 1000;
         int seconds = (int) units;
-        millis -= 1000 * (long) seconds;
-        return new TimeDuration(years, months, days, hours, minutes, seconds, (int) millis);
+        milliseconds -= 1000 * (long) seconds;
+        return new TimeDuration(years, months, days, hours, minutes, seconds, (int) milliseconds);
     }
 
     /** Returns a <code>TimeDuration</code> instance derived from a <code>Number</code>
@@ -373,7 +374,7 @@
         (3600000 * (long) duration.hours) +
         (60000 * (long) duration.minutes) +
         (1000 * (long) duration.seconds) +
-        duration.millis;
+        duration.milliseconds;
     }
 
     protected static class NullDuration extends TimeDuration {

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/TimeDurationTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/TimeDurationTests.java?rev=911089&r1=911088&r2=911089&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/TimeDurationTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/TimeDurationTests.java Wed Feb 17 17:23:39 2010
@@ -57,7 +57,7 @@
         assertEquals(label + ".hours()", hours, duration.hours());
         assertEquals(label + ".minutes()", minutes, duration.minutes());
         assertEquals(label + ".seconds()", seconds, duration.seconds());
-        assertEquals(label + ".milliseconds()", milliseconds, duration.millis());
+        assertEquals(label + ".milliseconds()", milliseconds, duration.milliseconds());
         assertEquals(label + ".isNegative()", isNegative, duration.isNegative());
         assertEquals(label + ".toString()", string, duration.toString());
         assertEquals(label + ".equals(from/to long)", duration, TimeDuration.fromLong(TimeDuration.toLong(duration)));



Re: TimeDuration stuff: Re: svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Posted by Adrian Crum <ad...@hlmksw.com>.
Adam Heath wrote:
> Adrian Crum wrote:
>> Adam Heath wrote:
>>> doogie@apache.org wrote:
>>>> Author: doogie
>>>> Date: Wed Feb 17 17:23:39 2010
>>>> New Revision: 911089
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=911089&view=rev
>>>> Log:
>>>> Rename millis parameters everywhere to milliseconds.  Also rename the
>>>> millis method.
>>> At this point, I'm mostly done with TimeDuration.  However, there's
>>> one more thing I have to do.  The contract for java.lang.Object says
>>> that if you implement equals, you must implement hashCode against the
>>> same set of fields.  TimeDuration doesn't currently do this.
>>>
>>> So, while trying to figure out how to do that exactly, I started
>>> adding some helper methods to UtilObject to make hashCode of multiple
>>> fields easier.  Before that happened tho, I decided to write full test
>>> cases for UtilObject.
>>>
>>> So, TimeDuration and UtilObject now have full coverage.
>> By the way, now that I fixed the epoch bug, don't you think we can put
>> advanceCalendar back the way it was? The units argument will always be
>> positive now.
> 
> Yeah, I saw what you did.  I was about to commit my flood, but you
> just beat me.  There is still full coverage, however, which means my
> version of the fix is still being run(all lines, all branches).  I
> haven't had time to try and remove it and see if everything still
> succeeds.  It might be that there isn't enough testing, and your fix
> actually fixes something else.

Never mind. I just re-read your code comments and realized what you're 
doing is correct.


Re: TimeDuration stuff: Re: svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Posted by Adam Heath <do...@brainfood.com>.
Adrian Crum wrote:
> Adam Heath wrote:
>> doogie@apache.org wrote:
>>> Author: doogie
>>> Date: Wed Feb 17 17:23:39 2010
>>> New Revision: 911089
>>>
>>> URL: http://svn.apache.org/viewvc?rev=911089&view=rev
>>> Log:
>>> Rename millis parameters everywhere to milliseconds.  Also rename the
>>> millis method.
>>
>> At this point, I'm mostly done with TimeDuration.  However, there's
>> one more thing I have to do.  The contract for java.lang.Object says
>> that if you implement equals, you must implement hashCode against the
>> same set of fields.  TimeDuration doesn't currently do this.
>>
>> So, while trying to figure out how to do that exactly, I started
>> adding some helper methods to UtilObject to make hashCode of multiple
>> fields easier.  Before that happened tho, I decided to write full test
>> cases for UtilObject.
>>
>> So, TimeDuration and UtilObject now have full coverage.
> 
> By the way, now that I fixed the epoch bug, don't you think we can put
> advanceCalendar back the way it was? The units argument will always be
> positive now.

Yeah, I saw what you did.  I was about to commit my flood, but you
just beat me.  There is still full coverage, however, which means my
version of the fix is still being run(all lines, all branches).  I
haven't had time to try and remove it and see if everything still
succeeds.  It might be that there isn't enough testing, and your fix
actually fixes something else.

Re: TimeDuration stuff: Re: svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Posted by Adrian Crum <ad...@hlmksw.com>.
Adam Heath wrote:
> doogie@apache.org wrote:
>> Author: doogie
>> Date: Wed Feb 17 17:23:39 2010
>> New Revision: 911089
>>
>> URL: http://svn.apache.org/viewvc?rev=911089&view=rev
>> Log:
>> Rename millis parameters everywhere to milliseconds.  Also rename the
>> millis method.
> 
> At this point, I'm mostly done with TimeDuration.  However, there's
> one more thing I have to do.  The contract for java.lang.Object says
> that if you implement equals, you must implement hashCode against the
> same set of fields.  TimeDuration doesn't currently do this.
> 
> So, while trying to figure out how to do that exactly, I started
> adding some helper methods to UtilObject to make hashCode of multiple
> fields easier.  Before that happened tho, I decided to write full test
> cases for UtilObject.
> 
> So, TimeDuration and UtilObject now have full coverage.

By the way, now that I fixed the epoch bug, don't you think we can put 
advanceCalendar back the way it was? The units argument will always be 
positive now.

Re: TimeDuration stuff: Re: svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Posted by Adam Heath <do...@brainfood.com>.
Adrian Crum wrote:
> Adam Heath wrote:
>> doogie@apache.org wrote:
>>> Author: doogie
>>> Date: Wed Feb 17 17:23:39 2010
>>> New Revision: 911089
>>>
>>> URL: http://svn.apache.org/viewvc?rev=911089&view=rev
>>> Log:
>>> Rename millis parameters everywhere to milliseconds.  Also rename the
>>> millis method.
>>
>> At this point, I'm mostly done with TimeDuration.  However, there's
>> one more thing I have to do.  The contract for java.lang.Object says
>> that if you implement equals, you must implement hashCode against the
>> same set of fields.  TimeDuration doesn't currently do this.
>>
>> So, while trying to figure out how to do that exactly, I started
>> adding some helper methods to UtilObject to make hashCode of multiple
>> fields easier.  Before that happened tho, I decided to write full test
>> cases for UtilObject.
> 
> Thank you for all your work!

I don't need thanks.  What I would like, however, is for people to
start doing things similiar to what I do.  I try to provide examples
of how to work the with community software.

Re: TimeDuration stuff: Re: svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Posted by Adrian Crum <ad...@hlmksw.com>.
Adam Heath wrote:
> doogie@apache.org wrote:
>> Author: doogie
>> Date: Wed Feb 17 17:23:39 2010
>> New Revision: 911089
>>
>> URL: http://svn.apache.org/viewvc?rev=911089&view=rev
>> Log:
>> Rename millis parameters everywhere to milliseconds.  Also rename the
>> millis method.
> 
> At this point, I'm mostly done with TimeDuration.  However, there's
> one more thing I have to do.  The contract for java.lang.Object says
> that if you implement equals, you must implement hashCode against the
> same set of fields.  TimeDuration doesn't currently do this.
> 
> So, while trying to figure out how to do that exactly, I started
> adding some helper methods to UtilObject to make hashCode of multiple
> fields easier.  Before that happened tho, I decided to write full test
> cases for UtilObject.

Thank you for all your work!


TimeDuration stuff: Re: svn commit: r911089 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/util: TimeDuration.java test/TimeDurationTests.java

Posted by Adam Heath <do...@brainfood.com>.
doogie@apache.org wrote:
> Author: doogie
> Date: Wed Feb 17 17:23:39 2010
> New Revision: 911089
> 
> URL: http://svn.apache.org/viewvc?rev=911089&view=rev
> Log:
> Rename millis parameters everywhere to milliseconds.  Also rename the
> millis method.

At this point, I'm mostly done with TimeDuration.  However, there's
one more thing I have to do.  The contract for java.lang.Object says
that if you implement equals, you must implement hashCode against the
same set of fields.  TimeDuration doesn't currently do this.

So, while trying to figure out how to do that exactly, I started
adding some helper methods to UtilObject to make hashCode of multiple
fields easier.  Before that happened tho, I decided to write full test
cases for UtilObject.

So, TimeDuration and UtilObject now have full coverage.