⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 naturalcomparator.java

📁 BOOK:Beginning Algorithms Code Examples
💻 JAVA
字号:
package com.wrox.algorithms.sorting;/** * A {@link Comparator} that compares objects that have a natural sort order, ie. implement {@link Comparable}. * */public final class NaturalComparator implements Comparator {    /** The single, publicly accessible, instance of the comparator. */    public static final NaturalComparator INSTANCE = new NaturalComparator();    /**     * Constructor marked private to prevent instantiation.     */    private NaturalComparator() {    }    public int compare(Object left, Object right) throws ClassCastException {        assert left != null : "left can't be null";        assert right != null : "right can't be null";        return ((Comparable) left).compareTo(right);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -