-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FMWK-443 Add configuration flag writeSortedMaps #745
Changes from 2 commits
945377d
681a02d
0c57e1e
d578919
91875bc
d859c63
605e0a1
e3a7d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,12 @@ | |
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.TreeMap; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.aerospike.client.ResultCode.OP_NOT_APPLICABLE; | ||
|
@@ -157,7 +159,12 @@ private void convertToAerospikeWriteData(Object source, AerospikeWriteData data) | |
|
||
private Map<String, Object> convertProperties(TypeInformation<?> type, AerospikePersistentEntity<?> entity, | ||
ConvertingPropertyAccessor<?> accessor, boolean isCustomType) { | ||
Map<String, Object> target = new TreeMap<>(); | ||
Map<String, Object> target; | ||
if (!settings.isWriteTreeMaps()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simpler to check |
||
target = new HashMap<>(); | ||
} else { | ||
target = new TreeMap<>(); | ||
} | ||
typeMapper.writeType(type, target); | ||
entity.doWithProperties((PropertyHandler<AerospikePersistentProperty>) property -> { | ||
|
||
|
@@ -234,7 +241,14 @@ protected Map<Object, Object> convertMap(final Map<Object, Object> source, final | |
Assert.notNull(source, "Given map must not be null!"); | ||
Assert.notNull(type, "Given type must not be null!"); | ||
|
||
return source.entrySet().stream().collect(TreeMap::new, (m, e) -> { | ||
Supplier<Map<Object, Object>> mapSupplier; | ||
if (!settings.isWriteTreeMaps()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
|
||
mapSupplier = HashMap::new; | ||
} else { | ||
mapSupplier = TreeMap::new; | ||
} | ||
Map<Object, Object> map = mapSupplier.get(); | ||
for (Map.Entry<Object, Object> e : source.entrySet()) { | ||
Object key = e.getKey(); | ||
Object value = e.getValue(); | ||
if (key == null) { | ||
|
@@ -260,8 +274,9 @@ protected Map<Object, Object> convertMap(final Map<Object, Object> source, final | |
|
||
Object convertedValue = getValueToWrite(value, type.getMapValueType()); | ||
if (simpleKey instanceof byte[]) simpleKey = ByteBuffer.wrap((byte[]) simpleKey); | ||
m.put(simpleKey, convertedValue); | ||
}, TreeMap::putAll); | ||
map.put(simpleKey, convertedValue); | ||
} | ||
return map; | ||
} | ||
|
||
private Map<String, Object> convertCustomType(Object source, TypeInformation<?> type) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming to
useSortedMap
.