001package jmri.util; 002 003import java.util.Comparator; 004 005import jmri.NamedBean; 006 007/** 008 * Compare two NamedBeans using the {@link PreferNumericComparator} against 009 * {@link NamedBean#getSystemName()} for each NamedBean. 010 * <p> 011 * If the requirement is that {@link Comparator#compare(Object, Object)} return 012 * 0 for two numerically identical NamedBean System Names (i.e. 013 * {@code IT42 == IT0042}), use {@link NamedBeanComparator}, but if the 014 * requirement is that System Names should be numerically ordered, but that 015 * non-identical representations of numbers should be different, (i.e. 016 * {@code IT42 != IT0042}, but order should be 017 * {@code IT3, IT4, IT5, IT42, IT0042, IT50}), use this Comparator. 018 * 019 * @author Randall Wood Copyright 2019 020 * @param <B> the type of NamedBean to compare 021 */ 022public class NamedBeanPreferNumericComparator<B extends NamedBean> extends NamedBeanComparator<B> { 023 024 private final PreferNumericComparator comparator = new PreferNumericComparator(); 025 026 @Override 027 public int compare(B n1, B n2) { 028 return comparator.compare(n1.getSystemName(), n2.getSystemName()); 029 } 030 031}