[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
QSort question from yesterday still unsolved
From: |
Paul E Johnson |
Subject: |
QSort question from yesterday still unsolved |
Date: |
Thu, 02 Aug 2001 14:05:34 -0500 |
Concerning MA's question from yesterday, I've gotten a few follow up
emails, still have not figured it out. I'd be inclined to look for
sorting tools native to Java, but since the Swarm QSort is there, I
wonder how to use it, like everybody else.
The QSort usage in java is not easy. In Objective-C, QSort is a class
method, and I've looked at the example of the java usage of NSelect
(http://lark.cc.ukans.edu/~pauljohn/SwarmFaq/WorkingExampleCode/java/NSelectUsage.txt)
as an example of how a class method might be used in Java. I guess that
the basics of the usage should be something like:
new QSortImpl().sortObjectsIn$using (aList, sel );
but the problem is that I was getting a lot of compiler messages about
the usage of an IVAR sel in a static context.
So I kept working on this test program to try to make the sel use
statics thing so I wouldn't get that complaint, and ended up with this
(ugly?) that does compile but gets a runtime error. I think the print
statements show that the selector and class are found, but the runtime
error is in the QSortImpl usage. I tried at this for a while and I'm
ready to ask for anybody's insights.
import swarm.Globals;
import swarm.simtools.NSelectImpl;
import swarm.simtools.QSortImpl;
import swarm.simtools.QSort;
import swarm.Selector;
import java.util.List;
import java.util.LinkedList;
import java.util.ListIterator;
import java.lang.Integer;
public class TestQSort {
static void main (String args[]) {
Globals.env.initSwarm ("TestQSort", "address@hidden", "0.0",
args);
List aList = new LinkedList ();
List bList = new LinkedList ();
for (int i = 0; i < 100; i++)
aList.add (new Integer (i));
Class myClass = getMyClass();
Selector sel = getASelector(myClass,"comparison");
new QSortImpl().sortObjectsIn$using (aList, sel );
ListIterator index = bList.listIterator ();
while (index.hasNext ()) {
System.out.println (index.next ());
}
}
public int comparison (Integer a, Integer b ) {
if (a.intValue() < b.intValue()) return -1;
else if (a.intValue() > b.intValue()) return 1;
else return 0;
}
static Selector getASelector(Class a, String s) {
Selector newsel=null;
try {
newsel = new Selector (a,s,false);
System.out.println("My selector is " + newsel + " \n");
}
catch (Exception e) {
System.out.println("Failure");
}
return newsel;
}
static Class getMyClass(){
Class aClass=null;
try{
aClass = Class.forName("TestQSort");
System.out.println("My Class is " + aClass + " \n");
}catch (Exception e){
System.out.println("Failure2");
}
return aClass;
}
}
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
- QSort question from yesterday still unsolved,
Paul E Johnson <=