11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3636
3737/**
3838 * 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]}.
4042 *
4143 * <p>Basically a subset of the input data is returned based on the
4244 * evaluation of the expression supplied as selection criteria.
@@ -100,11 +102,10 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
100102 Object val = selectionCriteria .getValueInternal (state ).getValue ();
101103 if (val instanceof Boolean b ) {
102104 if (b ) {
105+ result .put (entry .getKey (), entry .getValue ());
103106 if (this .variant == FIRST ) {
104- result .put (entry .getKey (), entry .getValue ());
105107 return new ValueRef .TypedValueHolderValueRef (new TypedValue (result ), this );
106108 }
107- result .put (entry .getKey (), entry .getValue ());
108109 lastKey = entry .getKey ();
109110 }
110111 }
@@ -120,22 +121,22 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
120121 }
121122
122123 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 );
124125 }
125126
126127 if (this .variant == LAST ) {
127128 Map <Object , Object > resultMap = new HashMap <>();
128129 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 );
131132 }
132133
133- return new ValueRef .TypedValueHolderValueRef (new TypedValue (result ),this );
134+ return new ValueRef .TypedValueHolderValueRef (new TypedValue (result ), this );
134135 }
135136
136137 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 )));
139140
140141 List <Object > result = new ArrayList <>();
141142 int index = 0 ;
0 commit comments