Mercurial Hosting > luan
comparison src/luan/LuanTable.java @ 1613:92beba8bf1c8
handle ConcurrentModificationException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 24 May 2021 22:30:17 -0600 |
parents | fa066aaa068c |
children | a37ffe2d1b14 |
comparison
equal
deleted
inserted
replaced
1612:8852f34a646a | 1613:92beba8bf1c8 |
---|---|
9 import java.util.ArrayList; | 9 import java.util.ArrayList; |
10 import java.util.Collections; | 10 import java.util.Collections; |
11 import java.util.Comparator; | 11 import java.util.Comparator; |
12 import java.util.Set; | 12 import java.util.Set; |
13 import java.util.HashSet; | 13 import java.util.HashSet; |
14 import java.util.ConcurrentModificationException; | |
14 | 15 |
15 | 16 |
16 public final class LuanTable implements LuanMutable { | 17 public final class LuanTable implements LuanMutable { |
17 private Map map = null; | 18 private Map map = null; |
18 private List list = null; | 19 private List list = null; |
349 | 350 |
350 private LuanFunction rawPairs() { | 351 private LuanFunction rawPairs() { |
351 return new LuanFunction() { | 352 return new LuanFunction() { |
352 final Iterator<Map.Entry> iter = rawIterator(); | 353 final Iterator<Map.Entry> iter = rawIterator(); |
353 | 354 |
354 @Override public Object[] call(Luan luan,Object[] args) { | 355 @Override public Object[] call(Luan luan,Object[] args) throws LuanException { |
355 if( !iter.hasNext() ) | 356 if( !iter.hasNext() ) |
356 return LuanFunction.NOTHING; | 357 return LuanFunction.NOTHING; |
357 Map.Entry<Object,Object> entry = iter.next(); | 358 try { |
358 return new Object[]{entry.getKey(),entry.getValue()}; | 359 Map.Entry<Object,Object> entry = iter.next(); |
360 return new Object[]{entry.getKey(),entry.getValue()}; | |
361 } catch(ConcurrentModificationException e) { | |
362 throw new LuanException("table modified while iterating"); | |
363 } | |
359 } | 364 } |
360 }; | 365 }; |
361 } | 366 } |
362 | 367 |
363 public Iterator<Map.Entry> rawIterator() { | 368 public Iterator<Map.Entry> rawIterator() { |