Mercurial Hosting > luan
comparison core/src/luan/LuanTable.java @ 431:3ffe8ba5b297
TableLuan cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 02 May 2015 21:12:48 -0600 |
parents | f28320fd671d |
children | d9df6d6cb927 |
comparison
equal
deleted
inserted
replaced
430:f28320fd671d | 431:3ffe8ba5b297 |
---|---|
30 for( int i=0; i<list.size(); i++ ) { | 30 for( int i=0; i<list.size(); i++ ) { |
31 if( list.get(i) == null ) { | 31 if( list.get(i) == null ) { |
32 listToMap(i); | 32 listToMap(i); |
33 break; | 33 break; |
34 } | 34 } |
35 } | |
36 } | |
37 | |
38 LuanTable(Map<Object,Object> map) { | |
39 map.remove(null); | |
40 for( Iterator<Object> i=map.values().iterator(); i.hasNext(); ) { | |
41 if( i.next() == null ) | |
42 i.remove(); | |
43 } | |
44 this.map = map; | |
45 } | |
46 | |
47 LuanTable(Set<Object> set) { | |
48 map = newMap(); | |
49 for( Object obj : set ) { | |
50 if( obj != null ) | |
51 map.put(obj,Boolean.TRUE); | |
52 } | 35 } |
53 } | 36 } |
54 | 37 |
55 public LuanTable(LuanTable tbl) { | 38 public LuanTable(LuanTable tbl) { |
56 if( tbl.map != null && !tbl.map.isEmpty() ) | 39 if( tbl.map != null && !tbl.map.isEmpty() ) |
231 mapToList(); | 214 mapToList(); |
232 } | 215 } |
233 return list; | 216 return list; |
234 } | 217 } |
235 | 218 |
236 public void insert(int pos,Object value) { | 219 public void rawInsert(int pos,Object value) { |
237 if( value==null ) | 220 if( value==null ) |
238 throw new IllegalArgumentException("can't insert a nil value"); | 221 throw new IllegalArgumentException("can't insert a nil value"); |
239 list().add(pos-1,value); | 222 list().add(pos-1,value); |
240 mapToList(); | 223 mapToList(); |
241 } | 224 } |
242 | 225 |
243 public void add(Object value) { | 226 public void rawAdd(Object value) { |
244 if( value==null ) | 227 if( value==null ) |
245 throw new IllegalArgumentException("can't add a nil value"); | 228 throw new IllegalArgumentException("can't add a nil value"); |
246 list().add(value); | 229 list().add(value); |
247 mapToList(); | 230 mapToList(); |
248 } | 231 } |
249 | 232 |
250 public Object remove(int pos) { | 233 public Object rawRemove(int pos) { |
251 return list().remove(pos-1); | 234 return list().remove(pos-1); |
252 } | 235 } |
253 | 236 |
254 public void sort(Comparator<Object> cmp) { | 237 public void rawSort(Comparator<Object> cmp) { |
255 Collections.sort(list(),cmp); | 238 Collections.sort(list(),cmp); |
256 } | 239 } |
257 | 240 |
258 public int length() { | 241 public int length() { |
259 return list==null ? 0 : list.size(); | 242 return list==null ? 0 : list.size(); |
304 throw new UnsupportedOperationException(); | 287 throw new UnsupportedOperationException(); |
305 } | 288 } |
306 }; | 289 }; |
307 } | 290 } |
308 | 291 |
309 public LuanTable subList(int from,int to) { | 292 public LuanTable rawSubList(int from,int to) { |
310 LuanTable tbl = shallowClone(); | 293 LuanTable tbl = shallowClone(); |
311 tbl.list = new ArrayList<Object>(list().subList(from-1,to-1)); | 294 tbl.list = new ArrayList<Object>(list().subList(from-1,to-1)); |
312 return tbl; | 295 return tbl; |
313 } | 296 } |
314 | 297 |
334 } | 317 } |
335 | 318 |
336 | 319 |
337 // from AbstractLuanTable | 320 // from AbstractLuanTable |
338 | 321 |
339 protected final Map<Object,Object> newMap() { | 322 private Map<Object,Object> newMap() { |
340 return new LinkedHashMap<Object,Object>(); | 323 return new LinkedHashMap<Object,Object>(); |
341 } | |
342 | |
343 public boolean isEmpty() { | |
344 return isList() && length()==0; | |
345 } | 324 } |
346 | 325 |
347 public boolean isSet() { | 326 public boolean isSet() { |
348 for( Map.Entry<Object,Object> entry : this ) { | 327 for( Map.Entry<Object,Object> entry : this ) { |
349 if( !entry.getValue().equals(Boolean.TRUE) ) | 328 if( !entry.getValue().equals(Boolean.TRUE) ) |