У меня проблема, и мне нужна помощь ...
У моего объекта есть имя, долгота и широта.Моя проблема в том, что у меня есть массив, в котором есть все объекты внутри, и теперь есть (почти) дубликаты.
Это означает, что long / lat практически одинаковы, но определенно дублируют.
Как я могу отфильтровать их, чтобы получить список с уникальными объектами?Вот что я сделал до сих пор ...
public static Collection<Station> findDuplicates(Collection<Station> stations) {
Collection<Station> uniqueList = new ArrayList<>();
for (Station firstStation : stations) {
Station tempStation = firstStation;
for (Station secondStation : stations) {
//Check if distance of the stations is less than 25m then we assume it's the same and we are going to merge the stations
if ((distanceFrom(firstStation.getLatitude(), firstStation.getLongitude(), secondStation.getLatitude(), secondStation.getLongitude()) < 25)) {
tempStation = mergeStation(firstStation, secondStation);
}
}
}
//How to find/add unique stations to uniqueList
return uniqueList;
}
Заранее спасибо!