[ale] OT, but not as OT as recent stuff (JAVA)

Master Wizard mainwizard at vei.net
Thu Nov 7 21:24:41 EST 2002


Why use Long's at all.
Depending on the need, BigDecimal or BigInteger would probably be better 
and they have a built-in subtract method. If the hash stores a 
BigDecimal, you could do the following:

long rez = 
(((BigDecimal)hash.get(key)).subtract((BigDecimal)hash2.get(key))).longValue().

There are also many other convienience methods for rounding, precision, 
scale and others.

Ed.

Geoffrey wrote:

> Sorry for the delay in my thanks, but thanks for the solution that at 
> least two other folks suggested as well, this worked.
> 
> Mazukna, Thomas wrote:
> 
>> You can not put primitive types into Hashtable, only objects, so you
>> probably store Long.
>>
>> hash.put( key , new Long( 1000 ) );
>>
>> When you get back an Object form hashtable cast it back to correct type:
>>
>> Long one = (Long)hash.get(key);
>> Long two = (Long) hash2.get(key);
>> long rez = one.longValue() - two.longValue();
>>
>> or one pass
>> long rez = ((Long)hash.get(key)).longValue() -
>> ((Long)hash2.get(key)).longValue();
>>
>> Tomas
>>
>> -----Original Message-----
>> From: Geoffrey [mailto:esoteric at 3times25.net]
>> Sent: Thursday, October 31, 2002 3:56 PM
>> To: Mazukna, Thomas
>> Cc: ALE
>> Subject: Re: [ale] OT, but not as OT as recent stuff (JAVA)
>>
>>
>>
>>
>> Mazukna, Thomas wrote:
>>
>>> how did you managed to put number into the Object ? where is the value ?
>>
>>
>>
>> The object is returned by a hashtable.  Basically need to do this:
>>
>> longvar[0] = hash.get(key) - hash2.get(anotherkey);
>>
>> The values returned are large numbers (data transfer counts).
>>
>>
>>> Tomas
>>>
>>> -----Original Message-----
>>> From: Geoffrey [mailto:esoteric at 3times25.net]
>>> Sent: Thursday, October 31, 2002 2:55 PM
>>> To: ALE
>>> Subject: [ale] OT, but not as OT as recent stuff (JAVA)
>>>
>>>
>>> Okay Java gurus, I've come to the conclusion Java was designed to 
>>> drive you insane whenever you need to convert types.  I'm trying to 
>>> take two java.lang.Objects which are a series of numbers subtract one 
>>> from the other and store the result in a long value.  I've tried:
>>>
>>> (long)theObject
>>> (Long)theObject
>>> Long.parseLong(theObject)
>>>
>>> I'm exhausted....
>>>
>>> Enlightenment would be blessed...
>>>
>>
>>
> 




---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list