@Test public void testAcceptWithWriteLock() { EventList<String> source = new BasicEventList<>(); TransactionList<String> txList = new TransactionList<>(source); source.addAll(GlazedListsTests.stringToList("ABC")); assertEquals(GlazedListsTests.stringToList("ABC"), source); assertEquals(GlazedListsTests.stringToList("ABC"), txList); Guard.acceptWithWriteLock(txList, list -> { txList.beginEvent(); txList.add("D"); txList.remove(1); txList.set(0, "B"); assertEquals(GlazedListsTests.stringToList("BCD"), source); assertEquals(GlazedListsTests.stringToList("BCD"), txList); txList.rollbackEvent(); assertEquals(GlazedListsTests.stringToList("ABC"), source); assertEquals(GlazedListsTests.stringToList("ABC"), txList); }); }
public static <E, L extends EventList<E>> void acceptWithWriteLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().writeLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().writeLock().unlock(); } }
Guard { public static <E, L extends EventList<E>> void acceptWithWriteLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().writeLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().writeLock().unlock(); } } }
Guard { public static <E, L extends EventList<E>> void acceptWithWriteLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().writeLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().writeLock().unlock(); } } private  Guard(); }
Guard { public static <E, L extends EventList<E>> void acceptWithWriteLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().writeLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().writeLock().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 acceptWithWriteLock(L eventList, Consumer<L> consumer) { if (eventList == null) { return; } eventList.getReadWriteLock().writeLock().lock(); try { consumer.accept(eventList); } finally { eventList.getReadWriteLock().writeLock().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);  }