@Test public void testGet_shouldReturnNewList_ifUnderlyingListHasCanged() { itemSupplier.get(); modelObjects.add(42); assertThat(itemSupplier.get(), hasSize(1)); SimplePmo pmo = itemSupplier.get().get(0); assertThat(pmo.getModelObject(), is(42)); modelObjects.add(43); assertThat(itemSupplier.get(), hasSize(2)); assertThat(itemSupplier.get().get(0), is(pmo)); assertThat(itemSupplier.get().get(1).getModelObject(), is(43)); }
@Override public List<PMO> get() { List<? extends MO> actualModelObjects = modelObjectSupplier.get(); requireNonNull(actualModelObjects, "modelObjectSupplier must supply a List of model objects (which may be empty)"); if (hasUnderlyingModelObjectListChanged(actualModelObjects)) { HashSet<? extends MO> actualModelObjectsSet = new HashSet<>(actualModelObjects); itemMap.keySet().removeIf(o -> !actualModelObjectsSet.contains(o)); items = new LinkedList<>(); actualModelObjects.forEach(mo -> items.add(applymo2pmoMapping(mo))); modelObjectsCopy = new ArrayList<>(actualModelObjects); } return items; }
SimpleItemSupplier implements Supplier<List<PMO>> { @Override public List<PMO> get() { List<? extends MO> actualModelObjects = modelObjectSupplier.get(); requireNonNull(actualModelObjects, "modelObjectSupplier must supply a List of model objects (which may be empty)"); if (hasUnderlyingModelObjectListChanged(actualModelObjects)) { HashSet<? extends MO> actualModelObjectsSet = new HashSet<>(actualModelObjects); itemMap.keySet().removeIf(o -> !actualModelObjectsSet.contains(o)); items = new LinkedList<>(); actualModelObjects.forEach(mo -> items.add(applymo2pmoMapping(mo))); modelObjectsCopy = new ArrayList<>(actualModelObjects); } return items; } }
SimpleItemSupplier implements Supplier<List<PMO>> { @Override public List<PMO> get() { List<? extends MO> actualModelObjects = modelObjectSupplier.get(); requireNonNull(actualModelObjects, "modelObjectSupplier must supply a List of model objects (which may be empty)"); if (hasUnderlyingModelObjectListChanged(actualModelObjects)) { HashSet<? extends MO> actualModelObjectsSet = new HashSet<>(actualModelObjects); itemMap.keySet().removeIf(o -> !actualModelObjectsSet.contains(o)); items = new LinkedList<>(); actualModelObjects.forEach(mo -> items.add(applymo2pmoMapping(mo))); modelObjectsCopy = new ArrayList<>(actualModelObjects); } return items; } SimpleItemSupplier(Supplier<? extends List<? extends MO>> modelObjectSupplier,
            Function<MO, PMO> mo2pmoMapping); }
SimpleItemSupplier implements Supplier<List<PMO>> { @Override public List<PMO> get() { List<? extends MO> actualModelObjects = modelObjectSupplier.get(); requireNonNull(actualModelObjects, "modelObjectSupplier must supply a List of model objects (which may be empty)"); if (hasUnderlyingModelObjectListChanged(actualModelObjects)) { HashSet<? extends MO> actualModelObjectsSet = new HashSet<>(actualModelObjects); itemMap.keySet().removeIf(o -> !actualModelObjectsSet.contains(o)); items = new LinkedList<>(); actualModelObjects.forEach(mo -> items.add(applymo2pmoMapping(mo))); modelObjectsCopy = new ArrayList<>(actualModelObjects); } return items; } SimpleItemSupplier(Supplier<? extends List<? extends MO>> modelObjectSupplier,
            Function<MO, PMO> mo2pmoMapping); @Override List<PMO> get(); }
SimpleItemSupplier implements Supplier<List<PMO>> { @Override public List<PMO> get() { List<? extends MO> actualModelObjects = modelObjectSupplier.get(); requireNonNull(actualModelObjects, "modelObjectSupplier must supply a List of model objects (which may be empty)"); if (hasUnderlyingModelObjectListChanged(actualModelObjects)) { HashSet<? extends MO> actualModelObjectsSet = new HashSet<>(actualModelObjects); itemMap.keySet().removeIf(o -> !actualModelObjectsSet.contains(o)); items = new LinkedList<>(); actualModelObjects.forEach(mo -> items.add(applymo2pmoMapping(mo))); modelObjectsCopy = new ArrayList<>(actualModelObjects); } return items; } SimpleItemSupplier(Supplier<? extends List<? extends MO>> modelObjectSupplier,
            Function<MO, PMO> mo2pmoMapping); @Override List<PMO> get();  }