@Test public void testApplyWithReadLock() { EventList<String> source = new BasicEventList<>(); source.addAll(GlazedListsTests.stringToList("ABC")); RangeList<String> rangeList = new RangeList<>(source); rangeList.setHeadRange(0, 2); int sum = Guard.applyWithReadLock(rangeList, list -> { return list.getStartIndex() + list.getEndIndex(); }); assertEquals(2, sum); }
public static <E, L extends EventList<E>, R> R applyWithReadLock(L list, Function<L, R> function) { list.getReadWriteLock().readLock().lock(); try { return function.apply(list); } finally { list.getReadWriteLock().readLock().unlock(); } }
Guard { public static <E, L extends EventList<E>, R> R applyWithReadLock(L list, Function<L, R> function) { list.getReadWriteLock().readLock().lock(); try { return function.apply(list); } finally { list.getReadWriteLock().readLock().unlock(); } } }
Guard { public static <E, L extends EventList<E>, R> R applyWithReadLock(L list, Function<L, R> function) { list.getReadWriteLock().readLock().lock(); try { return function.apply(list); } finally { list.getReadWriteLock().readLock().unlock(); } } private  Guard(); }
Guard { public static <E, L extends EventList<E>, R> R applyWithReadLock(L list, Function<L, R> function) { list.getReadWriteLock().readLock().lock(); try { return function.apply(list); } finally { list.getReadWriteLock().readLock().unlock(); } } private  Guard(); static void acceptWithReadLock(L eventList, Consumer<L> consumer); static void acceptWithWriteLock(L eventList, Consumer<L> consumer); static R applyWithReadLock(L list, Function<L, R> function); static R applyWithWriteLock(L list, Function<L, R> function); }
Guard { public static <E, L extends EventList<E>, R> R applyWithReadLock(L list, Function<L, R> function) { list.getReadWriteLock().readLock().lock(); try { return function.apply(list); } finally { list.getReadWriteLock().readLock().unlock(); } } private  Guard(); static void acceptWithReadLock(L eventList, Consumer<L> consumer); static void acceptWithWriteLock(L eventList, Consumer<L> consumer); static R applyWithReadLock(L list, Function<L, R> function); static R applyWithWriteLock(L list, Function<L, R> function);  }