[jira] Created: (JEXL-40) JEXL fails to find abstract public methods in the base class if overridden by non-public derived types

2007-11-29 Thread Kohsuke Kawaguchi (JIRA)
JEXL fails to find abstract public methods in the base class if overridden by 
non-public derived types
--

 Key: JEXL-40
 URL: https://issues.apache.org/jira/browse/JEXL-40
 Project: Commons JEXL
  Issue Type: Bug
Affects Versions: 1.1
Reporter: Kohsuke Kawaguchi


If I have a code that fits the following pattern:

{noformat}
public class Base {
  public abstract void foo();
}

class Derived extends Base {
  public void foo() {}
}
{noformat}

JEXL fails to discover the foo method on an instance of Derived, even if this 
method is invokable.

This is because in ClassMap.java, the populateMethodCache method reads:

{noformat}
// Some of the interfaces contain abstract methods. That is fine, because the 
actual object must
// implement them anyway (else it wouldn't be implementing the interface). If 
we find an abstract
// method in a non-interface, we skip it, because we do want to make sure that 
no abstract methods end up in
// the cache.
if (classToReflect.isInterface() || !Modifier.isAbstract(modifiers)) {
{noformat}

The problem can be fixed by simply getting rid this check and always do 
"methodCache.put(methods[i]);"

The comment above doesn't make much sense to me. First, interfaces only contain 
abstract methods by definition. And if interfaces are deemed OK, I don't see 
why abstract methods in the base classes are treated any differently. Given any 
instance that's assignable to the base type, under normal circumstances every 
abstract method is invokable. There's no difference between interfaces and base 
classes on this point.

(The only situation where abstract methods are not implemented is when class 
files were changed in incompatible way)

This pattern of having abstract methods in the base type to be implemented by 
non-public class is a common pattern. So I suggest we simply remove the if 
block shown above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Created: (SANDBOX-204) Cleanup the code

2007-11-29 Thread Siegfried Goeschl (JIRA)
Cleanup the code


 Key: SANDBOX-204
 URL: https://issues.apache.org/jira/browse/SANDBOX-204
 Project: Commons Sandbox
  Issue Type: Improvement
  Components: Exec
Reporter: Siegfried Goeschl
Assignee: Siegfried Goeschl
Priority: Minor


The code looks a bit untidy - broken & missing javadocs, unused imports, 
missing comments - might be a good thing to do past midnight when the family is 
asleep ... :-)



 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Created: (SANDBOX-203) Support for non-standard exit values indicating successful execution

2007-11-29 Thread Siegfried Goeschl (JIRA)
Support for non-standard exit values indicating successful execution


 Key: SANDBOX-203
 URL: https://issues.apache.org/jira/browse/SANDBOX-203
 Project: Commons Sandbox
  Issue Type: Bug
  Components: Exec
Reporter: Siegfried Goeschl
Assignee: Siegfried Goeschl


For printing a PDF document on Windows XP Adobe Acrobat Reader 8.x can be used 
- even when successful the application returns "1" as exit value causing an 
exception in commons-exec. "1" is considered an execution failure and there is 
no way to overwrite the behavior which renders commons-exec useless here. 

PS: Having said that Acrobat Reader 8.x also returns "1" if it can't print ... 
:-( 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Resolved: (LANG-380) infinite loop in Fraction.reduce when numerator == 0

2007-11-29 Thread Matt Benson (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-380?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Benson resolved LANG-380.
--

Resolution: Fixed

> infinite loop in Fraction.reduce when numerator == 0
> 
>
> Key: LANG-380
> URL: https://issues.apache.org/jira/browse/LANG-380
> Project: Commons Lang
>  Issue Type: Bug
>Affects Versions: 2.3
>Reporter: Niall Pemberton
> Fix For: 2.4
>
>
> Summary pretty much says it all.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Created: (LANG-380) infinite loop in Fraction.reduce when numerator == 0

2007-11-29 Thread Matt Benson (JIRA)
infinite loop in Fraction.reduce when numerator == 0


 Key: LANG-380
 URL: https://issues.apache.org/jira/browse/LANG-380
 Project: Commons Lang
  Issue Type: Bug
Affects Versions: 2.3
Reporter: Niall Pemberton
 Fix For: 2.4


Summary pretty much says it all.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Issue Comment Edited: (LANG-379) Calculating A date fragment in any time-unit

2007-11-29 Thread Robert Scholte (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12546780
 ] 

rfscholte-getthere edited comment on LANG-379 at 11/29/07 8:08 AM:
---

There are still some small issues to solve. One of them is proper exception 
handling. This includes UnsupportedFragmentException (or other logic Exception) 
and IllegalArgumentException if date is null. Another exception must be caught 
when the fragment is smaller then the unit (or should it return 0?) Like I 
said: still some enhancements required here.



  was (Author: rfscholte-getthere):
There are still some small issues to solve. One of them is proper exception 
handling. This includes UnsupportedFragmentException (or other logic Exception) 
and IllegalArgumentException if date is null. Another exception must be caught 
when the fragment is smaller then the unit (or should it return 0?) Like I 
said: still same enhancements required here.


  
> Calculating A date fragment in any time-unit
> 
>
> Key: LANG-379
> URL: https://issues.apache.org/jira/browse/LANG-379
> Project: Commons Lang
>  Issue Type: New Feature
>Affects Versions: 2.4
>Reporter: Robert Scholte
>Priority: Minor
> Attachments: DateUtilsFragmentTest.java
>
>
> These DateUtils-features can make it possible to calculate a date-part in any 
> time-unit. For example: the number of minutes of this year, the number of 
> seconds of today, etc.
> I've started with some coding, and if there's enough interest we can make it 
> more solid. 
> public static long getFragmentInSeconds(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.DAY_OF_YEAR);
>   }
>   public static long getFragmentInSeconds(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR);
>   }
>   
>   private static long getFragment(Date date, int fragment, int unit) {
>   Calendar calendar = Calendar.getInstance();
>   calendar.setTime(date);
>   return getFragment(calendar, fragment, unit);
>   }
>   private static long getFragment(Calendar calendar, int fragment, int 
> unit) {
>   long millisPerUnit = getMillisPerFragment(unit);
>   long result = 0;
>   switch (fragment) {
>   case Calendar.YEAR:
>   result += (calendar.get(Calendar.DAY_OF_YEAR) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.MONTH:
>   result += (calendar.get(Calendar.DAY_OF_MONTH) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result += (calendar.get(Calendar.HOUR_OF_DAY) * 
> MILLIS_PER_HOUR) / millisPerUnit;
>   case Calendar.HOUR_OF_DAY:
>   result += (calendar.get(Calendar.MINUTE) * 
> MILLIS_PER_MINUTE) / millisPerUnit;
>   case Calendar.MINUTE:
>   result += (calendar.get(Calendar.SECOND) * 
> MILLIS_PER_SECOND) / millisPerUnit;
>   case Calendar.SECOND:
>   result += (calendar.get(Calendar.MILLISECOND) * 1) / 
> millisPerUnit;
>   }
>   return result;
>   }
>   
>   private static long getMillisPerFragment(int fragment) {
>   long result = Long.MAX_VALUE;
>   switch (fragment) {
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result = MILLIS_PER_DAY;
>   break;
>   case Calendar.HOUR_OF_DAY:
>   result = MILLIS_PER_HOUR;
>   break;
>   case Calendar.

[jira] Commented: (LANG-379) Calculating A date fragment in any time-unit

2007-11-29 Thread Robert Scholte (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12546780
 ] 

Robert Scholte commented on LANG-379:
-

There are still some small issues to solve. One of them is proper exception 
handling. This includes UnsupportedFragmentException (or other logic Exception) 
and IllegalArgumentException if date is null. Another exception must be caught 
when the fragment is smaller then the unit (or should it return 0?) Like I 
said: still same enhancements required here.



> Calculating A date fragment in any time-unit
> 
>
> Key: LANG-379
> URL: https://issues.apache.org/jira/browse/LANG-379
> Project: Commons Lang
>  Issue Type: New Feature
>Affects Versions: 2.4
>Reporter: Robert Scholte
>Priority: Minor
> Attachments: DateUtilsFragmentTest.java
>
>
> These DateUtils-features can make it possible to calculate a date-part in any 
> time-unit. For example: the number of minutes of this year, the number of 
> seconds of today, etc.
> I've started with some coding, and if there's enough interest we can make it 
> more solid. 
> public static long getFragmentInSeconds(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.DAY_OF_YEAR);
>   }
>   public static long getFragmentInSeconds(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR);
>   }
>   
>   private static long getFragment(Date date, int fragment, int unit) {
>   Calendar calendar = Calendar.getInstance();
>   calendar.setTime(date);
>   return getFragment(calendar, fragment, unit);
>   }
>   private static long getFragment(Calendar calendar, int fragment, int 
> unit) {
>   long millisPerUnit = getMillisPerFragment(unit);
>   long result = 0;
>   switch (fragment) {
>   case Calendar.YEAR:
>   result += (calendar.get(Calendar.DAY_OF_YEAR) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.MONTH:
>   result += (calendar.get(Calendar.DAY_OF_MONTH) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result += (calendar.get(Calendar.HOUR_OF_DAY) * 
> MILLIS_PER_HOUR) / millisPerUnit;
>   case Calendar.HOUR_OF_DAY:
>   result += (calendar.get(Calendar.MINUTE) * 
> MILLIS_PER_MINUTE) / millisPerUnit;
>   case Calendar.MINUTE:
>   result += (calendar.get(Calendar.SECOND) * 
> MILLIS_PER_SECOND) / millisPerUnit;
>   case Calendar.SECOND:
>   result += (calendar.get(Calendar.MILLISECOND) * 1) / 
> millisPerUnit;
>   }
>   return result;
>   }
>   
>   private static long getMillisPerFragment(int fragment) {
>   long result = Long.MAX_VALUE;
>   switch (fragment) {
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result = MILLIS_PER_DAY;
>   break;
>   case Calendar.HOUR_OF_DAY:
>   result = MILLIS_PER_HOUR;
>   break;
>   case Calendar.MINUTE:
>   result = MILLIS_PER_MINUTE;
>   break;
>   case Calendar.SECOND:
>   result = MILLIS_PER_SECOND;
>   break;
>   case Calendar.MILLISECOND:
>   result = 1;
>   break;
>   }
>   return result;
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this emai

[jira] Commented: (LANG-379) Calculating A date fragment in any time-unit

2007-11-29 Thread Paul Benedict (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12546764
 ] 

Paul Benedict commented on LANG-379:


Should the switch statements should throw an exception on the default case? It 
is an assertion error to pass an unsupported fragment.

> Calculating A date fragment in any time-unit
> 
>
> Key: LANG-379
> URL: https://issues.apache.org/jira/browse/LANG-379
> Project: Commons Lang
>  Issue Type: New Feature
>Affects Versions: 2.4
>Reporter: Robert Scholte
>Priority: Minor
> Attachments: DateUtilsFragmentTest.java
>
>
> These DateUtils-features can make it possible to calculate a date-part in any 
> time-unit. For example: the number of minutes of this year, the number of 
> seconds of today, etc.
> I've started with some coding, and if there's enough interest we can make it 
> more solid. 
> public static long getFragmentInSeconds(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.DAY_OF_YEAR);
>   }
>   public static long getFragmentInSeconds(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR);
>   }
>   
>   private static long getFragment(Date date, int fragment, int unit) {
>   Calendar calendar = Calendar.getInstance();
>   calendar.setTime(date);
>   return getFragment(calendar, fragment, unit);
>   }
>   private static long getFragment(Calendar calendar, int fragment, int 
> unit) {
>   long millisPerUnit = getMillisPerFragment(unit);
>   long result = 0;
>   switch (fragment) {
>   case Calendar.YEAR:
>   result += (calendar.get(Calendar.DAY_OF_YEAR) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.MONTH:
>   result += (calendar.get(Calendar.DAY_OF_MONTH) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result += (calendar.get(Calendar.HOUR_OF_DAY) * 
> MILLIS_PER_HOUR) / millisPerUnit;
>   case Calendar.HOUR_OF_DAY:
>   result += (calendar.get(Calendar.MINUTE) * 
> MILLIS_PER_MINUTE) / millisPerUnit;
>   case Calendar.MINUTE:
>   result += (calendar.get(Calendar.SECOND) * 
> MILLIS_PER_SECOND) / millisPerUnit;
>   case Calendar.SECOND:
>   result += (calendar.get(Calendar.MILLISECOND) * 1) / 
> millisPerUnit;
>   }
>   return result;
>   }
>   
>   private static long getMillisPerFragment(int fragment) {
>   long result = Long.MAX_VALUE;
>   switch (fragment) {
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result = MILLIS_PER_DAY;
>   break;
>   case Calendar.HOUR_OF_DAY:
>   result = MILLIS_PER_HOUR;
>   break;
>   case Calendar.MINUTE:
>   result = MILLIS_PER_MINUTE;
>   break;
>   case Calendar.SECOND:
>   result = MILLIS_PER_SECOND;
>   break;
>   case Calendar.MILLISECOND:
>   result = 1;
>   break;
>   }
>   return result;
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Updated: (LANG-379) Calculating A date fragment in any time-unit

2007-11-29 Thread Robert Scholte (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-379?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Robert Scholte updated LANG-379:


Attachment: DateUtilsFragmentTest.java

Some tests

> Calculating A date fragment in any time-unit
> 
>
> Key: LANG-379
> URL: https://issues.apache.org/jira/browse/LANG-379
> Project: Commons Lang
>  Issue Type: New Feature
>Affects Versions: 2.4
>Reporter: Robert Scholte
>Priority: Minor
> Attachments: DateUtilsFragmentTest.java
>
>
> These DateUtils-features can make it possible to calculate a date-part in any 
> time-unit. For example: the number of minutes of this year, the number of 
> seconds of today, etc.
> I've started with some coding, and if there's enough interest we can make it 
> more solid. 
> public static long getFragmentInSeconds(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Date date, int fragment) {
>   return getFragment(date, fragment, Calendar.DAY_OF_YEAR);
>   }
>   public static long getFragmentInSeconds(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.SECOND);
>   }
>   
>   public static long getFragmentInMinutes(Calendar calendar, int 
> fragment) {
>   return getFragment(calendar, fragment, Calendar.MINUTE);
>   }
>   
>   public static long getFragmentInHours(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.HOUR_OF_DAY);
>   }
>   
>   public static long getFragmentInDays(Calendar calendar, int fragment) {
>   return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR);
>   }
>   
>   private static long getFragment(Date date, int fragment, int unit) {
>   Calendar calendar = Calendar.getInstance();
>   calendar.setTime(date);
>   return getFragment(calendar, fragment, unit);
>   }
>   private static long getFragment(Calendar calendar, int fragment, int 
> unit) {
>   long millisPerUnit = getMillisPerFragment(unit);
>   long result = 0;
>   switch (fragment) {
>   case Calendar.YEAR:
>   result += (calendar.get(Calendar.DAY_OF_YEAR) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.MONTH:
>   result += (calendar.get(Calendar.DAY_OF_MONTH) * 
> MILLIS_PER_DAY) / millisPerUnit;
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result += (calendar.get(Calendar.HOUR_OF_DAY) * 
> MILLIS_PER_HOUR) / millisPerUnit;
>   case Calendar.HOUR_OF_DAY:
>   result += (calendar.get(Calendar.MINUTE) * 
> MILLIS_PER_MINUTE) / millisPerUnit;
>   case Calendar.MINUTE:
>   result += (calendar.get(Calendar.SECOND) * 
> MILLIS_PER_SECOND) / millisPerUnit;
>   case Calendar.SECOND:
>   result += (calendar.get(Calendar.MILLISECOND) * 1) / 
> millisPerUnit;
>   }
>   return result;
>   }
>   
>   private static long getMillisPerFragment(int fragment) {
>   long result = Long.MAX_VALUE;
>   switch (fragment) {
>   case Calendar.DAY_OF_YEAR:
>   case Calendar.DATE:
>   result = MILLIS_PER_DAY;
>   break;
>   case Calendar.HOUR_OF_DAY:
>   result = MILLIS_PER_HOUR;
>   break;
>   case Calendar.MINUTE:
>   result = MILLIS_PER_MINUTE;
>   break;
>   case Calendar.SECOND:
>   result = MILLIS_PER_SECOND;
>   break;
>   case Calendar.MILLISECOND:
>   result = 1;
>   break;
>   }
>   return result;
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Created: (LANG-379) Calculating A date fragment in any time-unit

2007-11-29 Thread Robert Scholte (JIRA)
Calculating A date fragment in any time-unit


 Key: LANG-379
 URL: https://issues.apache.org/jira/browse/LANG-379
 Project: Commons Lang
  Issue Type: New Feature
Affects Versions: 2.4
Reporter: Robert Scholte
Priority: Minor


These DateUtils-features can make it possible to calculate a date-part in any 
time-unit. For example: the number of minutes of this year, the number of 
seconds of today, etc.

I've started with some coding, and if there's enough interest we can make it 
more solid. 

public static long getFragmentInSeconds(Date date, int fragment) {
return getFragment(date, fragment, Calendar.SECOND);
}

public static long getFragmentInMinutes(Date date, int fragment) {
return getFragment(date, fragment, Calendar.MINUTE);
}

public static long getFragmentInHours(Date date, int fragment) {
return getFragment(date, fragment, Calendar.HOUR_OF_DAY);
}

public static long getFragmentInDays(Date date, int fragment) {
return getFragment(date, fragment, Calendar.DAY_OF_YEAR);
}

public static long getFragmentInSeconds(Calendar calendar, int 
fragment) {
return getFragment(calendar, fragment, Calendar.SECOND);
}

public static long getFragmentInMinutes(Calendar calendar, int 
fragment) {
return getFragment(calendar, fragment, Calendar.MINUTE);
}

public static long getFragmentInHours(Calendar calendar, int fragment) {
return getFragment(calendar, fragment, Calendar.HOUR_OF_DAY);
}

public static long getFragmentInDays(Calendar calendar, int fragment) {
return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR);
}

private static long getFragment(Date date, int fragment, int unit) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return getFragment(calendar, fragment, unit);
}

private static long getFragment(Calendar calendar, int fragment, int 
unit) {
long millisPerUnit = getMillisPerFragment(unit);
long result = 0;
switch (fragment) {
case Calendar.YEAR:
result += (calendar.get(Calendar.DAY_OF_YEAR) * 
MILLIS_PER_DAY) / millisPerUnit;
case Calendar.MONTH:
result += (calendar.get(Calendar.DAY_OF_MONTH) * 
MILLIS_PER_DAY) / millisPerUnit;
case Calendar.DAY_OF_YEAR:
case Calendar.DATE:
result += (calendar.get(Calendar.HOUR_OF_DAY) * 
MILLIS_PER_HOUR) / millisPerUnit;
case Calendar.HOUR_OF_DAY:
result += (calendar.get(Calendar.MINUTE) * 
MILLIS_PER_MINUTE) / millisPerUnit;
case Calendar.MINUTE:
result += (calendar.get(Calendar.SECOND) * 
MILLIS_PER_SECOND) / millisPerUnit;
case Calendar.SECOND:
result += (calendar.get(Calendar.MILLISECOND) * 1) / 
millisPerUnit;
}
return result;
}

private static long getMillisPerFragment(int fragment) {
long result = Long.MAX_VALUE;
switch (fragment) {
case Calendar.DAY_OF_YEAR:
case Calendar.DATE:
result = MILLIS_PER_DAY;
break;
case Calendar.HOUR_OF_DAY:
result = MILLIS_PER_HOUR;
break;
case Calendar.MINUTE:
result = MILLIS_PER_MINUTE;
break;
case Calendar.SECOND:
result = MILLIS_PER_SECOND;
break;
case Calendar.MILLISECOND:
result = 1;
break;
}
return result;
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Updated: (VALIDATOR-252) Performance improvement of DomainValidator by change the regular expression

2007-11-29 Thread Makoto Uchino (JIRA)

 [ 
https://issues.apache.org/jira/browse/VALIDATOR-252?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Makoto Uchino updated VALIDATOR-252:


Attachment: DomainValidator.java.diff

Patch file for DomainValidator.java for performance improvement.

> Performance improvement of DomainValidator by change the regular expression
> ---
>
> Key: VALIDATOR-252
> URL: https://issues.apache.org/jira/browse/VALIDATOR-252
> Project: Commons Validator
>  Issue Type: Improvement
>  Components: Routines
>Affects Versions: 1.4
> Environment: Windows 2000 Professional, Pentium4 2.4GHz, RAM:512M, 
> Eclipse 3.3m Junit 3.8.1
>Reporter: Makoto Uchino
>Priority: Minor
> Fix For: 1.4
>
> Attachments: DomainValidator.java.diff
>
>
> It seemed to take very long time to match the regular expression when long 
> TLD (consists of around 30-characters over TLD) was specified for 
> DomainValidator, this exponential performance will make it appear that the 
> program has hung.
> The match time improves if it is possible to change DOMAIN_LABEL_REGEX from 
> using (?:) to (?>), as follows.
> DOMAIN_LABEL_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]*\\p{Alnum})*"
> (All unit tests in DomainValidatorTest are succeed even if it changes as 
> shown in the above-mentioned.)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.