001package jmri.jmrit.symbolicprog;
002
003/**
004 * Enum for which numbers should be shown on the speed table.
005 * 
006 * @author Daniel Bergqvist (C) 2021
007 */
008public enum SpeedTableNumbers {
009    
010    None(Bundle.getMessage("SpeedTable_None"), (index) -> {return false;}),
011    All(Bundle.getMessage("SpeedTable_All"), (index) -> {return true;}),
012    Only1of3(Bundle.getMessage("SpeedTable_1of3"), (index) -> {return (index % 3) == 0;}),
013    Only1of7(Bundle.getMessage("SpeedTable_1of7"), (index) -> {
014        int index1 = index+1;   // index is 0 <= x < count;  index1 is 1 <= x <= count.
015        return (index1 == 1) || (index1 == 7) || (index1 == 14) || (index1 == 21) || (index1 == 28);
016    });
017    
018    private final String label;
019    private final Filter filter;
020    
021    private SpeedTableNumbers(String label, Filter filter) {
022        this.label = label;
023        this.filter = filter;
024    }
025    
026    @Override
027    public String toString() {
028        return label;
029    }
030    
031    public boolean filter(int index) {
032        return filter.filter(index);
033    }
034    
035    
036    private static interface Filter {
037        boolean filter(int index);
038    }
039    
040}