1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
36
36
37
37
/**
38
38
* Represents selection over a map or collection.
39
- * For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns [2, 4, 6, 8, 10]
39
+ *
40
+ * <p>For example, <code>{1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this)}</code> evaluates
41
+ * to {@code [2, 4, 6, 8, 10]}.
40
42
*
41
43
* <p>Basically a subset of the input data is returned based on the
42
44
* evaluation of the expression supplied as selection criteria.
@@ -100,11 +102,10 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
100
102
Object val = selectionCriteria .getValueInternal (state ).getValue ();
101
103
if (val instanceof Boolean b ) {
102
104
if (b ) {
105
+ result .put (entry .getKey (), entry .getValue ());
103
106
if (this .variant == FIRST ) {
104
- result .put (entry .getKey (), entry .getValue ());
105
107
return new ValueRef .TypedValueHolderValueRef (new TypedValue (result ), this );
106
108
}
107
- result .put (entry .getKey (), entry .getValue ());
108
109
lastKey = entry .getKey ();
109
110
}
110
111
}
@@ -120,22 +121,22 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
120
121
}
121
122
122
123
if ((this .variant == FIRST || this .variant == LAST ) && result .isEmpty ()) {
123
- return new ValueRef .TypedValueHolderValueRef (new TypedValue ( null ) , this );
124
+ return new ValueRef .TypedValueHolderValueRef (TypedValue . NULL , this );
124
125
}
125
126
126
127
if (this .variant == LAST ) {
127
128
Map <Object , Object > resultMap = new HashMap <>();
128
129
Object lastValue = result .get (lastKey );
129
- resultMap .put (lastKey ,lastValue );
130
- return new ValueRef .TypedValueHolderValueRef (new TypedValue (resultMap ),this );
130
+ resultMap .put (lastKey , lastValue );
131
+ return new ValueRef .TypedValueHolderValueRef (new TypedValue (resultMap ), this );
131
132
}
132
133
133
- return new ValueRef .TypedValueHolderValueRef (new TypedValue (result ),this );
134
+ return new ValueRef .TypedValueHolderValueRef (new TypedValue (result ), this );
134
135
}
135
136
136
137
if (operand instanceof Iterable || ObjectUtils .isArray (operand )) {
137
- Iterable <?> data = (operand instanceof Iterable <?> iterable ?
138
- iterable : Arrays .asList (ObjectUtils .toObjectArray (operand )));
138
+ Iterable <?> data = (operand instanceof Iterable <?> iterable ? iterable :
139
+ Arrays .asList (ObjectUtils .toObjectArray (operand )));
139
140
140
141
List <Object > result = new ArrayList <>();
141
142
int index = 0 ;
0 commit comments