### Question:
Guard { public static <E, L extends EventList<E>, R> R applyWithWriteLock(L list, Function<L, R> function) { list.getReadWriteLock().writeLock().lock(); try { return function.apply(list); } finally { list.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);  }### Answer:
@Test public void testApplyWithWriteLock() { CompositeList<String> compositeList = new CompositeList<>(); EventList<String> memberList = Guard.applyWithWriteLock(compositeList, list -> { final EventList<String> newMemberList = compositeList.createMemberList(); compositeList.addMemberList(newMemberList); return newMemberList; }); assertEquals(memberList, compositeList); }