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