001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.spi.preferences;
003
004import java.util.Objects;
005
006/**
007 * Base abstract class of all settings, holding the setting value.
008 *
009 * @param <T> The setting type
010 * @since 12881 (moved from package {@code org.openstreetmap.josm.data.preferences})
011 */
012public abstract class AbstractSetting<T> implements Setting<T> {
013    protected final T value;
014    protected Long time;
015    protected boolean isNew;
016
017    /**
018     * Constructs a new {@code AbstractSetting} with the given value
019     * @param value The setting value
020     */
021    protected AbstractSetting(T value) {
022        this.value = value;
023        this.time = null;
024        this.isNew = false;
025    }
026
027    @Override
028    public T getValue() {
029        return value;
030    }
031
032    @Override
033    public void setTime(Long time) {
034        this.time = time;
035    }
036
037    @Override
038    public Long getTime() {
039        return this.time;
040    }
041
042    @Override
043    public void setNew(boolean isNew) {
044        this.isNew = isNew;
045    }
046
047    @Override
048    public boolean isNew() {
049        return isNew;
050    }
051
052    @Override
053    public String toString() {
054        return value != null ? value.toString() : "null";
055    }
056
057    @Override
058    public int hashCode() {
059        return Objects.hash(value);
060    }
061
062    @Override
063    public boolean equals(Object obj) {
064        if (this == obj)
065            return true;
066        if (obj == null || getClass() != obj.getClass())
067            return false;
068        return Objects.equals(value, ((AbstractSetting<?>) obj).value);
069    }
070}