001package jmri.util;
002
003import java.util.Comparator;
004
005import jmri.NamedBean;
006
007/**
008 * Comparator for JMRI NamedBeans via their System Names.
009 * <p>
010 * Uses the built-in Comparable interface of the named beans.
011 * <p>
012 * A System Name is a system prefix followed by type letter then a suffix with a
013 * system-specific format. This class first compares on prefix, then if the
014 * prefixes are equal it compares the type letter, then if they're still equal
015 * it does an {@link AlphanumComparator} compare on suffix.
016 * <p>
017 * This sorts on the information in the NamedBean itself, including using the
018 * actual type by deferring prefix comparison into the specific NamedBean
019 * subclass. This is different from the (deprecated) SystemNameComparator, which
020 * only does a common lexical sort. See the
021 * <a href="http://jmri.org/help/en/html/doc/Technical/Names.shtml">Names
022 * documentation page</a>.
023 * 
024 * @param <B> supported type of NamedBean
025 */
026public class NamedBeanComparator <B extends NamedBean> implements Comparator<B> {
027
028    @Override
029    public int compare(B n1, B n2) {
030        return n1.compareTo(n2);
031    }
032}