Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–11 unchanged (11 lines)
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.apache.commons.jxpath.ri.compiler;
18
19/**
20 * Base implementation of Expression for the operations ">", ">=", "<", "<=".
21 *
22 * @author Matt Benson
23 * @version $Revision:$ $Date:$
24 */
25public abstract class CoreOperationRelationalExpression extends CoreOperation {
26
27 protected CoreOperationRelationalExpression(Expression[] args) {
28 super(args);
29 }
30
31 protected final int getPrecedence() {
32 return 3;
33 }
34
35 protected final boolean isSymmetric() {
36 return false;
37 }
38
39}
40

After

…lines 1–12 unchanged (12 lines)
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.apache.commons.jxpath.ri.compiler;
18
19import java.util.Collection;
20import java.util.HashSet;
21import java.util.Iterator;
22
23import org.apache.commons.jxpath.ri.EvalContext;
24import org.apache.commons.jxpath.ri.InfoSetUtil;
25import org.apache.commons.jxpath.ri.axes.InitialContext;
26import org.apache.commons.jxpath.ri.axes.SelfContext;
27
28/**
29 * Base implementation of Expression for the operations ">", ">=", "<", "<=".
30 *
31 * @author Matt Benson
32 * @version $Revision:$ $Date:$
33 */
34public abstract class CoreOperationRelationalExpression extends CoreOperation {
35
36 protected CoreOperationRelationalExpression(Expression[] args) {
37 super(args);
38 }
39
40 public final Object computeValue(EvalContext context) {
41 return compute(args[0].computeValue(context), args[1]
42 .computeValue(context)) ? Boolean.TRUE : Boolean.FALSE;
43 }
44
45 protected final int getPrecedence() {
46 return 3;
47 }
48
49 protected final boolean isSymmetric() {
50 return false;
51 }
52
53 protected abstract boolean evaluateCompare(int compare);
54
55 private boolean compute(Object left, Object right) {
56 left = reduce(left);
57 right = reduce(right);
58
59 if (left instanceof InitialContext) {
60 ((InitialContext) left).reset();
61 }
62 if (right instanceof InitialContext) {
63 ((InitialContext) right).reset();
64 }
65 if (left instanceof Iterator && right instanceof Iterator) {
66 return findMatch((Iterator) left, (Iterator) right);
67 }
68 if (left instanceof Iterator) {
69 return containsMatch((Iterator) left, right);
70 }
71 if (right instanceof Iterator) {
72 return containsMatch((Iterator) right, left);
73 }
74 return evaluateCompare(compare(left, right));
75 }
76
77 private Object reduce(Object o) {
78 if (o instanceof SelfContext) {
79 o = ((EvalContext) o).getSingleNodePointer();
80 }
81 if (o instanceof Collection) {
82 o = ((Collection) o).iterator();
83 }
84 return o;
85 }
86
87 private boolean containsMatch(Iterator it, Object value) {
88 while (it.hasNext()) {
89 Object element = it.next();
90 if (evaluateCompare(compare(element, value))) {
91 return true;
92 }
93 }
94 return false;
95 }
96
97 private boolean findMatch(Iterator lit, Iterator rit) {
98 HashSet left = new HashSet();
99 while (lit.hasNext()) {
100 left.add(lit.next());
101 }
102 while (rit.hasNext()) {
103 if (containsMatch(left.iterator(), rit.next())) {
104 return true;
105 }
106 }
107 return false;
108 }
109
110 private int compare(Object l, Object r) {
111 double ld = InfoSetUtil.doubleValue(l);
112 double rd = InfoSetUtil.doubleValue(r);
113 return ld == rd ? 0 : ld < rd ? -1 : 1;
114 }
115
116}
117

Before

program
block_comment "/*\n * Licensed to the Apache Software Foundation (ASF) under"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "jxpath"
. "."
identifier "ri"
. "."
identifier "compiler"
; ";"
block_comment "/**\n * Base implementation of Expression for the operations "...
class_declaration
modifiers
public "public"
abstract "abstract"
class "class"
identifier "CoreOperationRelationalExpression"
superclass
extends "extends"
type_identifier "CoreOperation"
class_body
{ "{"
constructor_declaration (+24 nodes collapsed)
method_declaration
modifiers
protected "protected"
final "final"
integral_type
int "int"
identifier "getPrecedence"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
decimal_integer_literal "3"
; ";"
} "}"
method_declaration
modifiers
protected "protected"
final "final"
boolean_type "boolean"
identifier "isSymmetric"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
false "false"
; ";"
} "}"
} "}"

After

program
block_comment "/*\n * Licensed to the Apache Software Foundation (ASF) under"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "jxpath"
. "."
identifier "ri"
. "."
identifier "compiler"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "HashSet"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Iterator"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "jxpath"
. "."
identifier "ri"
. "."
identifier "EvalContext"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "jxpath"
. "."
identifier "ri"
. "."
identifier "InfoSetUtil"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "jxpath"
. "."
identifier "ri"
. "."
identifier "axes"
. "."
identifier "InitialContext"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "jxpath"
. "."
identifier "ri"
. "."
identifier "axes"
. "."
identifier "SelfContext"
; ";"
block_comment "/**\n * Base implementation of Expression for the operations "...
class_declaration
modifiers
public "public"
abstract "abstract"
class "class"
identifier "CoreOperationRelationalExpression"
superclass
extends "extends"
type_identifier "CoreOperation"
class_body
{ "{"
constructor_declaration (+24 nodes collapsed)
method_declaration
modifiers
public "public"
final "final"
type_identifier "Object"
identifier "computeValue"
formal_parameters
( "("
formal_parameter
type_identifier "EvalContext"
identifier "context"
) ")"
block
{ "{"
return_statement
return "return"
ternary_expression
method_invocation
identifier "compute"
argument_list
( "("
method_invocation
array_access
identifier "args"
[ "["
decimal_integer_literal "0"
] "]"
. "."
identifier "computeValue"
argument_list
( "("
identifier "context"
) ")"
, ","
method_invocation
array_access
identifier "args"
[ "["
decimal_integer_literal "1"
] "]"
. "."
identifier "computeValue"
argument_list
( "("
identifier "context"
) ")"
) ")"
? "?"
field_access
identifier "Boolean"
. "."
identifier "TRUE"
: ":"
field_access
identifier "Boolean"
. "."
identifier "FALSE"
; ";"
} "}"
method_declaration
modifiers
protected "protected"
final "final"
integral_type
int "int"
identifier "getPrecedence"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
decimal_integer_literal "3"
; ";"
} "}"
method_declaration
modifiers
protected "protected"
final "final"
boolean_type "boolean"
identifier "isSymmetric"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
false "false"
; ";"
} "}"
method_declaration
modifiers
protected "protected"
abstract "abstract"
boolean_type "boolean"
identifier "evaluateCompare"
formal_parameters
( "("
formal_parameter
integral_type
int "int"
identifier "compare"
) ")"
; ";"
method_declaration
modifiers
private "private"
boolean_type "boolean"
identifier "compute"
formal_parameters
( "("
formal_parameter
type_identifier "Object"
identifier "left"
, ","
formal_parameter
type_identifier "Object"
identifier "right"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "left"
= "="
method_invocation
identifier "reduce"
argument_list
( "("
identifier "left"
) ")"
; ";"
expression_statement
assignment_expression
identifier "right"
= "="
method_invocation
identifier "reduce"
argument_list
( "("
identifier "right"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
instanceof_expression
identifier "left"
instanceof "instanceof"
type_identifier "InitialContext"
) ")"
block
{ "{"
expression_statement
method_invocation
parenthesized_expression
( "("
cast_expression
( "("
type_identifier "InitialContext"
) ")"
identifier "left"
) ")"
. "."
identifier "reset"
argument_list
( "("
) ")"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
instanceof_expression
identifier "right"
instanceof "instanceof"
type_identifier "InitialContext"
) ")"
block
{ "{"
expression_statement
method_invocation
parenthesized_expression
( "("
cast_expression
( "("
type_identifier "InitialContext"
) ")"
identifier "right"
) ")"
. "."
identifier "reset"
argument_list
( "("
) ")"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
instanceof_expression
identifier "left"
instanceof "instanceof"
type_identifier "Iterator"
&& "&&"
instanceof_expression
identifier "right"
instanceof "instanceof"
type_identifier "Iterator"
) ")"
block
{ "{"
return_statement
return "return"
method_invocation
identifier "findMatch"
argument_list
( "("
cast_expression
( "("
type_identifier "Iterator"
) ")"
identifier "left"
, ","
cast_expression
( "("
type_identifier "Iterator"
) ")"
identifier "right"
) ")"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
instanceof_expression
identifier "left"
instanceof "instanceof"
type_identifier "Iterator"
) ")"
block
{ "{"
return_statement
return "return"
method_invocation
identifier "containsMatch"
argument_list
( "("
cast_expression
( "("
type_identifier "Iterator"
) ")"
identifier "left"
, ","
identifier "right"
) ")"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
instanceof_expression
identifier "right"
instanceof "instanceof"
type_identifier "Iterator"
) ")"
block
{ "{"
return_statement
return "return"
method_invocation
identifier "containsMatch"
argument_list
( "("
cast_expression
( "("
type_identifier "Iterator"
) ")"
identifier "right"
, ","
identifier "left"
) ")"
; ";"
} "}"
return_statement
return "return"
method_invocation
identifier "evaluateCompare"
argument_list
( "("
method_invocation
identifier "compare"
argument_list
( "("
identifier "left"
, ","
identifier "right"
) ")"
) ")"
; ";"
} "}"
method_declaration
modifiers
private "private"
type_identifier "Object"
identifier "reduce"
formal_parameters
( "("
formal_parameter
type_identifier "Object"
identifier "o"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
instanceof_expression
identifier "o"
instanceof "instanceof"
type_identifier "SelfContext"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "o"
= "="
method_invocation
parenthesized_expression
( "("
cast_expression
( "("
type_identifier "EvalContext"
) ")"
identifier "o"
) ")"
. "."
identifier "getSingleNodePointer"
argument_list
( "("
) ")"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
instanceof_expression
identifier "o"
instanceof "instanceof"
type_identifier "Collection"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "o"
= "="
method_invocation
parenthesized_expression
( "("
cast_expression
( "("
type_identifier "Collection"
) ")"
identifier "o"
) ")"
. "."
identifier "iterator"
argument_list
( "("
) ")"
; ";"
} "}"
return_statement
return "return"
identifier "o"
; ";"
} "}"
method_declaration
modifiers
private "private"
boolean_type "boolean"
identifier "containsMatch"
formal_parameters
( "("
formal_parameter
type_identifier "Iterator"
identifier "it"
, ","
formal_parameter
type_identifier "Object"
identifier "value"
) ")"
block
{ "{"
while_statement
while "while"
parenthesized_expression
( "("
method_invocation
identifier "it"
. "."
identifier "hasNext"
argument_list
( "("
) ")"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Object"
variable_declarator
identifier "element"
= "="
method_invocation
identifier "it"
. "."
identifier "next"
argument_list
( "("
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "evaluateCompare"
argument_list
( "("
method_invocation
identifier "compare"
argument_list
( "("
identifier "element"
, ","
identifier "value"
) ")"
) ")"
) ")"
block
{ "{"
return_statement
return "return"
true "true"
; ";"
} "}"
} "}"
return_statement
return "return"
false "false"
; ";"
} "}"
method_declaration
modifiers
private "private"
boolean_type "boolean"
identifier "findMatch"
formal_parameters
( "("
formal_parameter
type_identifier "Iterator"
identifier "lit"
, ","
formal_parameter
type_identifier "Iterator"
identifier "rit"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "HashSet"
variable_declarator
identifier "left"
= "="
object_creation_expression
new "new"
type_identifier "HashSet"
argument_list
( "("
) ")"
; ";"
while_statement
while "while"
parenthesized_expression
( "("
method_invocation
identifier "lit"
. "."
identifier "hasNext"
argument_list
( "("
) ")"
) ")"
block
{ "{"
expression_statement
method_invocation
identifier "left"
. "."
identifier "add"
argument_list
( "("
method_invocation
identifier "lit"
. "."
identifier "next"
argument_list
( "("
) ")"
) ")"
; ";"
} "}"
while_statement
while "while"
parenthesized_expression
( "("
method_invocation
identifier "rit"
. "."
identifier "hasNext"
argument_list
( "("
) ")"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "containsMatch"
argument_list
( "("
method_invocation
identifier "left"
. "."
identifier "iterator"
argument_list
( "("
) ")"
, ","
method_invocation
identifier "rit"
. "."
identifier "next"
argument_list
( "("
) ")"
) ")"
) ")"
block
{ "{"
return_statement
return "return"
true "true"
; ";"
} "}"
} "}"
return_statement
return "return"
false "false"
; ";"
} "}"
method_declaration
modifiers
private "private"
integral_type
int "int"
identifier "compare"
formal_parameters
( "("
formal_parameter
type_identifier "Object"
identifier "l"
, ","
formal_parameter
type_identifier "Object"
identifier "r"
) ")"
block
{ "{"
local_variable_declaration
floating_point_type
double "double"
variable_declarator
identifier "ld"
= "="
method_invocation
identifier "InfoSetUtil"
. "."
identifier "doubleValue"
argument_list
( "("
identifier "l"
) ")"
; ";"
local_variable_declaration
floating_point_type
double "double"
variable_declarator
identifier "rd"
= "="
method_invocation
identifier "InfoSetUtil"
. "."
identifier "doubleValue"
argument_list
( "("
identifier "r"
) ")"
; ";"
return_statement
return "return"
ternary_expression
binary_expression
identifier "ld"
== "=="
identifier "rd"
? "?"
decimal_integer_literal "0"
: ":"
ternary_expression
binary_expression
identifier "ld"
< "<"
identifier "rd"
? "?"
unary_expression
- "-"
decimal_integer_literal "1"
: ":"
decimal_integer_literal "1"
; ";"
} "}"
} "}"