[424] in java-interest

home help back first fref pref prev next nref lref last post

Re: SortedVector class

daemon@ATHENA.MIT.EDU (Shaun Terry)
Wed Jun 21 11:37:15 1995

Date: Wed, 21 Jun 95 11:01:26 EDT
From: shaun@calcdev.ml.com (Shaun Terry)
To: cmcmanis@scndprsn.Eng.Sun.COM
Cc: java-interest@java.Eng.Sun.COM


I like your change. It's a bit more of a pain to implement but it's more
flexible and does follow the 'class iterator' way of doing things.

I think that SortedVector ought to have two constructors really:
		SortedVector(Vector v, Object Arbitor) &
		SortedVector(Vector v)

The second constructor allowing for a class which implements
the Sortable interface itself. This wouldn't take away the
flexibility of your change but would allow a developer to make a class
sortable in one way (say, ascending, which you're going to want to do the vast
majority of the time anyway) without having to define a second class.
 
SPT

> 
> 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

home help back first fref pref prev next nref lref last post