📄 xypointcomparator.java
字号:
package com.wrox.algorithms.geometry;import com.wrox.algorithms.sorting.Comparator;/** * A {@link Comparator} that orders {@link Point} objects based on their x coordinates, followed by their y coordinates. * */public final class XYPointComparator implements Comparator { /** The single instance of the class. */ public static final XYPointComparator INSTANCE = new XYPointComparator(); /** * Constructor marked private to prevent instantiation. */ private XYPointComparator() { } public int compare(Object left, Object right) throws ClassCastException { return compare((Point) left, (Point) right); } public int compare(Point p, Point q) throws ClassCastException { assert p != null : "p can't be null"; assert q != null : "q can't be null"; int result = new Double(p.getX()).compareTo(new Double(q.getX())); if (result != 0) { return result; } return new Double(p.getY()).compareTo(new Double(q.getY())); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -