001package jmri.jmrix.bachrus.speedmatcher.speedStepScale;
002
003import jmri.jmrix.bachrus.speedmatcher.SpeedMatcher.SpeedTableStep;
004import static jmri.jmrix.bachrus.speedmatcher.speedStepScale.SpeedStepScaleSpeedMatcher.getSpeedForSpeedTableStep;
005
006/**
007 * Wrapper class for a SpeedTableStep and its corresponding speed, including a
008 * toString override for use in a speed selector combobox.
009 *
010 * @author toddt
011 */
012public class SpeedTableStepSpeed {
013
014    private final SpeedTableStep speedTableStep;
015    private final float speed;
016
017    /**
018     * Creates a SpeedTableStepSpeed from the given speedTableStep
019     * @param speedTableStep the SpeedTableStep to use
020     */
021    public SpeedTableStepSpeed(SpeedTableStep speedTableStep) {
022        this.speedTableStep = speedTableStep;
023        this.speed = getSpeedForSpeedTableStep(this.speedTableStep.getSpeedStep());
024    }
025
026    /**
027     * Gets this SpeedTableStepSpeed's SpeedTableStep
028     * @return this SpeedTableStepSpeed's SpeedTableStep
029     */
030    public SpeedTableStep getSpeedTableStep() {
031        return speedTableStep;
032    }
033
034    /**
035     * Gets this SpeedTableStepSpeed's speed
036     * @return the Speed TableStepSpeed's speed
037     */
038    public float getSpeed() {
039        return speed;
040    }
041
042    /**
043     * Converts this SpeedTableStepSpeed to a string
044     * @return a single decimal string of this SpeedTableStepSpeed's speed
045     */
046    @Override
047    public String toString() {
048        return String.format("%.1f", this.speed);
049    }
050}