001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.osm; 003 004import java.io.Serializable; 005import java.util.Comparator; 006 007/** 008 * Provides some node order , based on coordinates, nodes with equal coordinates are equal. 009 * 010 * @author viesturs 011 */ 012public class NodePositionComparator implements Comparator<Node>, Serializable { 013 014 private static final long serialVersionUID = 1L; 015 016 @Override 017 public int compare(Node n1, Node n2) { 018 019 if (n1.getCoor().equalsEpsilon(n2.getCoor())) 020 return 0; 021 022 double dLat = n1.getCoor().lat() - n2.getCoor().lat(); 023 if (dLat > 0) 024 return 1; 025 if (dLat < 0) 026 return -1; 027 double dLon = n1.getCoor().lon() - n2.getCoor().lon(); 028 if (dLon == 0) 029 return 0; 030 return dLon > 0 ? 1 : -1; 031 } 032}