forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubleValue.java
More file actions
66 lines (55 loc) · 1.48 KB
/
DoubleValue.java
File metadata and controls
66 lines (55 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* Every number with a point or a exponential format is a DoubleValue
*/
public class DoubleValue extends ASTNodeAccessImpl implements Expression {
private Double value;
private String stringValue;
public DoubleValue() {
// empty constructor
}
public DoubleValue(final String value) {
if (value == null || value.length() == 0) {
throw new IllegalArgumentException("value can neither be null nor empty.");
}
String val = value;
if (val.charAt(0) == '+') {
val = val.substring(1);
}
this.value = Double.parseDouble(val);
this.stringValue = val;
}
public DoubleValue(final double value) {
this.value = value;
this.stringValue = String.valueOf(value);
}
@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
public double getValue() {
return value;
}
public void setValue(Double d) {
value = d;
stringValue = String.valueOf(value);
}
@Override
public String toString() {
return stringValue;
}
public DoubleValue withValue(Double value) {
this.setValue(value);
return this;
}
}