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

Last change on this file was 13002, checked in by bastiK, 7 years ago

see #15229 - remove some uses of Main.pref

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