forked from hflicka/arden2bytecode
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathNormalizedArdenValue.java
More file actions
63 lines (57 loc) · 1.84 KB
/
NormalizedArdenValue.java
File metadata and controls
63 lines (57 loc) · 1.84 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
package arden.tests.specification.testcompiler.impl;
import arden.runtime.ArdenDuration;
import arden.runtime.ArdenList;
import arden.runtime.ArdenNumber;
import arden.runtime.ArdenObject;
import arden.runtime.ArdenTime;
import arden.runtime.ArdenValue;
import arden.tests.specification.testcompiler.TestCompilerResult;
/**
* Wrapper to correctly print the normalized internal representation of an ArdenValue. <br>
* e.g. "1 day" -> "86400 seconds"
* @see TestCompilerResult
*/
class NormalizedArdenValue extends ArdenValue {
private ArdenValue value;
public NormalizedArdenValue(ArdenValue value) {
this.value = value;
}
@Override
public ArdenValue setTime(long newPrimaryTime) {
// not used
return null;
}
@Override
public String toString() {
if (value instanceof ArdenList) {
// convert child elements
ArdenList list = (ArdenList) value;
for (int i = 0; i < list.values.length; i++) {
list.values[i] = new NormalizedArdenValue(list.values[i]);
}
return list.toString();
} else if (value instanceof ArdenObject) {
// convert fields
ArdenObject object = (ArdenObject) value;
for (int i = 0; i < object.fields.length; i++) {
object.fields[i] = new NormalizedArdenValue(object.fields[i]);
}
return object.toString();
} else if (value instanceof ArdenDuration) {
// use only internal representation (seconds, months)
ArdenDuration duration = (ArdenDuration) value;
String unit = duration.isMonths? "months" : "seconds";
if (duration.value == 1)
return "1 " + unit.substring(0, unit.length() - 1);
else
return ArdenNumber.toString(duration.value) + " " + unit;
} else if (value instanceof ArdenTime) {
// remove trailing zeros
ArdenTime time = (ArdenTime) value;
if(time.value % 1000 != 0) {
return time.toString().replaceAll("0*$", "");
}
}
return value.toString();
}
}