Mercurial Hosting > luan
diff src/luan/LuanTable.java @ 118:735708619119
add Debug.debug()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@119 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 01 Jun 2014 07:07:31 +0000 |
parents | 3c404a296995 |
children | cc3a0578edac |
line wrap: on
line diff
--- a/src/luan/LuanTable.java Fri May 30 08:57:24 2014 +0000 +++ b/src/luan/LuanTable.java Sun Jun 01 07:07:31 2014 +0000 @@ -23,16 +23,30 @@ public LuanTable(List<Object> list) { this.list = list; + this.map = new HashMap<Object,Object>(); + map.put("n",list.size()); + for( int i=0; i<list.size(); i++ ) { + if( list.get(i) == null ) { + listToMap(i); + break; + } + } } public LuanTable(Map<Object,Object> map) { + map.remove(null); + for( Iterator<Object> i=map.values().iterator(); i.hasNext(); ) { + if( i.next() == null ) + i.remove(); + } this.map = map; } public LuanTable(Set<Object> set) { map = new HashMap<Object,Object>(); for( Object obj : set ) { - map.put(obj,Boolean.TRUE); + if( obj != null ) + map.put(obj,Boolean.TRUE); } } @@ -200,10 +214,8 @@ } else if( i>=0 && i<list.size() ) { Object old = list.get(i); list.set(i,val); - if( val == null && i == list.size()-1 ) { - while( i>=0 && list.get(i)==null ) { - list.remove(i--); - } + if( val == null ) { + listToMap(i); } return old; } @@ -234,6 +246,20 @@ } } + private void listToMap(int from) { + if( list != null ) { + while( list.size() > from ) { + int i = list.size() - 1; + Object v = list.remove(i); + if( v != null ) { + if( map==null ) + map = new HashMap<Object,Object>(); + map.put(i+1,v); + } + } + } + } + private List<Object> list() { if( list == null ) { list = new ArrayList<Object>(); @@ -314,11 +340,11 @@ } }; } - +/* public Object[] listToArray() { return list==null ? new Object[0] : list.toArray(); } - +*/ public LuanTable subList(int from,int to) { return new LuanTable(new ArrayList<Object>(list().subList(from-1,to-1))); }