Class PagedResponseImpl<T>

java.lang.Object
com.atlassian.servicedesk.api.util.paging.PagedResponseImpl<T>
All Implemented Interfaces:
PagedResponse<T>, Iterable<T>

@Internal public class PagedResponseImpl<T> extends Object implements PagedResponse<T>
A wrapper around a list of content.
  • Constructor Details

  • Method Details

    • getPagedRequest

      public PagedRequest getPagedRequest()
      Specified by:
      getPagedRequest in interface PagedResponse<T>
      Returns:
      the request used to produce this response
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • size

      public int size()
      Specified by:
      size in interface PagedResponse<T>
      Returns:
      the number of results in this page of results
    • getResults

      public List<T> getResults()
      Specified by:
      getResults in interface PagedResponse<T>
      Returns:
      the results
    • hasNextPage

      public boolean hasNextPage()
      Description copied from interface: PagedResponse
      Indicates whether the source has more results after this page.
      Specified by:
      hasNextPage in interface PagedResponse<T>
      Returns:
      true if there are more results
    • map

      public <M> PagedResponse<M> map(com.google.common.base.Function<T,M> mapper)
      Description copied from interface: PagedResponse
      Allows you to map a paged response of T into M
      Specified by:
      map in interface PagedResponse<T>
      Type Parameters:
      M - the output type
      Parameters:
      mapper - the mapping function
      Returns:
      a paged response of M
    • findFirst

      public Optional<T> findFirst()
      Specified by:
      findFirst in interface PagedResponse<T>
      Returns:
      an optional first element of the paged response
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • from

      public static <T> PagedResponseImpl.Builder<T> from(Iterable<T> list, boolean hasMore)
      A builder of PagedResponse's that starts with the specified list
      Parameters:
      list - the starting elements
      hasMore - does it have more
      Returns:
      a builder
    • fromSingle

      public static <T> PagedResponseImpl.Builder<T> fromSingle(boolean hasMore, T element)
      A builder of PagedResponse's that starts with the single element
      Parameters:
      hasMore - does it have more
      element - the starting element
      Returns:
      a builder
    • transform

      public static <F, T> PagedResponseImpl<T> transform(PagedResponse<F> input, com.google.common.base.Function<F,T> mapper)
      Converts a given PageResponse contains items of type F into an equivalent PageResponse with items of type T, transformed by the given mapper. All other attributes of PageResponse are kept intact.
    • empty

      public static <T> PagedResponseImpl<T> empty(boolean hasMore)
      Returns an empty PagedResponse with the specified hasNextPage flag
      Parameters:
      hasMore - whether the response actually has more
      Returns:
      n empty PagedResponse
    • empty

      public static <T> PagedResponseImpl<T> empty(boolean hasMore, PagedRequest request)
      Returns an empty PagedResponse
      Parameters:
      hasMore - whether the response actually has more
      request - the input paged request
      Returns:
      n empty PagedResponse
    • empty

      public static <T> PagedResponseImpl<T> empty(boolean hasMore, LimitedPagedRequest request)
      Returns an empty PagedResponse
      Parameters:
      hasMore - whether the response actually has more
      request - the input paged request
      Returns:
      n empty PagedResponse
    • toPagedResponse

      public static <T> PagedResponse<T> toPagedResponse(LimitedPagedRequest limitedPagedRequest, List<T> items)
      Reduces a list of items to the system enforced limited page size. This method assume the items are sorted
      Returns:
      a PagedResponse that is of the limited size
    • sortAndToPagedResponse

      public static <T> PagedResponse<T> sortAndToPagedResponse(LimitedPagedRequest limitedPagedRequest, List<T> items, Comparator<T> comparator)
      Use the provided Comparator to sort and reduces a list of items to the system enforced limited page size.
      Returns:
      a PagedResponse that is of the limited size
    • filteredPageResponse

      public static <T> PagedResponse<T> filteredPageResponse(LimitedPagedRequest limitedPagedRequest, List<T> items, com.google.common.base.Predicate<? super T> predicate)
      Reduces a list of items for a limited request by the predicate provided. Useful for permission checks that are known to the Manager layer...