Skip to content

Commit 2226323

Browse files
committed
Change
1 parent 76f441c commit 2226323

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

server/src/main/java/org/elasticsearch/ingest/ESONSource.java

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.AbstractSet;
2626
import java.util.ArrayList;
2727
import java.util.Collection;
28+
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.Iterator;
3031
import java.util.List;
@@ -494,16 +495,19 @@ public int size() {
494495
@Override
495496
public Set<Entry<String, Object>> entrySet() {
496497
ensureMaterializedMap();
497-
return entrySet(true, false);
498+
return entrySet(false);
498499
}
499500

500-
public Iterable<? extends Entry<?, ?>> entrySetNullInsteadOfRawValues() {
501-
// TODO: Fix
502-
ensureMaterializedMap();
503-
return this.entrySet(false, true);
501+
public Set<Entry<String, Object>> entrySetNullInsteadOfRawValues() {
502+
if (materializedMap == null) {
503+
Map<String, Object> emptyMap = Collections.emptyMap();
504+
return emptyMap.entrySet();
505+
} else {
506+
return entrySet(true);
507+
}
504508
}
505509

506-
private Set<Entry<String, Object>> entrySet(boolean shouldComputeValue, boolean nullForRawValues) {
510+
private Set<Entry<String, Object>> entrySet(boolean nullForRawValues) {
507511
return new AbstractSet<>() {
508512
@Override
509513
public Iterator<Entry<String, Object>> iterator() {
@@ -518,7 +522,7 @@ public boolean hasNext() {
518522
@Override
519523
public Entry<String, Object> next() {
520524
Map.Entry<String, Type> mapEntry = mapIterator.next();
521-
return new LazyEntry(mapEntry.getKey(), mapEntry.getValue(), shouldComputeValue, nullForRawValues);
525+
return new LazyEntry(mapEntry.getKey(), mapEntry.getValue(), nullForRawValues);
522526
}
523527

524528
@Override
@@ -576,15 +580,13 @@ public boolean remove(Object o) {
576580
private class LazyEntry implements Entry<String, Object> {
577581
private final String key;
578582
private final Type type;
579-
private final boolean shouldComputeValue;
580583
private final boolean nullForRawValues;
581584
private Object cachedValue;
582585
private boolean valueComputed = false;
583586

584-
LazyEntry(String key, Type type, boolean shouldComputeValue, boolean nullForRawValues) {
587+
LazyEntry(String key, Type type, boolean nullForRawValues) {
585588
this.key = key;
586589
this.type = type;
587-
this.shouldComputeValue = shouldComputeValue;
588590
this.nullForRawValues = nullForRawValues;
589591
}
590592

@@ -599,10 +601,7 @@ public boolean isRawValue() {
599601

600602
@Override
601603
public Object getValue() {
602-
if (shouldComputeValue == false) {
603-
// assert valueComputed == false;
604-
return type;
605-
} else if (valueComputed == false) {
604+
if (valueComputed == false) {
606605
if (type == null) {
607606
cachedValue = null;
608607
} else if (type instanceof Mutation mutation) {
@@ -622,9 +621,7 @@ public Object getValue() {
622621
@Override
623622
public Object setValue(Object value) {
624623
Object oldValue = ESONObject.this.put(key, value);
625-
if (shouldComputeValue) {
626-
cachedValue = value;
627-
}
624+
cachedValue = value;
628625
return oldValue;
629626
}
630627

@@ -774,11 +771,38 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
774771
}
775772

776773
public Iterator<Object> iteratorNullInsteadOfRawValues() {
777-
// TODO: Fix
778-
ensureMaterializedList();
779-
return iterator();
780-
}
774+
if (materializedList == null) {
775+
return new Iterator<Object>() {
776+
@Override
777+
public boolean hasNext() {
778+
return false;
779+
}
781780

781+
@Override
782+
public Object next() {
783+
return null;
784+
}
785+
};
786+
} else {
787+
Iterator<Type> typeIterator = materializedList.iterator();
788+
return new Iterator<>() {
789+
@Override
790+
public boolean hasNext() {
791+
return typeIterator.hasNext();
792+
}
793+
794+
@Override
795+
public Object next() {
796+
Type next = typeIterator.next();
797+
if (next instanceof VariableValue || next instanceof FixedValue) {
798+
return null;
799+
} else {
800+
return next;
801+
}
802+
}
803+
};
804+
}
805+
}
782806
}
783807

784808
private static Object convertTypeToValue(Type type, Values values) {

0 commit comments

Comments
 (0)