[418] in java-interest
Re: SortedVector class
daemon@ATHENA.MIT.EDU (Chuck McManis)
Tue Jun 20 19:32:36 1995
Date: Tue, 20 Jun 1995 15:58:40 -0700
From: cmcmanis@scndprsn.Eng.Sun.COM (Chuck McManis)
To: shaun@calcdev.ml.com
Cc: java-interest@java.Eng.Sun.COM
Looks cool although I'd probably change in just a teensy tiny way :-)
public interface Sortable {
int compareObjects(Object a, Object b) ;
}
I would make the SortedVector add the constants:
public final int SWAP = 1;
public final int DONT_SWAP = 0;
Now make the constructor take an object that is the "sort" arbitrator
that implements interface Sortable and returns one of SWAP of DONT_SWAP.
Then you can define :
public class AscendingStringSorter implements Sortable {
int compareObjects(Object a, Object b) {
if (! ((a instanceof String) && (b instanceOf String)))
throw new SortableException();
if (a.compareTo(b) < 0)
return (SortedVector.SWAP);
else
return (SortedVector.DONT_SWAP);
}
}
And you can use it by new SortedVector(Vector v, Object Arbitor);
Then build a sorter for Strings or whatever and the base class need
never know its being sorted.
Plus you can implement the sort policy in the arbitor object and do things
like numeric sort or alpha sort one strings etc.
What do you think?
--Chuck
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com