001package jmri.util.startup;
002
003import java.util.ArrayList;
004import java.util.List;
005import javax.annotation.Nonnull;
006
007/**
008 * Abstract startup action model.
009 *
010 * @author Randall Wood (c) 2016
011 */
012public abstract class AbstractStartupModel implements StartupModel {
013
014    private String name;
015    private boolean enabled = true;
016    private final List<Exception> exceptions = new ArrayList<>();
017
018    protected AbstractStartupModel() {
019        this.name = null;
020    }
021
022    @Override
023    public String getName() {
024        return this.name;
025    }
026
027    @Override
028    public void setName(String name) {
029        this.name = name;
030    }
031
032    @Override
033    @Nonnull
034    public String toString() {
035        String string = this.getName();
036        if (string == null) {
037            return super.toString();
038        }
039        return string;
040    }
041
042    /**
043     * {@inheritDoc}
044     *
045     * The default behavior is to return true if {@link #getName()} returns a
046     * non-null, non-empty String.
047     *
048     * @return true if valid; false otherwise
049     */
050    @Override
051    public boolean isValid() {
052        String s = this.getName();
053        return s != null && !s.isEmpty();
054    }
055
056    /** {@inheritDoc} */
057    @Override
058    public void setEnabled(boolean value) {
059        enabled = value;
060    }
061
062    /** {@inheritDoc} */
063    @Override
064    public boolean isEnabled() {
065        return enabled;
066    }
067
068    @Override
069    public List<Exception> getExceptions() {
070        return new ArrayList<>(this.exceptions);
071    }
072
073    @Override
074    public void addException(@Nonnull Exception exception) {
075        this.exceptions.add(exception);
076    }
077}