Skip to content

Commit 0ef852a

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-2623 - Add support for $function and $accumulator aggregation operators.
Original pull request: #887.
1 parent 26f0a1c commit 0ef852a

File tree

5 files changed

+689
-0
lines changed

5 files changed

+689
-0
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AbstractAggregationExpression.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,48 @@ protected java.util.Map<String, Object> append(String key, Object value) {
140140

141141
}
142142

143+
protected java.util.Map<String, Object> remove(String key) {
144+
145+
Assert.isInstanceOf(Map.class, this.value, "Value must be a type of Map!");
146+
147+
java.util.Map<String, Object> clone = new LinkedHashMap<>((java.util.Map) this.value);
148+
clone.remove(key);
149+
return clone;
150+
}
151+
152+
/**
153+
* Append the given key at the position in the underlying {@link LinkedHashMap}.
154+
*
155+
* @param index
156+
* @param key
157+
* @param value
158+
* @return
159+
* @since 3.1
160+
*/
161+
protected java.util.Map<String, Object> appendAt(int index, String key, Object value) {
162+
163+
Assert.isInstanceOf(Map.class, this.value, "Value must be a type of Map!");
164+
165+
java.util.LinkedHashMap<String, Object> clone = new java.util.LinkedHashMap<>();
166+
167+
int i = 0;
168+
for (Map.Entry<String, Object> entry : ((java.util.Map<String, Object>) this.value).entrySet()) {
169+
170+
if (i == index) {
171+
clone.put(key, value);
172+
}
173+
if (!entry.getKey().equals(key)) {
174+
clone.put(entry.getKey(), entry.getValue());
175+
}
176+
i++;
177+
}
178+
if (i <= index) {
179+
clone.put(key, value);
180+
}
181+
return clone;
182+
183+
}
184+
143185
protected List<Object> values() {
144186

145187
if (value instanceof List) {

0 commit comments

Comments
 (0)