Skip to content

Commit

Permalink
Fix syntax in Selection/Projection examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Feb 16, 2024
1 parent ab48ac3 commit eefdee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@

/**
* 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 {
Expand All @@ -64,9 +67,9 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException

// 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
/**
* 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
Expand Down

0 comments on commit eefdee7

Please sign in to comment.