Package org.silverpeas.core.selection
Class SelectionBasket
- java.lang.Object
-
- org.silverpeas.core.selection.SelectionBasket
-
- All Implemented Interfaces:
Serializable
public class SelectionBasket extends Object implements Serializable
A basket of a selection of Silverpeas resources. It is specific to each user and lives along the current session of the user; it expires with the session of the user. A resource can be present only one time in the basket whatever its selection context. So putting it again in the basket doesn't add it a second time but update its position in the basket so that it will be the first one to be popped.The basket behaves like an indexed stack of
SelectionEntry
instances, each of them related to a given Silverpeas resource selected by the current user. Each entries, and hence each resource, is then indexed by their position in the stack, that is to say by the ordered way they were put into the basket: the first resource put in the basket is at the tail of the stack, the second resource just atop of the first resource, and so on. The last resource is hence at the head of the stack, and therefore it will be the first one to be popped. Because the resources put in the basket are indexed by their position, they can be gotten by their index.- Author:
- mmoquillon
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SelectionBasket
clear()
Clears this basket of all the resources it contains.int
count()
Gets the number of resources in this basket.static SelectionBasket
get()
Gets the basket of resources selected by the current user.<T extends SilverpeasResource>
Optional<SelectionEntry<T>>getAt(int index)
Gets the resource that is at the specified position in this basket.Stream<SelectionEntry<SilverpeasResource>>
getSelectedResources()
Gets a functional stream on the selected resources this basket contains.boolean
isEmpty()
Is the basket empty?<T extends SilverpeasResource>
Optional<SelectionEntry<T>>pop()
Pops the last resource put in the basket; the resource atop of the basket.<T extends SilverpeasResource>
SelectionBasketput(T resource)
Puts the specified Silverpeas resource into this basket of selected resources to transfer information about it.<T extends SilverpeasResource>
SelectionBasketput(T resource, SelectionContext context)
Puts the specified Silverpeas resource into this basket of selected resources for the given selection context .<T extends SilverpeasResource>
voidremove(T resource)
<T extends SilverpeasResource>
Optional<SelectionEntry<T>>removeAt(int index)
Removes the resource that is at the specified position in the basket.
-
-
-
Method Detail
-
get
public static SelectionBasket get()
Gets the basket of resources selected by the current user. The basket is- Returns:
- the current instance of
SelectionBasket
in the scope of the session of the user.
-
put
public <T extends SilverpeasResource> SelectionBasket put(T resource)
Puts the specified Silverpeas resource into this basket of selected resources to transfer information about it. The resource can be present only one time in the basket whatever the context of its selection; putting it another time is just moving it in atop of all others selected resources in the basket with the new selection context.- Parameters:
resource
- a resource to put.- Returns:
- the basket enriched with the specified resource.
-
put
public <T extends SilverpeasResource> SelectionBasket put(T resource, SelectionContext context)
Puts the specified Silverpeas resource into this basket of selected resources for the given selection context . The resource can be present only one time in the basket whatever the context of its selection; putting it another time is just moving it in atop of all others selected resources in the basket with the new selection context.- Parameters:
resource
- a resource to put.- Returns:
- the basket enriched with the specified resource.
-
pop
public <T extends SilverpeasResource> Optional<SelectionEntry<T>> pop()
Pops the last resource put in the basket; the resource atop of the basket. The resource just below it becomes then the first resource (position at 0).- Returns:
- maybe the last resource put in the basket and then removes it from the basket. If the basket is empty, then nothing is returned.
-
getSelectedResources
public Stream<SelectionEntry<SilverpeasResource>> getSelectedResources()
Gets a functional stream on the selected resources this basket contains.- Returns:
- a stream on
SilverpeasResource
objects of the basket.
-
getAt
public <T extends SilverpeasResource> Optional<SelectionEntry<T>> getAt(int index)
Gets the resource that is at the specified position in this basket.- Parameters:
index
- the position number, starting by 0 meaning the head of the basket.- Returns:
- maybe the selected resource positioned at the given position. If the index is out of range of the capacity of the basket, then nothing is returned.
-
removeAt
public <T extends SilverpeasResource> Optional<SelectionEntry<T>> removeAt(int index)
Removes the resource that is at the specified position in the basket. The position of the resources following the removed one are then shifted to one place.- Parameters:
index
- the position number, starting by 0 meaning the head of the basket.- Returns:
- the selected resource positioned at the given position and then remove it from the basket. If the index is out of range of the capacity of the basket, then nothing is returned.
-
remove
public <T extends SilverpeasResource> void remove(T resource)
-
clear
public SelectionBasket clear()
Clears this basket of all the resources it contains.- Returns:
- the basket emptied.
-
isEmpty
public boolean isEmpty()
Is the basket empty?- Returns:
- true if there is no resources in this basket. False otherwise.
-
count
public int count()
Gets the number of resources in this basket.- Returns:
- the number of selected resources.
-
-