Class AbstractSlice<T>

  • All Implemented Interfaces:
    Slice<T>
    Direct Known Subclasses:
    PageImpl, SliceImpl

    public abstract class AbstractSlice<T>
    extends java.lang.Object
    implements Slice<T>
    An abstract Slice, which implements common logic to all type of Slices.
    • Constructor Detail

      • AbstractSlice

        public AbstractSlice​(int number,
                             int size,
                             SortingData sortingData,
                             java.util.List<T> content)
        Constructor.
        Parameters:
        number - Number of slice.
        size - Slice size.
        sortingData - The SortingData that was used to sort contents of this slice.
        content - Content in this slice.
    • Method Detail

      • number

        public int number()
        Specified by:
        number in interface Slice<T>
        Returns:
        Number of slice.
      • size

        public int size()
        Specified by:
        size in interface Slice<T>
        Returns:
        Slice size.
      • numberOfElements

        public int numberOfElements()
        Specified by:
        numberOfElements in interface Slice<T>
        Returns:
        Amount of elements in the slice (can be less than the slice size if it is the last one).
      • offset

        public long offset()
        Specified by:
        offset in interface Slice<T>
        Returns:
        The offset to be taken according to the underlying Slice number and size.
      • content

        public java.util.List<T> content()
        Specified by:
        content in interface Slice<T>
        Returns:
        Content in this slice.
      • hasContent

        public boolean hasContent()
        Description copied from interface: Slice
        Indicates whether there are elements in this slice.
        Specified by:
        hasContent in interface Slice<T>
        Returns:
        true if there are elements, or false otherwise.
      • isFirst

        public boolean isFirst()
        Description copied from interface: Slice
        Indicates whether this is the first slice.
        Specified by:
        isFirst in interface Slice<T>
        Returns:
        true if it is the first slice, or false otherwise.
      • hasPrevious

        public boolean hasPrevious()
        Description copied from interface: Slice
        Indicates whether there is a previous slice.
        Specified by:
        hasPrevious in interface Slice<T>
        Returns:
        true if there is a previous slice, or false otherwise.
      • previousRequest

        public java.util.Optional<PagingRequest> previousRequest()
        Specified by:
        previousRequest in interface Slice<T>
        Returns:
        An Optional of PagingRequest from which the previous slice can be requested, if there is such, or empty otherwise.
      • nextRequest

        public java.util.Optional<PagingRequest> nextRequest()
        Specified by:
        nextRequest in interface Slice<T>
        Returns:
        An Optional of PagingRequest from which the next slice can be requested, if there is such, or empty otherwise.
      • isLast

        public boolean isLast()
        Description copied from interface: Slice
        Indicates whether this is the last slice.
        Specified by:
        isLast in interface Slice<T>
        Returns:
        true if it is the last slice, or false otherwise.