@Test public void testAcceptWithReadLock() { EventList<String> source = new BasicEventList<>(); source.addAll(GlazedListsTests.stringToList("ABC")); RangeList<String> rangeList = new RangeList<>(source); rangeList.setHeadRange(0, 2); Guard.acceptWithReadLock(rangeList, list -> { assertEquals(0, list.getStartIndex()); assertEquals(2, list.getEndIndex()); }); }
public static <E, L extends EventList<E>> void acceptWithReadLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().readLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().readLock().unlock(); } }
Guard { public static <E, L extends EventList<E>> void acceptWithReadLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().readLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().readLock().unlock(); } } }
Guard { public static <E, L extends EventList<E>> void acceptWithReadLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().readLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().readLock().unlock(); } } private  Guard(); }
Guard { public static <E, L extends EventList<E>> void acceptWithReadLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().readLock().lock(); try { consumer.accept(eventList); } finally { eventList.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>> void acceptWithReadLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().readLock().lock(); try { consumer.accept(eventList); } finally { eventList.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);  }