1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.peaseplate.internal.lang.command;
21
22 import org.peaseplate.TemplateRuntimeException;
23 import org.peaseplate.locator.TemplateLocator;
24
25 public class GreaterThanCommand extends AbstractCompareCommand {
26
27 public GreaterThanCommand(TemplateLocator locator, int line, int column, ICommand leftCommand, ICommand rightCommand) {
28 super(locator, line, column, leftCommand, rightCommand);
29 }
30
31
32
33
34 @Override
35 public String getSign() {
36 return ">";
37 }
38
39
40
41
42 @Override
43 public Boolean evaluateNull() throws TemplateRuntimeException {
44 return Boolean.FALSE;
45 }
46
47
48
49
50 @SuppressWarnings("unchecked")
51 @Override
52 public <TYPE> Boolean evaluateComparable(Comparable<TYPE> left, Comparable<TYPE> right) throws TemplateRuntimeException {
53 TYPE typedRight = null;
54
55 try {
56 typedRight = (TYPE)right;
57 }
58 catch (ClassCastException e) {
59 Class<?> leftType = (left != null) ? left.getClass() : Void.class;
60 Class<?> rightType = (right != null) ? right.getClass() : Void.class;
61
62 throw new TemplateRuntimeException(
63 getLocator(), getLine(), getColumn(),
64 "Operation " + getSign() + " not supported on operands of type " + leftType + " and " + rightType, e
65 );
66 }
67
68 return Boolean.valueOf(left.compareTo(typedRight) > 0);
69 }
70
71
72
73
74 @Override
75 @SuppressWarnings("unchecked")
76 public Boolean evaluateNonComparable(Object left, Object right) throws TemplateRuntimeException {
77 if ((left instanceof Comparable) && (right instanceof Comparable)) {
78 Comparable<Object> leftComparable = null;
79
80 try {
81 leftComparable = (Comparable<Object>)left;
82 }
83 catch (ClassCastException e) {
84 throw new TemplateRuntimeException(
85 getLocator(), getLine(), getColumn(),
86 "Operation " + getSign() + " not supported on operands of type " + left.getClass() + " and " + right.getClass(), e
87 );
88 }
89
90 return Boolean.valueOf(leftComparable.compareTo(right) > 0);
91 }
92
93 return super.evaluateNonComparable(left, right);
94 }
95
96 }