source: josm/trunk/src/org/openstreetmap/josm/data/preferences/DoubleProperty.java@ 13536

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

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

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