public class CollectionContainerImpl<E extends Entity> extends InstanceContainerImpl<E> implements CollectionContainer<E>
CollectionContainer.CollectionChangeEvent<T extends Entity>, CollectionContainer.UnmuteEventsMode
InstanceContainer.ItemChangeEvent<T extends Entity>, InstanceContainer.ItemPropertyChangeEvent<T extends Entity>
Modifier and Type | Field and Description |
---|---|
protected java.util.List<E> |
collection |
protected java.util.Map<java.lang.Object,java.lang.Integer> |
idMap |
protected Sorter |
sorter |
entityMetaClass, events, item, listener, listenersEnabled, loader, view
Constructor and Description |
---|
CollectionContainerImpl(MetaClass metaClass) |
Modifier and Type | Method and Description |
---|---|
Subscription |
addCollectionChangeListener(java.util.function.Consumer<CollectionContainer.CollectionChangeEvent<E>> listener)
Adds listener to
CollectionContainer.CollectionChangeEvent . |
protected void |
addToCollection(E entity) |
protected void |
attachListener(java.util.Collection<E> entities) |
protected void |
buildIdMap() |
protected void |
clearItemIfNotExists() |
boolean |
containsItem(java.lang.Object entityId)
Returns true if an item with the given id exists in the container.
|
protected void |
detachListener(java.util.Collection<E> entities) |
protected void |
fireCollectionChanged(CollectionChangeType type,
java.util.Collection<? extends E> changes) |
E |
getItem(java.lang.Object entityId)
Returns entity by its id.
|
int |
getItemIndex(java.lang.Object entityId)
Returns the index in the items list of the entity with the given id or -1 if there is no such entity.
|
E |
getItemOrNull(java.lang.Object entityId)
Returns entity by its id or null if the container doesn't have an entity with the given id.
|
java.util.List<E> |
getItems()
Returns immutable list of contained entities.
|
java.util.List<E> |
getMutableItems()
Returns mutable list of contained entities.
|
Sorter |
getSorter()
Returns sorter object currently set for the container.
|
protected void |
replaceInCollection(int idx,
E entity) |
void |
replaceItem(E entity)
If the item with the same id exists in the container, it is replaced with the given instance.
|
void |
setItem(E item)
Sets the given entity instance to the container.
|
void |
setItems(java.util.Collection<E> entities)
Sets a collection of entities to the container.
|
void |
setSorter(Sorter sorter)
Sets sorter object.
|
java.lang.String |
toString() |
void |
unmute(CollectionContainer.UnmuteEventsMode mode)
Enables all event listeners.
|
addItemChangeListener, addItemPropertyChangeListener, attachListener, detachListener, fireItemChanged, getEntityMetaClass, getItem, getItemOrNull, getLoader, getView, itemPropertyChanged, mute, setLoader, setView, unmute
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addItemChangeListener, addItemPropertyChangeListener, getEntityMetaClass, getItem, getItemOrNull, getView, mute, setView, unmute
protected java.util.Map<java.lang.Object,java.lang.Integer> idMap
protected Sorter sorter
public CollectionContainerImpl(MetaClass metaClass)
public void setItem(@Nullable E item)
InstanceContainer
setItem
in interface InstanceContainer<E extends Entity>
setItem
in class InstanceContainerImpl<E extends Entity>
public java.util.List<E> getItems()
CollectionContainer
getItems
in interface CollectionContainer<E extends Entity>
public java.util.List<E> getMutableItems()
CollectionContainer
CollectionContainer.CollectionChangeEvent
.getMutableItems
in interface CollectionContainer<E extends Entity>
public void setItems(@Nullable java.util.Collection<E> entities)
CollectionContainer
setItems
in interface CollectionContainer<E extends Entity>
@Nonnull public E getItem(java.lang.Object entityId)
CollectionContainer
getItem
in interface CollectionContainer<E extends Entity>
@Nullable public E getItemOrNull(java.lang.Object entityId)
CollectionContainer
getItemOrNull
in interface CollectionContainer<E extends Entity>
public int getItemIndex(java.lang.Object entityId)
CollectionContainer
getItemIndex
in interface CollectionContainer<E extends Entity>
public boolean containsItem(java.lang.Object entityId)
CollectionContainer
containsItem
in interface CollectionContainer<E extends Entity>
public void replaceItem(E entity)
CollectionContainer
Sends CollectionContainer.CollectionChangeEvent
of the SET_ITEM
or ADD_ITEMS
type.
replaceItem
in interface CollectionContainer<E extends Entity>
protected void replaceInCollection(int idx, E entity)
protected void addToCollection(E entity)
public Subscription addCollectionChangeListener(java.util.function.Consumer<CollectionContainer.CollectionChangeEvent<E>> listener)
CollectionContainer
CollectionContainer.CollectionChangeEvent
.addCollectionChangeListener
in interface CollectionContainer<E extends Entity>
public Sorter getSorter()
CollectionContainer
getSorter
in interface CollectionContainer<E extends Entity>
public void setSorter(Sorter sorter)
CollectionContainer
setSorter
in interface CollectionContainer<E extends Entity>
public void unmute(CollectionContainer.UnmuteEventsMode mode)
CollectionContainer
mode
.unmute
in interface CollectionContainer<E extends Entity>
mode
- modeprotected void fireCollectionChanged(CollectionChangeType type, java.util.Collection<? extends E> changes)
protected void attachListener(java.util.Collection<E> entities)
protected void detachListener(java.util.Collection<E> entities)
protected void buildIdMap()
protected void clearItemIfNotExists()
public java.lang.String toString()
toString
in class InstanceContainerImpl<E extends Entity>