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