Last change
on this file since 8404 was 8390, checked in by Don-vip, 9 years ago |
Sonar - various performance improvements
|
-
Property svn:eol-style
set to
native
|
File size:
1.1 KB
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.preferences;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * A property containing an {@code Integer} value.
|
---|
8 | * @since 3246
|
---|
9 | */
|
---|
10 | public class IntegerProperty extends AbstractProperty<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 | }
|
---|
20 |
|
---|
21 | @Override
|
---|
22 | public Integer get() {
|
---|
23 | return Main.pref.getInteger(getKey(), getDefaultValue());
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public boolean put(Integer value) {
|
---|
28 | return Main.pref.putInteger(getKey(), value);
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * parses and saves an integer value
|
---|
33 | * @param value the value to be parsed
|
---|
34 | * @return true - preference value has changed
|
---|
35 | * false - parsing failed or preference value has not changed
|
---|
36 | */
|
---|
37 | public boolean parseAndPut(String value) {
|
---|
38 | try {
|
---|
39 | return put(Integer.valueOf(value));
|
---|
40 | } catch (NumberFormatException ex) {
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.