Class AbstractDetachableCollection<T>
- java.lang.Object
-
- org.wicketstuff.minis.model.collection.AbstractDetachableCollection<T>
-
- Type Parameters:
T-
- All Implemented Interfaces:
Serializable,Iterable<T>,Collection<T>,IDetachable,IClusterable
- Direct Known Subclasses:
DetachableSet
public abstract class AbstractDetachableCollection<T> extends Object implements Collection<T>, IDetachable, Serializable
A collection that can be converted between attached and detached state via calls toattach()anddetach(). Elements are converted between the two states using the specifiedIDetachCodec. This collection allows the use of real objects, and yet has the convenience of a small session footprint. If the collection is detached, invocation of any method fromCollectionwill cause this collection to be attached. NOTICE: During the conversion to either state N method calls are invoked on theIDetachCodec, one for each element in the collection. This can cause a performance problem in certain situations. Exampleclass SelectUsersPanel extends Panel { // codec to transcode user object to and from its detached state private static final IDetachCodec<User> userCodec=new IDetachCodec<User> { public Serializable detach(User object) { return object.getId(); } public User attach(Serializable object) { return UserDao.get().userForId(object); } } // collection used to store selected user objects private final DetachableHashSet<User> selected=new DetachableHashSet<User>(userCodec); protected void onDetach() { // this will shrink the size of selected collection before the page is stored in session. // the collection will be attached automatically when some method is invoked on it. selected.detach(); super.onDetach(); } public SelectUsersPanel (String id) { super(id); Form form=new Form("form"); add(form); CheckGroup checked=new CheckGroup("checked", new PropertyModel(this, "selected")); form.add(checked); checked.add(new DataView("users", new UsersDataProvider()) { protected void populateItem(Item item) { item.add(new Check("user", item.getModel())); item.add(new Label("username", new PropertyModel(item.getModel(), "username"))); } } ... }- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractDetachableCollection(IDetachCodec<T> codec)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidattach()Converts the collection into its attached state.voiddetach()Converts the collection into a detached state.booleanequals(Object obj)protected Collection<T>getAttachedStore()Returns collection used to store elements in attached state.inthashCode()protected abstract Collection<T>newAttachedStore()Creates a collection used to store elements in attached state-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Constructor Detail
-
AbstractDetachableCollection
public AbstractDetachableCollection(IDetachCodec<T> codec)
Constructor- Parameters:
codec- codec that will be used to transcode elements between attached and detached states
-
-
Method Detail
-
attach
public final void attach()
Converts the collection into its attached state. If the collection is already attached this is a noop.
-
detach
public final void detach()
Converts the collection into a detached state. If the collection is already detached this is a noop.- Specified by:
detachin interfaceIDetachable
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin interfaceCollection<T>- Overrides:
equalsin classObject
-
getAttachedStore
protected Collection<T> getAttachedStore()
Returns collection used to store elements in attached state. If this collection is currently detached it will be attached.- Returns:
- collection used to store elements in attached state
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<T>- Overrides:
hashCodein classObject
-
newAttachedStore
protected abstract Collection<T> newAttachedStore()
Creates a collection used to store elements in attached state- Returns:
- collection used to store elements in attached state
-
-