Mercurial Hosting > luan
diff core/src/luan/LuanTableImpl.java @ 284:8870840251ea
use LinkedHashMap in LuanTable to preserve order
git-svn-id: https://luan-java.googlecode.com/svn/trunk@285 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 02 Dec 2014 03:55:33 +0000 |
parents | ef39bc4d3f70 |
children | 9fb523472035 |
line wrap: on
line diff
--- a/core/src/luan/LuanTableImpl.java Tue Dec 02 03:34:04 2014 +0000 +++ b/core/src/luan/LuanTableImpl.java Tue Dec 02 03:55:33 2014 +0000 @@ -4,7 +4,6 @@ import java.util.ListIterator; import java.util.Map; import java.util.AbstractMap; -import java.util.HashMap; import java.util.List; import java.util.ArrayList; import java.util.Collections; @@ -24,14 +23,14 @@ /* public LuanTableImpl(LuanTableImpl tbl) { if( tbl.map != null ) - this.map = new HashMap<Object,Object>(tbl.map); + this.map = newMap(tbl.map); if( tbl.list != null ) this.list = new ArrayList<Object>(tbl.list); } */ LuanTableImpl(List<Object> list) { this.list = list; - this.map = new HashMap<Object,Object>(); + this.map = newMap(); map.put("n",list.size()); for( int i=0; i<list.size(); i++ ) { if( list.get(i) == null ) { @@ -51,7 +50,7 @@ } LuanTableImpl(Set<Object> set) { - map = new HashMap<Object,Object>(); + map = newMap(); for( Object obj : set ) { if( obj != null ) map.put(obj,Boolean.TRUE); @@ -64,7 +63,7 @@ @Override public void deepenClone(LuanTableImpl clone,DeepCloner cloner) { if( map != null ) { - clone.map = new HashMap<Object,Object>(); + clone.map = newMap(); for( Map.Entry<Object,Object> entry : map.entrySet() ) { clone.map.put( cloner.get(entry.getKey()), cloner.get(entry.getValue()) ); } @@ -90,7 +89,7 @@ @Override public Map<Object,Object> asMap() { if( list == null || list.isEmpty() ) return map!=null ? map : Collections.emptyMap(); - Map<Object,Object> rtn = map!=null ? new HashMap<Object,Object>(map) : new HashMap<Object,Object>(); + Map<Object,Object> rtn = map!=null ? newMap(map) : newMap(); for( ListIterator iter = list.listIterator(); iter.hasNext(); ) { int i = iter.nextIndex(); rtn.put(i+1,iter.next()); @@ -222,7 +221,7 @@ } } if( map==null ) { - map = new HashMap<Object,Object>(); + map = newMap(); } if( key instanceof Number && !(key instanceof Double) ) { Number n = (Number)key; @@ -253,7 +252,7 @@ Object v = list.remove(i); if( v != null ) { if( map==null ) - map = new HashMap<Object,Object>(); + map = newMap(); map.put(i+1,v); } }