source: trunk/src/org/expeditee/simple/SString.java@ 1506

Last change on this file since 1506 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 2.2 KB
Line 
1/**
2 * SString.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
19package org.expeditee.simple;
20
21public class SString extends SPrimitive<String> {
22 public static String prefix = SVariable.prefix + "s" + SVariable.separator;
23
24 Double doubleValue_ = null;
25
26 public SString() {
27 super();
28 }
29
30 public SString(String name, String value) {
31 super(name, value);
32 }
33
34 public SString(String value) /* throws Exception */{
35 super(value);
36 }
37
38 @Override
39 public void parse(String s) {
40 value_ = s;
41 doubleValue_ = null;
42 }
43
44 @Override
45 public Boolean booleanValue() {
46 return Boolean.parseBoolean(value_);
47 }
48
49 @Override
50 public Long integerValue() {
51 if (value_.equals(""))
52 return 0L;
53 try {
54 return Long.decode(value_);
55 } catch (NumberFormatException ne) {
56 }
57 return Math.round(Double.parseDouble(value_));
58 }
59
60 @Override
61 public Double doubleValue() {
62 if (doubleValue_ != null)
63 return doubleValue_;
64
65 if (value_.equals(""))
66 doubleValue_ = 0.0;
67 else {
68 try {
69 doubleValue_ = Double.parseDouble(value_);
70 } catch (NumberFormatException ne) {
71 try{
72 doubleValue_ =(double) Long.decode(value_);
73 }catch(Exception e){
74 doubleValue_ = Double.NaN;
75 }
76 }
77 }
78 return doubleValue_;
79 }
80
81 @Override
82 public String stringValue() {
83 return value_;
84 }
85
86 @Override
87 public Character characterValue() {
88 if (value_.length() > 0)
89 return value_.charAt(0);
90
91 return '\0';
92 }
93
94 @Override
95 public void setValue(SPrimitive v) {
96 value_ = v.stringValue();
97 doubleValue_ = null;
98 }
99
100 public int length() {
101 return value_.length();
102 }
103}
Note: See TracBrowser for help on using the repository browser.