@Test public void testRemoveIf() { EventList<Integer> source = new BasicEventList<>(); source.add(ZERO); source.add(ONE); source.add(TWO); List<ListEvent<Integer>> events = new ArrayList<>(); source.addListEventListener(events::add); FunctionList<Integer, String> intsToStrings = new FunctionList<>(source, new IntegerToString(), new StringToInteger()); ListConsistencyListener.install(intsToStrings); assertEquals(Arrays.asList("0", "1", "2"), intsToStrings); intsToStrings.removeIf(s -> !s.equals("0")); assertEquals(Collections.singletonList("0"), intsToStrings); assertEquals(Collections.singletonList(ZERO), source); assertEquals(1, events.size()); }
@Override public boolean removeIf(Predicate<? super E> filter) { ListEventAssembler<?> sourceUpdates; if (source instanceof AbstractEventList) { sourceUpdates = ((AbstractEventList) source).updates; } else sourceUpdates = null; boolean foundMatch = false; for (int i = size() - 1; i >= 0; i--) { if (filter.test(mappedElements.get(i))) { if (sourceUpdates != null && !foundMatch) { sourceUpdates.beginEvent(true); } foundMatch = true; remove(i); } } if (sourceUpdates != null && foundMatch) { sourceUpdates.commitEvent(); } return foundMatch; }
FunctionList extends TransformedList<S, E> implements RandomAccess { @Override public boolean removeIf(Predicate<? super E> filter) { ListEventAssembler<?> sourceUpdates; if (source instanceof AbstractEventList) { sourceUpdates = ((AbstractEventList) source).updates; } else sourceUpdates = null; boolean foundMatch = false; for (int i = size() - 1; i >= 0; i--) { if (filter.test(mappedElements.get(i))) { if (sourceUpdates != null && !foundMatch) { sourceUpdates.beginEvent(true); } foundMatch = true; remove(i); } } if (sourceUpdates != null && foundMatch) { sourceUpdates.commitEvent(); } return foundMatch; } }
FunctionList extends TransformedList<S, E> implements RandomAccess { @Override public boolean removeIf(Predicate<? super E> filter) { ListEventAssembler<?> sourceUpdates; if (source instanceof AbstractEventList) { sourceUpdates = ((AbstractEventList) source).updates; } else sourceUpdates = null; boolean foundMatch = false; for (int i = size() - 1; i >= 0; i--) { if (filter.test(mappedElements.get(i))) { if (sourceUpdates != null && !foundMatch) { sourceUpdates.beginEvent(true); } foundMatch = true; remove(i); } } if (sourceUpdates != null && foundMatch) { sourceUpdates.commitEvent(); } return foundMatch; } FunctionList(EventList<S> source, Function<S,E> forward);  FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse); }
FunctionList extends TransformedList<S, E> implements RandomAccess { @Override public boolean removeIf(Predicate<? super E> filter) { ListEventAssembler<?> sourceUpdates; if (source instanceof AbstractEventList) { sourceUpdates = ((AbstractEventList) source).updates; } else sourceUpdates = null; boolean foundMatch = false; for (int i = size() - 1; i >= 0; i--) { if (filter.test(mappedElements.get(i))) { if (sourceUpdates != null && !foundMatch) { sourceUpdates.beginEvent(true); } foundMatch = true; remove(i); } } if (sourceUpdates != null && foundMatch) { sourceUpdates.commitEvent(); } return foundMatch; } FunctionList(EventList<S> source, Function<S,E> forward);  FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse); void setForwardFunction(Function<S,E> forward); Function<S,E> getForwardFunction(); void setReverseFunction(Function<E,S> reverse); Function<E,S> getReverseFunction(); @Override void listChanged(ListEvent<S> listChanges); @Override E get(int index); @Override E remove(int index); @Override E set(int index, E value); @Override void add(int index, E value); @Override boolean removeIf(Predicate<? super E> filter); }
FunctionList extends TransformedList<S, E> implements RandomAccess { @Override public boolean removeIf(Predicate<? super E> filter) { ListEventAssembler<?> sourceUpdates; if (source instanceof AbstractEventList) { sourceUpdates = ((AbstractEventList) source).updates; } else sourceUpdates = null; boolean foundMatch = false; for (int i = size() - 1; i >= 0; i--) { if (filter.test(mappedElements.get(i))) { if (sourceUpdates != null && !foundMatch) { sourceUpdates.beginEvent(true); } foundMatch = true; remove(i); } } if (sourceUpdates != null && foundMatch) { sourceUpdates.commitEvent(); } return foundMatch; } FunctionList(EventList<S> source, Function<S,E> forward);  FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse); void setForwardFunction(Function<S,E> forward); Function<S,E> getForwardFunction(); void setReverseFunction(Function<E,S> reverse); Function<E,S> getReverseFunction(); @Override void listChanged(ListEvent<S> listChanges); @Override E get(int index); @Override E remove(int index); @Override E set(int index, E value); @Override void add(int index, E value); @Override boolean removeIf(Predicate<? super E> filter);  }