[9759] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.preferences;
|
---|
| 3 |
|
---|
[9821] | 4 | import org.openstreetmap.josm.data.Preferences;
|
---|
| 5 |
|
---|
[9759] | 6 | /**
|
---|
| 7 | * Interface for a preference value.
|
---|
| 8 | *
|
---|
| 9 | * Implementations must provide a proper <code>equals</code> method.
|
---|
| 10 | *
|
---|
| 11 | * @param <T> the data type for the value
|
---|
| 12 | * @since 9759
|
---|
| 13 | */
|
---|
| 14 | public interface Setting<T> {
|
---|
| 15 | /**
|
---|
| 16 | * Returns the value of this setting.
|
---|
| 17 | *
|
---|
| 18 | * @return the value of this setting
|
---|
| 19 | */
|
---|
| 20 | T getValue();
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * Check if the value of this Setting object is equal to the given value.
|
---|
| 24 | * @param otherVal the other value
|
---|
| 25 | * @return true if the values are equal
|
---|
| 26 | */
|
---|
[11394] | 27 | default boolean equalVal(T otherVal) {
|
---|
| 28 | return getValue() == null ? (otherVal == null) : getValue().equals(otherVal);
|
---|
| 29 | }
|
---|
[9759] | 30 |
|
---|
| 31 | /**
|
---|
| 32 | * Clone the current object.
|
---|
| 33 | * @return an identical copy of the current object
|
---|
| 34 | */
|
---|
| 35 | Setting<T> copy();
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * Enable usage of the visitor pattern.
|
---|
| 39 | *
|
---|
| 40 | * @param visitor the visitor
|
---|
| 41 | */
|
---|
| 42 | void visit(SettingVisitor visitor);
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * Returns a setting whose value is null.
|
---|
| 46 | *
|
---|
| 47 | * Cannot be static, because there is no static inheritance.
|
---|
| 48 | * @return a Setting object that isn't null itself, but returns null
|
---|
| 49 | * for {@link #getValue()}
|
---|
| 50 | */
|
---|
| 51 | Setting<T> getNullInstance();
|
---|
[9821] | 52 |
|
---|
| 53 | /**
|
---|
| 54 | * Set the time for this setting.
|
---|
| 55 | *
|
---|
| 56 | * For default preferences. They are saved in a cache file. Keeping the
|
---|
| 57 | * time allows to discard very old default settings.
|
---|
| 58 | * @param time the time in seconds since epoch
|
---|
| 59 | */
|
---|
| 60 | void setTime(Long time);
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Get the time for this setting.
|
---|
| 64 | * @return the time for this setting
|
---|
| 65 | * @see #setTime(java.lang.Long)
|
---|
| 66 | */
|
---|
| 67 | Long getTime();
|
---|
| 68 |
|
---|
| 69 | /**
|
---|
| 70 | * Mark setting as new.
|
---|
| 71 | *
|
---|
| 72 | * For default preferences. A setting is marked as new, if it has been seen
|
---|
| 73 | * in the current session.
|
---|
| 74 | * Methods like {@link Preferences#get(java.lang.String, java.lang.String)},
|
---|
| 75 | * can be called from different parts of the code with the same key. In this case,
|
---|
| 76 | * the supplied default value must match. However, this is only an error if the mismatching
|
---|
| 77 | * default value has been seen in the same session (and not loaded from cache).
|
---|
| 78 | * @param isNew true, if it is new
|
---|
| 79 | */
|
---|
| 80 | void setNew(boolean isNew);
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * Return if the setting has been marked as new.
|
---|
| 84 | * @return true, if the setting has been marked as new
|
---|
| 85 | * @see #setNew(boolean)
|
---|
| 86 | */
|
---|
| 87 | boolean isNew();
|
---|
[9759] | 88 | }
|
---|