1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.preferences;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.Preferences;
|
---|
5 |
|
---|
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 | */
|
---|
27 | boolean equalVal(T otherVal);
|
---|
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();
|
---|
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.
|
---|
72 | * Methods like {@link Preferences#get(java.lang.String, java.lang.String)},
|
---|
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();
|
---|
86 | }
|
---|