Mercurial Hosting > luan
comparison src/luan/LuanTable.java @ 1420:225808b90cee
options handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 26 Oct 2019 22:21:09 -0600 |
parents | 2024d23ddd64 |
children | 851b9a48cc44 |
comparison
equal
deleted
inserted
replaced
1419:59fd2e8b1b9d | 1420:225808b90cee |
---|---|
222 } | 222 } |
223 return; | 223 return; |
224 } | 224 } |
225 } | 225 } |
226 } | 226 } |
227 if( map==null ) | |
228 map = newMap(); | |
229 if( key instanceof Number && !(key instanceof Double) ) { | 227 if( key instanceof Number && !(key instanceof Double) ) { |
230 Number n = (Number)key; | 228 Number n = (Number)key; |
231 key = Double.valueOf(n.doubleValue()); | 229 key = Double.valueOf(n.doubleValue()); |
232 } | 230 } |
233 if( val == null ) { | 231 if( val == null ) { |
234 map.remove(key); | 232 if( map!=null ) |
233 map.remove(key); | |
235 } else { | 234 } else { |
235 if( map==null ) | |
236 map = newMap(); | |
236 map.put(key,val); | 237 map.put(key,val); |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
240 private void mapToList() { | 241 private void mapToList() { |
276 throw new IllegalArgumentException("can't insert a nil value"); | 277 throw new IllegalArgumentException("can't insert a nil value"); |
277 list().add(pos-1,value); | 278 list().add(pos-1,value); |
278 mapToList(); | 279 mapToList(); |
279 } | 280 } |
280 | 281 |
281 public Object rawRemove(int pos) { | 282 public Object removeFromList(int pos) { |
282 check(); | 283 check(); |
283 return list().remove(pos-1); | 284 return list().remove(pos-1); |
284 } | 285 } |
285 | 286 |
286 public void rawSort(Comparator<Object> cmp) { | 287 public void rawSort(Comparator<Object> cmp) { |
504 if( list != null ) | 505 if( list != null ) |
505 n ^= list.hashCode(); | 506 n ^= list.hashCode(); |
506 return n; | 507 return n; |
507 } | 508 } |
508 | 509 |
509 public boolean rawIsEmpty() { | 510 public boolean isEmpty() { |
510 return (map==null || map.isEmpty()) && (list==null || list.isEmpty()); | 511 return (map==null || map.isEmpty()) && (list==null || list.isEmpty()); |
511 } | 512 } |
512 | 513 |
513 public int rawSize() { | 514 public int rawSize() { |
514 int n = 0; | 515 int n = 0; |
517 if( list != null ) | 518 if( list != null ) |
518 n += list.size(); | 519 n += list.size(); |
519 return n; | 520 return n; |
520 } | 521 } |
521 | 522 |
523 public Object remove(Object key) { | |
524 Object old = rawGet(key); | |
525 rawPut2(key,null); | |
526 return old; | |
527 } | |
528 | |
522 protected void finalize() throws Throwable { | 529 protected void finalize() throws Throwable { |
523 Object h = getHandler("__gc"); | 530 Object h = getHandler("__gc"); |
524 if( h != null ) { | 531 if( h != null ) { |
525 LuanFunction fn = Luan.checkFunction(h); | 532 LuanFunction fn = Luan.checkFunction(h); |
526 fn.call(this); | 533 fn.call(this); |