Re: Finding nearest location, calculating distance - best way to store and sort info?

Arturo Pérez <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Well, the extra field is only relevant for the search operation.  But, 
I suppose you could do something like:

class AddressWithDistance {
	Address address;
	float   distance;

	public AddressWithDistance(Address centroid, Address address)
	{
		this.address = address;
		distance = ...calculate distance from centroid...
	}

	public float distance() { return distance; }
}

And then your Comparator could just sort on the distance.


-arturo

On May 4, 2006, at 1:12 AM, Matt Kime wrote:

> I know I'm really showing my java ignorance here but...
>
> can this be done within an object or an an object function? a quick
> trial seems to indicate that it can't be. as i think about it though,
> i guess its fine that it isn't.
>
> many thanks,
> matt
>
>
>> Well, that's what caching/memoization is for.  Rather than sort the
>> items directly, for example,
>> you could put them into a simple Object
>>     private class SortableAddress {
>>           Address address;
>>           float        distanceFromCentroid = -1;
>>     }
>>     then calculate and save the distance into that extra field.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.