Class 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 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 SilverpeasResourceSelectionBasket 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 SilverpeasResourceSelectionBasket 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 SilverpeasResourceOptional<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.
      • getAt

        public <T extends SilverpeasResourceOptional<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 SilverpeasResourceOptional<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.
      • 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.