Polishing
This commit is contained in:
parent
d5cb1d9adb
commit
81cdfafa78
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,7 +22,8 @@ import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates an object and a {@link TypeDescriptor} that describes it.
|
* Encapsulates an object and a {@link TypeDescriptor} that describes it.
|
||||||
* The type descriptor can contain generic declarations that would not
|
*
|
||||||
|
* <p>The type descriptor can contain generic declarations that would not
|
||||||
* be accessible through a simple {@code getClass()} call on the object.
|
* be accessible through a simple {@code getClass()} call on the object.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -36,7 +36,9 @@ import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents selection over a map or collection.
|
* Represents selection over a map or collection.
|
||||||
* For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns [2, 4, 6, 8, 10]
|
*
|
||||||
|
* <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
|
* <p>Basically a subset of the input data is returned based on the
|
||||||
* evaluation of the expression supplied as selection criteria.
|
* evaluation of the expression supplied as selection criteria.
|
||||||
|
@ -100,11 +102,10 @@ public class Selection extends SpelNodeImpl {
|
||||||
Object val = selectionCriteria.getValueInternal(state).getValue();
|
Object val = selectionCriteria.getValueInternal(state).getValue();
|
||||||
if (val instanceof Boolean b) {
|
if (val instanceof Boolean b) {
|
||||||
if (b) {
|
if (b) {
|
||||||
|
result.put(entry.getKey(), entry.getValue());
|
||||||
if (this.variant == FIRST) {
|
if (this.variant == FIRST) {
|
||||||
result.put(entry.getKey(), entry.getValue());
|
|
||||||
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result), this);
|
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result), this);
|
||||||
}
|
}
|
||||||
result.put(entry.getKey(), entry.getValue());
|
|
||||||
lastKey = entry.getKey();
|
lastKey = entry.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,22 +121,22 @@ public class Selection extends SpelNodeImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this.variant == FIRST || this.variant == LAST) && result.isEmpty()) {
|
if ((this.variant == FIRST || this.variant == LAST) && result.isEmpty()) {
|
||||||
return new ValueRef.TypedValueHolderValueRef(new TypedValue(null), this);
|
return new ValueRef.TypedValueHolderValueRef(TypedValue.NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.variant == LAST) {
|
if (this.variant == LAST) {
|
||||||
Map<Object, Object> resultMap = new HashMap<>();
|
Map<Object, Object> resultMap = new HashMap<>();
|
||||||
Object lastValue = result.get(lastKey);
|
Object lastValue = result.get(lastKey);
|
||||||
resultMap.put(lastKey,lastValue);
|
resultMap.put(lastKey, lastValue);
|
||||||
return new ValueRef.TypedValueHolderValueRef(new TypedValue(resultMap),this);
|
return new ValueRef.TypedValueHolderValueRef(new TypedValue(resultMap), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result),this);
|
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operand instanceof Iterable || ObjectUtils.isArray(operand)) {
|
if (operand instanceof Iterable || ObjectUtils.isArray(operand)) {
|
||||||
Iterable<?> data = (operand instanceof Iterable<?> iterable ?
|
Iterable<?> data = (operand instanceof Iterable<?> iterable ? iterable :
|
||||||
iterable : Arrays.asList(ObjectUtils.toObjectArray(operand)));
|
Arrays.asList(ObjectUtils.toObjectArray(operand)));
|
||||||
|
|
||||||
List<Object> result = new ArrayList<>();
|
List<Object> result = new ArrayList<>();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
Loading…
Reference in New Issue