15
15
*/
16
16
public class MapExpr extends AbstractExpression {
17
17
18
- protected List <Mapping > mappings = new ArrayList (13 );
18
+ private final List <Mapping > mappings = new ArrayList <> (13 );
19
19
20
- public MapExpr (XQueryContext context ) {
20
+ public MapExpr (final XQueryContext context ) {
21
21
super (context );
22
22
}
23
23
24
- public void map (PathExpr key , PathExpr value ) {
24
+ public void map (final PathExpr key , final PathExpr value ) {
25
25
final Mapping mapping = new Mapping (key .simplify (), value .simplify ());
26
26
this .mappings .add (mapping );
27
27
}
28
28
29
- public void analyze (AnalyzeContextInfo contextInfo ) throws XPathException {
30
- if (getContext ().getXQueryVersion () < 30 ){
29
+ @ Override
30
+ public void analyze (final AnalyzeContextInfo contextInfo ) throws XPathException {
31
+ if (getContext ().getXQueryVersion () < 30 ) {
31
32
throw new XPathException (this , ErrorCodes .EXXQDY0003 ,
32
- "Map is not available before XQuery 3.0" );
33
+ "Map is not available before XQuery 3.0" );
33
34
}
34
35
contextInfo .setParent (this );
35
36
for (final Mapping mapping : this .mappings ) {
@@ -38,35 +39,40 @@ public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
38
39
}
39
40
}
40
41
41
- public Sequence eval (Sequence contextSequence , Item contextItem ) throws XPathException {
42
- if (contextItem != null )
43
- {contextSequence = contextItem .toSequence ();}
42
+ @ Override
43
+ public Sequence eval (Sequence contextSequence , final Item contextItem ) throws XPathException {
44
+ if (contextItem != null ) {
45
+ contextSequence = contextItem .toSequence ();
46
+ }
44
47
final MapType map = new MapType (this .context );
45
48
for (final Mapping mapping : this .mappings ) {
46
49
final Sequence key = mapping .key .eval (contextSequence );
47
- if (key .getItemCount () != 1 )
48
- {throw new XPathException (MapErrorCode .EXMPDY001 , "Expected single value for key, got " + key .getItemCount ());}
50
+ if (key .getItemCount () != 1 ) {
51
+ throw new XPathException (MapErrorCode .EXMPDY001 , "Expected single value for key, got " + key .getItemCount ());
52
+ }
49
53
final AtomicValue atomic = key .itemAt (0 ).atomize ();
50
54
final Sequence value = mapping .value .eval (contextSequence );
51
55
map .add (atomic , value );
52
56
}
53
57
return map ;
54
58
}
55
59
60
+ @ Override
56
61
public int returnsType () {
57
62
return Type .MAP ;
58
63
}
59
64
60
65
@ Override
61
- public void accept (ExpressionVisitor visitor ) {
66
+ public void accept (final ExpressionVisitor visitor ) {
62
67
super .accept (visitor );
63
- for (final Mapping mapping : this .mappings ) {
68
+ for (final Mapping mapping : this .mappings ) {
64
69
mapping .key .accept (visitor );
65
70
mapping .value .accept (visitor );
66
71
}
67
72
}
68
73
69
- public void dump (ExpressionDumper dumper ) {
74
+ @ Override
75
+ public void dump (final ExpressionDumper dumper ) {
70
76
dumper .display ("map {" );
71
77
for (final Mapping mapping : this .mappings ) {
72
78
mapping .key .dump (dumper );
@@ -77,7 +83,7 @@ public void dump(ExpressionDumper dumper) {
77
83
}
78
84
79
85
@ Override
80
- public void resetState (boolean postOptimization ) {
86
+ public void resetState (final boolean postOptimization ) {
81
87
super .resetState (postOptimization );
82
88
mappings .forEach (m -> m .resetState (postOptimization ));
83
89
}
@@ -86,12 +92,12 @@ private static class Mapping {
86
92
final Expression key ;
87
93
final Expression value ;
88
94
89
- public Mapping (Expression key , Expression value ) {
95
+ public Mapping (final Expression key , final Expression value ) {
90
96
this .key = key ;
91
97
this .value = value ;
92
98
}
93
99
94
- private void resetState (boolean postOptimization ) {
100
+ private void resetState (final boolean postOptimization ) {
95
101
key .resetState (postOptimization );
96
102
value .resetState (postOptimization );
97
103
}
0 commit comments