You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tr...@thinkvirtual.com on 2002/11/14 05:21:07 UTC

Conversion utilities

I also have a package of conversion classes that convert different measurements from imperial to metric and vice versa for things like Length, Pressure, Force, etc.

And along with that I have a Fraction and FractionFormat class that deals with fractions (parsing, formatting, etc).

Wonder if commons might be a good fit for that?

Travis Reeder


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [lang] Money/Units/Quantities [was Re: Conversion utilities]

Posted by Stephen Colebourne <sc...@btopenworld.com>.
+1, I've got some code too that I can merge in to fill any gaps.
I suggest we keep this in the [lang-sandbox] with CalendarUtils for the
moment.
Stephen

----- Original Message -----
From: "Steven Caswell" <st...@caswell.name>
> I have a Money class that I can contribute to get the ball rolling.
>
>
> Steven Caswell
> steven@caswell.name
> a.k.a Mungo Knotwise of Michel Delving
> "One ring to rule them all, one ring to find them..."
>
>
> > -----Original Message-----
> > From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
> > Sent: Thursday, November 14, 2002 4:29 PM
> > To: Jakarta Commons Developers List
> > Subject: [lang] Money/Units/Quantities [was Re: Conversion utilities]
> >
> >
> > http://www.dautelle.com/jade is the most well known units and
> > quantities package. It also follows the JSR on the subject.
> > In some ways, it would be nice to see this work brought under
> > the Jakarta Commons group, as there is much useful code there.
> >
> > Even if we don't intend to have a whole units package in
> > [lang], we should probably have Money and Currency classes.
> > They are pretty fundamental to many business applications. (I
> > don't think that a [money] is required here
> > ??)
> >
> > Stephen
> >
> > ----- Original Message -----
> > From: "Henri Yandell" <ba...@generationjava.com>
> > To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> > Cc: <ya...@studylink.com>
> > Sent: Thursday, November 14, 2002 7:54 PM
> > Subject: Re: Conversion utilities
> >
> >
> > >
> > >
> > > On Thu, 14 Nov 2002, Jeff Varszegi wrote:
> > >
> > > > Janek,
> > > >
> > > > I made an interface called Range that is supported by
> > classes called
> > > > ComparableRange etc.  The ComparableRange class can use
> > any objects
> > > > that support Comparable (or, alternately, any objects with a
> > > > supplied Comparator), and I also made specific versions
> > for Date and
> > > > Double to
> > >
> > > +1. Why did no one think of this before? We're all fined one weeks
> > > +pay.
> > >
> > > > eliminate unnecessary casting.  I needed the Date one for
> > code I'm
> > > > writing.  I didn't get the time to implement any for
> > primitive types
> > > > yet.
> > >
> > > > Range supports disjoint ranges of values, checking to see
> > if a value
> > > > falls within the range, merging two ranges, etc.
> > >
> > > So this is like NumberRange, but genericises it and makes it cool?
> > >
> > > > I will send my code as soon as I can-- right now I'm setting up a
> > > > home network, and my laptop isn't on it yet.  In the
> > meantime, can
> > > > you post the CurrencyRange code you've got?  Thanks a lot. I
> > > > definitely think it will be of general-purpose
> > application.  I don't
> > > > know of any quantities library either, but I'd be
> > thrilled to take a
> > > > look at one.
> > >
> > > Jade's the only one I've heard of. By a guy over in .fr I
> > think. For
> > > quantities that is, always heard good things of it.
> > >
> > > Hen
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:commons-dev-> unsubscribe@jakarta.apache.org>
> > For
> > additional commands,
> > e-mail: <ma...@jakarta.apache.org>
> >
> >
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [lang] Money/Units/Quantities [was Re: Conversion utilities]

Posted by Steven Caswell <st...@caswell.name>.
I have a Money class that I can contribute to get the ball rolling.


Steven Caswell
steven@caswell.name
a.k.a Mungo Knotwise of Michel Delving
"One ring to rule them all, one ring to find them..."


> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
> Sent: Thursday, November 14, 2002 4:29 PM
> To: Jakarta Commons Developers List
> Subject: [lang] Money/Units/Quantities [was Re: Conversion utilities]
> 
> 
> http://www.dautelle.com/jade is the most well known units and 
> quantities package. It also follows the JSR on the subject. 
> In some ways, it would be nice to see this work brought under 
> the Jakarta Commons group, as there is much useful code there.
> 
> Even if we don't intend to have a whole units package in 
> [lang], we should probably have Money and Currency classes. 
> They are pretty fundamental to many business applications. (I 
> don't think that a [money] is required here
> ??)
> 
> Stephen
> 
> ----- Original Message -----
> From: "Henri Yandell" <ba...@generationjava.com>
> To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> Cc: <ya...@studylink.com>
> Sent: Thursday, November 14, 2002 7:54 PM
> Subject: Re: Conversion utilities
> 
> 
> >
> >
> > On Thu, 14 Nov 2002, Jeff Varszegi wrote:
> >
> > > Janek,
> > >
> > > I made an interface called Range that is supported by 
> classes called 
> > > ComparableRange etc.  The ComparableRange class can use 
> any objects 
> > > that support Comparable (or, alternately, any objects with a 
> > > supplied Comparator), and I also made specific versions 
> for Date and 
> > > Double to
> >
> > +1. Why did no one think of this before? We're all fined one weeks 
> > +pay.
> >
> > > eliminate unnecessary casting.  I needed the Date one for 
> code I'm 
> > > writing.  I didn't get the time to implement any for 
> primitive types 
> > > yet.
> >
> > > Range supports disjoint ranges of values, checking to see 
> if a value 
> > > falls within the range, merging two ranges, etc.
> >
> > So this is like NumberRange, but genericises it and makes it cool?
> >
> > > I will send my code as soon as I can-- right now I'm setting up a 
> > > home network, and my laptop isn't on it yet.  In the 
> meantime, can 
> > > you post the CurrencyRange code you've got?  Thanks a lot. I 
> > > definitely think it will be of general-purpose 
> application.  I don't 
> > > know of any quantities library either, but I'd be 
> thrilled to take a 
> > > look at one.
> >
> > Jade's the only one I've heard of. By a guy over in .fr I 
> think. For 
> > quantities that is, always heard good things of it.
> >
> > Hen
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:commons-dev-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[lang] Money/Units/Quantities [was Re: Conversion utilities]

Posted by Stephen Colebourne <sc...@btopenworld.com>.
http://www.dautelle.com/jade is the most well known units and quantities
package. It also follows the JSR on the subject. In some ways, it would be
nice to see this work brought under the Jakarta Commons group, as there is
much useful code there.

Even if we don't intend to have a whole units package in [lang], we should
probably have Money and Currency classes. They are pretty fundamental to
many business applications. (I don't think that a [money] is required here
??)

Stephen

----- Original Message -----
From: "Henri Yandell" <ba...@generationjava.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Cc: <ya...@studylink.com>
Sent: Thursday, November 14, 2002 7:54 PM
Subject: Re: Conversion utilities


>
>
> On Thu, 14 Nov 2002, Jeff Varszegi wrote:
>
> > Janek,
> >
> > I made an interface called Range that is supported by classes called
> > ComparableRange etc.  The ComparableRange class can use any objects
> > that support Comparable (or, alternately, any objects with a supplied
> > Comparator), and I also made specific versions for Date and Double to
>
> +1. Why did no one think of this before? We're all fined one weeks pay.
>
> > eliminate unnecessary casting.  I needed the Date one for code I'm
> > writing.  I didn't get the time to implement any for primitive types
> > yet.
>
> > Range supports disjoint ranges of values, checking to see if a
> > value falls within the range, merging two ranges, etc.
>
> So this is like NumberRange, but genericises it and makes it cool?
>
> > I will send my code as soon as I can-- right now I'm setting up a home
> > network, and my laptop isn't on it yet.  In the meantime, can you post
> > the CurrencyRange code you've got?  Thanks a lot. I definitely think
> > it will be of general-purpose application.  I don't know of any
> > quantities library either, but I'd be thrilled to take a look at one.
>
> Jade's the only one I've heard of. By a guy over in .fr I think.
> For quantities that is, always heard good things of it.
>
> Hen
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Conversion utilities

Posted by Robert Leland <rl...@apache.org>.
Henri Yandell wrote:
> 
> On Thu, 14 Nov 2002, Jeff Varszegi wrote:
> 
> 
>>Janek,
>>
>>I made an interface called Range that is supported by classes called
>>ComparableRange etc.  The ComparableRange class can use any objects
>>that support Comparable (or, alternately, any objects with a supplied
>>Comparator), and I also made specific versions for Date and Double to

Sounds like you could coordinating with the commons-validator package
there is already a intRange(), floatRange(), in the GenerocValidator 
class. It could definately make use of your Range interface though !


-Rob


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Conversion utilities

Posted by Janek Bogucki <ya...@studylink.com>.
On Thursday 14 November 2002  7:54 pm, Henri Yandell wrote:
> Jade's the only one I've heard of. By a guy over in .fr I think.
> For quantities that is, always heard good things of it.
>
> Hen

I had a look at this library while looking for a CurrencyRange class. It did 
not have that but did have lots of other interesting stuff including a 
Duration class

   http://nanotitan.com/software/Libraries/quantity/

These are the available DurationUnits

SECONDS
DAYS
DAYS_MEAN_SOLAR
DAYS_SIDEREAL
HOURS
HOURS_MEAN_SOLAR
HOURS_SIDEREAL
MILLISECONDS
MINUTES
MINUTES_MEAN_SOLAR
MINUTES_SIDEREAL
NANOSECONDS
PLANCK_TIME
SECONDS
SECONDS_SIDEREAL
YEARS_CALENDAR
YEARS_SIDEREAL
YEARS_TROPICAL
           
but then for CurrencyUnits it just has US cents and dollars!

-Janek

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Conversion utilities

Posted by Henri Yandell <ba...@generationjava.com>.

On Thu, 14 Nov 2002, Jeff Varszegi wrote:

> Janek,
>
> I made an interface called Range that is supported by classes called
> ComparableRange etc.  The ComparableRange class can use any objects
> that support Comparable (or, alternately, any objects with a supplied
> Comparator), and I also made specific versions for Date and Double to

+1. Why did no one think of this before? We're all fined one weeks pay.

> eliminate unnecessary casting.  I needed the Date one for code I'm
> writing.  I didn't get the time to implement any for primitive types
> yet.

> Range supports disjoint ranges of values, checking to see if a
> value falls within the range, merging two ranges, etc.

So this is like NumberRange, but genericises it and makes it cool?

> I will send my code as soon as I can-- right now I'm setting up a home
> network, and my laptop isn't on it yet.  In the meantime, can you post
> the CurrencyRange code you've got?  Thanks a lot. I definitely think
> it will be of general-purpose application.  I don't know of any
> quantities library either, but I'd be thrilled to take a look at one.

Jade's the only one I've heard of. By a guy over in .fr I think.
For quantities that is, always heard good things of it.

Hen


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Conversion utilities

Posted by Jeff Varszegi <jv...@yahoo.com>.
Janek,

I made an interface called Range that is supported by classes called ComparableRange etc.  The
ComparableRange class can use any objects that support Comparable (or, alternately, any objects
with a supplied Comparator), and I also made specific versions for Date and Double to eliminate
unnecessary casting.  I needed the Date one for code I'm writing.  I didn't get the time to
implement any for primitive types yet.  Range supports disjoint ranges of values, checking to see
if a value falls within the range, merging two ranges, etc.  

I will send my code as soon as I can-- right now I'm setting up a home network, and my laptop
isn't on it yet.  In the meantime, can you post the CurrencyRange code you've got?  Thanks a lot.
I definitely think it will be of general-purpose application.  I don't know of any quantities
library either, but I'd be thrilled to take a look at one.

Your friend,
Jeff

--- Janek Bogucki <ya...@studylink.com> wrote:
> Hi Travis,
> 
> On Thursday 14 November 2002  4:21 am, travis@thinkvirtual.com wrote:
> > I also have a package of conversion classes that convert different
> > measurements from imperial to metric and vice versa for things like Length,
> > Pressure, Force, etc.
> >
> > And along with that I have a Fraction and FractionFormat class that deals
> > with fractions (parsing, formatting, etc).
> >
> > Wonder if commons might be a good fit for that?
> >
> > Travis Reeder
> >
> >
> > --
> > To unsubscribe, e-mail:  
> > <ma...@jakarta.apache.org> For additional
> > commands, e-mail: <ma...@jakarta.apache.org>
> 
> Let me add some more stuff that might be the basis for something.
> 
> I need to represent currency ranges (in various currencies using the 
> ISO 4217 currency codes), and duration ranges (with various units: hours, 
> days, months, years).
> 
> I imagine the CurrencyRange would go like this
> 
> CONCEPTUAL API:
> 
> public interface CurrencyRange {
> 
> 
>   // ---------------------------
>   // Property Getters
>   // ---------------------------
> 
>   Currency getCurrency();
> 
>   o.a.c.lang.NumberRange getRange ();
> 
> }
> 
> The Currency class would be similar to java.util.Currency, but would be 
> available for JDK 1.3.1 users (me).
> 
> CurrencyRange would be immutable and possibly final (I've sketched it as an 
> interface above for discussion). Since my needs are completely covered by the 
> two properties above I have not added any further operations.
> 
> The DurationRange would be similar:
> 
> CONCEPTUAL APIs:
> 
> public interface DurationRange {
> 
> 
>   // ---------------------------
>   // Property Getters
>   // ---------------------------
> 
>   DurationUnitEnum getUnit();
> 
>   o.a.c.lang.NumberRange getRange ();
> 
> }
> 
> The constructor could be like this
> 
>   DurationRange ( DurationUnitEnum, NumberRange range ) ;
> 
> (Once again DurationRange is likely to be a final class, not an interface.)
> 
> Travis' CalenderUtils.getRange ( int field, Date from, Date to ) method could 
> be used in a factory method on DurationRange
> 
>   /**
>    * Return a DurationRange where min==max and min == to - from, and field is
>    * from Calender.
>    */
>   public static DurationRange getInstance ( int field, Date from, Date to )
> 
>   /**
>    * Return a DurationRange where field is from Calender.
>    */
>   public static DurationRange getInstance ( int field, long min, long ) ;
> 
> 
> For DurationUnitEnum:
> 
> import java.util.Calendar ;
> 
> public final class DurationUnitEnum extends ValuedEnum {
> 
>    // enums based on code in Travis' CalendarUtils.getRange
>    public static final int  DURATION_UNIT_SECOND_VALUE  = Calendar.SECOND ;
>    public static final int  DURATION_UNIT_MINUTE_VALUE  = Calendar.MINUTE ;
>    public static final int  DURATION_UNIT_HOUR_VALUE    = Calendar.HOUR ;
>    public static final int  DURATION_UNIT_DAY_VALUE     = Calendar.DAY ;
>    public static final int  DURATION_UNIT_WEEK_VALUE    = Calendar.WEEK ;
>    public static final int  DURATION_UNIT_MONTH_VALUE   = Calendar.MONTH ;
>    public static final int  DURATION_UNIT_YEAR_VALUE    = Calendar.YEAR ;
> 
>  
>    public static final DurationUnitEnum DURATION_UNIT_SECOND
>         = new DurationUnitEnum
>                  ( "Seconds", DURATION_UNIT_SECOND_VALUE );
> 
>    <snip/>
> 
>    public static final DurationUnitEnum DURATION_UNIT_YEAR
>         = new DurationUnitEnum
>                  ( "Years", DURATION_UNIT_YEAR_VALUE );
> 
>    private DurationUnitEnum name, int value) {
>      super( name, value );
>    }
>  
>    public static DurationUnitEnum getEnum(String durationUnit) {
>      return (DurationUnitEnum) getEnum(DurationUnitEnum.class, durationUnit); 
>    }
>  
>    public static DurationUnitEnum getEnum(int durationUnit) {
>      return (DurationUnitEnum) getEnum(DurationUnitEnum.class, durationUnit);
>    }
>  
>    public static Map getEnumMap() {
>      return getEnumMap(DurationUnitEnum.class);
>    }
>  
>    public static List getEnumList() {
>      return getEnumList(DurationUnitEnum.class);
>    }
>  
>    public static Iterator iterator() {
>      return iterator(DurationUnitEnum.class);
>    }
>  }
>  
> I'd be happy to contribute the basic attempt at CurrencyRange, if there is 
> interest and it doesn't overlap with anything else already in existance.
> 
> If anyone can point at a quantities library with this in already i'd be very 
> happy.
> 
> -Janek
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Conversion utilities

Posted by Janek Bogucki <ya...@studylink.com>.
Hi Travis,

On Thursday 14 November 2002  4:21 am, travis@thinkvirtual.com wrote:
> I also have a package of conversion classes that convert different
> measurements from imperial to metric and vice versa for things like Length,
> Pressure, Force, etc.
>
> And along with that I have a Fraction and FractionFormat class that deals
> with fractions (parsing, formatting, etc).
>
> Wonder if commons might be a good fit for that?
>
> Travis Reeder
>
>
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org> For additional
> commands, e-mail: <ma...@jakarta.apache.org>

Let me add some more stuff that might be the basis for something.

I need to represent currency ranges (in various currencies using the 
ISO 4217 currency codes), and duration ranges (with various units: hours, 
days, months, years).

I imagine the CurrencyRange would go like this

CONCEPTUAL API:

public interface CurrencyRange {


  // ---------------------------
  // Property Getters
  // ---------------------------

  Currency getCurrency();

  o.a.c.lang.NumberRange getRange ();

}

The Currency class would be similar to java.util.Currency, but would be 
available for JDK 1.3.1 users (me).

CurrencyRange would be immutable and possibly final (I've sketched it as an 
interface above for discussion). Since my needs are completely covered by the 
two properties above I have not added any further operations.

The DurationRange would be similar:

CONCEPTUAL APIs:

public interface DurationRange {


  // ---------------------------
  // Property Getters
  // ---------------------------

  DurationUnitEnum getUnit();

  o.a.c.lang.NumberRange getRange ();

}

The constructor could be like this

  DurationRange ( DurationUnitEnum, NumberRange range ) ;

(Once again DurationRange is likely to be a final class, not an interface.)

Travis' CalenderUtils.getRange ( int field, Date from, Date to ) method could 
be used in a factory method on DurationRange

  /**
   * Return a DurationRange where min==max and min == to - from, and field is
   * from Calender.
   */
  public static DurationRange getInstance ( int field, Date from, Date to )

  /**
   * Return a DurationRange where field is from Calender.
   */
  public static DurationRange getInstance ( int field, long min, long ) ;


For DurationUnitEnum:

import java.util.Calendar ;

public final class DurationUnitEnum extends ValuedEnum {

   // enums based on code in Travis' CalendarUtils.getRange
   public static final int  DURATION_UNIT_SECOND_VALUE  = Calendar.SECOND ;
   public static final int  DURATION_UNIT_MINUTE_VALUE  = Calendar.MINUTE ;
   public static final int  DURATION_UNIT_HOUR_VALUE    = Calendar.HOUR ;
   public static final int  DURATION_UNIT_DAY_VALUE     = Calendar.DAY ;
   public static final int  DURATION_UNIT_WEEK_VALUE    = Calendar.WEEK ;
   public static final int  DURATION_UNIT_MONTH_VALUE   = Calendar.MONTH ;
   public static final int  DURATION_UNIT_YEAR_VALUE    = Calendar.YEAR ;

 
   public static final DurationUnitEnum DURATION_UNIT_SECOND
        = new DurationUnitEnum
                 ( "Seconds", DURATION_UNIT_SECOND_VALUE );

   <snip/>

   public static final DurationUnitEnum DURATION_UNIT_YEAR
        = new DurationUnitEnum
                 ( "Years", DURATION_UNIT_YEAR_VALUE );

   private DurationUnitEnum name, int value) {
     super( name, value );
   }
 
   public static DurationUnitEnum getEnum(String durationUnit) {
     return (DurationUnitEnum) getEnum(DurationUnitEnum.class, durationUnit); 
   }
 
   public static DurationUnitEnum getEnum(int durationUnit) {
     return (DurationUnitEnum) getEnum(DurationUnitEnum.class, durationUnit);
   }
 
   public static Map getEnumMap() {
     return getEnumMap(DurationUnitEnum.class);
   }
 
   public static List getEnumList() {
     return getEnumList(DurationUnitEnum.class);
   }
 
   public static Iterator iterator() {
     return iterator(DurationUnitEnum.class);
   }
 }
 
I'd be happy to contribute the basic attempt at CurrencyRange, if there is 
interest and it doesn't overlap with anything else already in existance.

If anyone can point at a quantities library with this in already i'd be very 
happy.

-Janek


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>