[Fwd: [Smartfrog-checkins] core/components/anubis/src/org/smartfrog/services/anubis/locator/util TimeQueue.java,1.1,1.2]

Steve Loughran <[email protected]> Tue, 28 Feb 2006 15:29:59 +0000
Newsgroups gmane.comp.java.smartfrog.devel
Message-ID <[email protected]>
I'm forwarding this commit to the mail list, and to paul, author of the 
anubis code, to highlight an interesting problem.

1, the original code wouldnt compile under Java1.5, because now its 
Long.compareTo(Long) instead of Long.compareTo(Object).

2. casting the param to (Long) may work, but at the risk of producing 
code on a java1.5 build that would not work on a java1.4 installation 
(it'd be trying to link against Long.compareTo(Long).

3. Casting to a simple Comparable appears to have done the trick. There 
isn't much left in the devious tricks bag if it doesnt.

Anything in our code that uses compareTo() could encounter the same 
problem, as this is now a generified interface.

Paul, if this doesn't build -its my fault :)

-steve

-------- Original Message --------
Subject: [Smartfrog-checkins] 
core/components/anubis/src/org/smartfrog/services/anubis/locator/util 
TimeQueue.java,1.1,1.2
Date: Tue, 28 Feb 2006 15:02:26 +0000
From: Steve Loughran <[email protected]>
To: smartfrog-checkins-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org

Update of 
/cvsroot/smartfrog/core/components/anubis/src/org/smartfrog/services/anubis/locator/util
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31926/components/anubis/src/org/smartfrog/services/anubis/locator/util

Modified Files:
	TimeQueue.java
Log Message:
This is a change to get everything to compile on Java1.5.
In java1.5, Comparable -> Comparable<T>, so Long.CompareTo() now takes a 
Long, and if you try and pass in an object you get a compile time error.
I could have cast the second arg to a Long, but there is a risk that the 
code, if compiled on Java1.5, would not link/run on Java1.4, because now 
TimerQueue is looging for CompareTo(Long) instead of CompareTo(Object).
The workaround is to cast to a Comparable and retain the 
compareTo(Object) method.

Index: TimeQueue.java
===================================================================
RCS file: 
/cvsroot/smartfrog/core/components/anubis/src/org/smartfrog/services/anubis/locator/util/TimeQueue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TimeQueue.java	14 Oct 2005 09:20:21 -0000	1.1
--- TimeQueue.java	28 Feb 2006 15:02:23 -0000	1.2
***************
*** 25,29 ****
   public class TimeQueue extends SortedSetMap {

-     private SetMap queue = null;

       /**
--- 25,28 ----
***************
*** 35,42 ****
           super( new Comparator() {
                          public int compare(Object obj1, Object obj2) {
!                            return ((Long)obj1).compareTo(obj2);
                          }
                          public boolean equals(Object obj1, Object obj2) {
!                            return ((Long)obj1).equals(obj2);
                          }
                  } );
--- 34,42 ----
           super( new Comparator() {
                          public int compare(Object obj1, Object obj2) {
!                            Comparable c=(Comparable) obj1;
!                            return c.compareTo(obj2);
                          }
                          public boolean equals(Object obj1, Object obj2) {
!                            return obj1.equals(obj2);
                          }
                  } );




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642