package be.selckin.swu.model; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.apache.wicket.model.IModel; import java.util.Collection; import java.util.List; public class ReadOnlyCollectionListAdapterLDM<T> extends ReadOnlyLDM<List<T>> { private final IModel<? extends Collection<? extends T>> model; public ReadOnlyCollectionListAdapterLDM(IModel<? extends Collection<? extends T>> model) { this.model = Preconditions.checkNotNull(model); } @Override protected List<T> load() { Collection<? extends T> collection = model.getObject(); return collection == null ? ImmutableList.<T>of() : ImmutableList.copyOf(collection); } @Override protected void onDetach() { model.detach(); } public static <T> ReadOnlyCollectionListAdapterLDM<T> of(IModel<? extends Collection<? extends T>> model) { return new ReadOnlyCollectionListAdapterLDM<T>(model); } }