Browse Source

Fix syntax in Selection/Projection examples

pull/32294/head
Sam Brannen 2 years ago
parent
commit
eefdee7983
  1. 13
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java
  2. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Selection.java

13
spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java

@ -33,12 +33,15 @@ import org.springframework.util.ObjectUtils;
/** /**
* Represents projection, where a given operation is performed on all elements in some * Represents projection, where a given operation is performed on all elements in some
* input sequence, returning a new sequence of the same size. For example: * input sequence, returning a new sequence of the same size.
* "{1,2,3,4,5,6,7,8,9,10}.!{#isEven(#this)}" returns "[n, y, n, y, n, y, n, y, n, y]" *
* <p>For example: <code>{1,2,3,4,5,6,7,8,9,10}.![#isEven(#this)]</code> evaluates
* to {@code [n, y, n, y, n, y, n, y, n, y]}.
* *
* @author Andy Clement * @author Andy Clement
* @author Mark Fisher * @author Mark Fisher
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen
* @since 3.0 * @since 3.0
*/ */
public class Projection extends SpelNodeImpl { public class Projection extends SpelNodeImpl {
@ -64,9 +67,9 @@ public class Projection extends SpelNodeImpl {
// When the input is a map, we push a special context object on the stack // When the input is a map, we push a special context object on the stack
// before calling the specified operation. This special context object // before calling the specified operation. This special context object
// has two fields 'key' and 'value' that refer to the map entries key // has two fields 'key' and 'value' that refer to the map entry's key
// and value, and they can be referenced in the operation // and value, and they can be referenced in the operation -- for example,
// eg. {'a':'y','b':'n'}.![value=='y'?key:null]" == ['a', null] // {'a':'y', 'b':'n'}.![value == 'y' ? key : null] evaluates to ['a', null].
if (operand instanceof Map<?, ?> mapData) { if (operand instanceof Map<?, ?> mapData) {
List<Object> result = new ArrayList<>(); List<Object> result = new ArrayList<>();
for (Map.Entry<?, ?> entry : mapData.entrySet()) { for (Map.Entry<?, ?> entry : mapData.entrySet()) {

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Selection.java

@ -37,11 +37,11 @@ import org.springframework.util.ObjectUtils;
/** /**
* Represents selection over a map or collection. * Represents selection over a map or collection.
* *
* <p>For example, <code>{1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this)}</code> evaluates * <p>For example, <code>{1,2,3,4,5,6,7,8,9,10}.?[#isEven(#this)]</code> evaluates
* to {@code [2, 4, 6, 8, 10]}. * to {@code [2, 4, 6, 8, 10]}.
* *
* <p>Basically a subset of the input data is returned based on the * <p>Basically a subset of the input data is returned based on the evaluation of
* evaluation of the expression supplied as selection criteria. * the expression supplied as selection criteria.
* *
* @author Andy Clement * @author Andy Clement
* @author Mark Fisher * @author Mark Fisher

Loading…
Cancel
Save