source: josm/trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java@ 12479

Last change on this file since 12479 was 10824, checked in by Don-vip, 8 years ago

see #13309 - Caching and notifying preferences (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.preferences;
3
4import org.openstreetmap.josm.Main;
5
6/**
7 * A property containing an {@code Integer} value.
8 * @since 3246
9 */
10public class IntegerProperty extends AbstractToStringProperty<Integer> {
11
12 /**
13 * Constructs a new {@code IntegerProperty}.
14 * @param key The property key
15 * @param defaultValue The default value
16 */
17 public IntegerProperty(String key, int defaultValue) {
18 super(key, defaultValue);
19 if (Main.pref != null) {
20 get();
21 }
22 }
23
24 @Override
25 public Integer get() {
26 // Removing this implementation breaks binary compatibility
27 return super.get();
28 }
29
30 @Override
31 public boolean put(Integer value) {
32 // Removing this implementation breaks binary compatibility
33 return super.put(value);
34 }
35
36 @Override
37 protected Integer fromString(String string) {
38 try {
39 return Integer.valueOf(string);
40 } catch (NumberFormatException e) {
41 throw new InvalidPreferenceValueException(e);
42 }
43 }
44
45 @Override
46 protected String toString(Integer t) {
47 return t.toString();
48 }
49
50 /**
51 * parses and saves an integer value
52 * @param value the value to be parsed
53 * @return true - preference value has changed
54 * false - parsing failed or preference value has not changed
55 */
56 public boolean parseAndPut(String value) {
57 try {
58 return put(Integer.valueOf(value));
59 } catch (NumberFormatException ex) {
60 return false;
61 }
62 }
63}
Note: See TracBrowser for help on using the repository browser.