source: josm/trunk/src/org/openstreetmap/josm/spi/preferences/Setting.java @ 12881

Last change on this file since 12881 was 12881, checked in by bastiK, 11 months ago

see #15229 - move remaining classes to spi.preferences package, to make it self-contained

  • extract event listener classes from Preferences (duplicated, for smooth transition)
  • move *Setting classes
  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.spi.preferences;
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
10 * @since xxx (moved from package {@code org.openstreetmap.josm.data.preferences})
11 */
12public 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     */
25    default boolean equalVal(T otherVal) {
26        return getValue() == null ? (otherVal == null) : getValue().equals(otherVal);
27    }
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 IPreferences#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}
Note: See TracBrowser for help on using the repository browser.