<pre>public Person findNearestAvailable(int location) { Iterator<Person> it = persons.iterator(); int nearestDistance = Integer.MAX_VALUE; Person nearestAssistant = null; while(it.hasNext()) // checks all persons { Person person = it.next(); if(person.isAvailable()) //but only the availalble ones { int distance = location - person.getLocation(); if(distance < nearestDistance){ nearestDistance = distance; nearestPerson = person; } } } return nearestPerson; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)