Skip to content

Commit fec54e4

Browse files
committed
Merge pull request #336 from msgpack/map-builder-preserves-order
ValueFactory.MapBuilder is preferred to preserve value order
2 parents c819413 + 2ff7ea0 commit fec54e4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

msgpack-core/src/main/java/org/msgpack/value/ValueFactory.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.math.BigInteger;
3030
import java.util.AbstractMap;
3131
import java.util.Arrays;
32-
import java.util.HashMap;
32+
import java.util.LinkedHashMap;
3333
import java.util.Iterator;
3434
import java.util.List;
3535
import java.util.Map;
@@ -191,10 +191,8 @@ public static ImmutableArrayValue emptyArray()
191191
ImmutableMapValue newMap(Map<K, V> map)
192192
{
193193
Value[] kvs = new Value[map.size() * 2];
194-
Iterator<Map.Entry<K, V>> ite = map.entrySet().iterator();
195194
int index = 0;
196-
while (ite.hasNext()) {
197-
Map.Entry<K, V> pair = ite.next();
195+
for (Map.Entry<K, V> pair : map.entrySet()) {
198196
kvs[index] = pair.getKey();
199197
index++;
200198
kvs[index] = pair.getValue();
@@ -253,7 +251,7 @@ public static Map.Entry<Value, Value> newMapEntry(Value key, Value value)
253251

254252
public static class MapBuilder
255253
{
256-
private final Map<Value, Value> map = new HashMap<Value, Value>();
254+
private final Map<Value, Value> map = new LinkedHashMap<Value, Value>();
257255

258256
public MapBuilder() {}
259257

0 commit comments

Comments
 (0)