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; @@ -33,12 +33,15 @@ import org.springframework.util.ObjectUtils;
/**
* 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:
* "{1,2,3,4,5,6,7,8,9,10}.!{#isEven(#this)}" returns "[n, y, n, y, n, y, n, y, n, y]"
* input sequence, returning a new sequence of the same size.
*
* <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 Mark Fisher
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.0
*/
public class Projection extends SpelNodeImpl {
@ -64,9 +67,9 @@ 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
// before calling the specified operation. This special context object
// has two fields 'key' and 'value' that refer to the map entries key
// and value, and they can be referenced in the operation
// eg. {'a':'y','b':'n'}.![value=='y'?key:null]" == ['a', null]
// has two fields 'key' and 'value' that refer to the map entry's key
// and value, and they can be referenced in the operation -- for example,
// {'a':'y', 'b':'n'}.![value == 'y' ? key : null] evaluates to ['a', null].
if (operand instanceof Map<?, ?> mapData) {
List<Object> result = new ArrayList<>();
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; @@ -37,11 +37,11 @@ import org.springframework.util.ObjectUtils;
/**
* 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]}.
*
* <p>Basically a subset of the input data is returned based on the
* evaluation of the expression supplied as selection criteria.
* <p>Basically a subset of the input data is returned based on the evaluation of
* the expression supplied as selection criteria.
*
* @author Andy Clement
* @author Mark Fisher

Loading…
Cancel
Save