www.pudn.com > ArchReport.rar > ClosestFind.java
/**
File Name: ClosestFind.java
Author: »ÆÔö²© #B02251132
Date: March 20 2004
Description: The ClosestFind class is used to find the artifact closest
to the provided ArchFind object.
**/
class ClosestFind{
private ArchFind item; // the provide item
private ArchFind closestToItem; // the item closest to 'item'
private double distance; // the distance between the two items
public ClosestFind(ArchFind it){
item = it;
closestToItem = null; //null indicates there are no other items
distance = Double.NaN; // initialize distance to not a number;
}
/* If the find object is closer to the item object than
* closestToItem object, then replace closestToItem by find
*/
public void update(ArchFind find){
//if there is no current item, then find becomes closestToItem
if(closestToItem==null){
closestToItem = find;
distance = closestToItem.distanceBetween(item);
return;
}
/*provide the implementation that check distance,
* and updates closestToItem if necessary
*/
else
if(closestToItem.distanceBetween(item)>find.distanceBetween(item))
closestToItem=find;
}
public ArchFind getClosest(){
return closestToItem;//return closest to item
}
}