1 | /**
|
---|
2 | * SReal.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.simple;
|
---|
20 |
|
---|
21 | public class SReal extends SPrimitive<Double> {
|
---|
22 | public static String prefix = SVariable.prefix + "r" + SVariable.separator;
|
---|
23 |
|
---|
24 | public SReal() {
|
---|
25 | super();
|
---|
26 | }
|
---|
27 |
|
---|
28 | public SReal(String name, Double value) {
|
---|
29 | super(name, value);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public SReal(double value) throws Exception {
|
---|
33 | super(value);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public SReal(float value) throws Exception {
|
---|
37 | super((double) value);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public void parse(String s) throws Exception {
|
---|
42 | if (s.equals(""))
|
---|
43 | value_ = 0.0;
|
---|
44 | else {
|
---|
45 | try {
|
---|
46 | value_ = Double.parseDouble(s);
|
---|
47 | } catch (NumberFormatException ne) {
|
---|
48 | value_ = (double) Long.decode(s);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public Boolean booleanValue() {
|
---|
55 | return value_ > 0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public Long integerValue() {
|
---|
60 | return Math.round(value_);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Double doubleValue() {
|
---|
65 | return value_;
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public Character characterValue() {
|
---|
70 | return new Character((char) Math.round(value_));
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public void setValue(SPrimitive v) throws IncorrectTypeException {
|
---|
75 | value_ = v.doubleValue();
|
---|
76 | }
|
---|
77 | }
|
---|