Codota Logo
Pageable.toOptional
Code IndexAdd Codota to your IDE (free)

How to use
toOptional
method
in
org.springframework.data.domain.Pageable

Best Java code snippets using org.springframework.data.domain.Pageable.toOptional (Showing top 5 results out of 315)

  • Common ways to obtain Pageable
private void myMethod () {
Pageable p =
  • Codota IconPageable.unpaged()
  • Codota Iconnew PageRequest(page, size)
  • Codota IconSort sort;new PageRequest(page, size, sort)
  • Smart code suggestions by Codota
}
origin: apache/servicemix-bundles

/**
 * Constructor of {@code PageImpl}.
 *
 * @param content the content of this page, must not be {@literal null}.
 * @param pageable the paging information, must not be {@literal null}.
 * @param total the total amount of items available. The total might be adapted considering the length of the content
 *          given, if it is going to be the content of the last page. This is in place to mitigate inconsistencies.
 */
public PageImpl(List<T> content, Pageable pageable, long total) {
  super(content, pageable);
  this.total = pageable.toOptional().filter(it -> !content.isEmpty())//
      .filter(it -> it.getOffset() + it.getPageSize() > total)//
      .map(it -> it.getOffset() + content.size())//
      .orElse(total);
}
origin: apache/servicemix-bundles

@Override
public Pageable resolveArgument(MethodParameter methodParameter, @Nullable ModelAndViewContainer mavContainer,
    NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) {
  assertPageableUniqueness(methodParameter);
  Optional<Pageable> defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter).toOptional();
  String pageString = webRequest.getParameter(getParameterNameToUse(pageParameterName, methodParameter));
  String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter));
  Optional<Integer> page = parseAndApplyBoundaries(pageString, Integer.MAX_VALUE, true);
  Optional<Integer> pageSize = parseAndApplyBoundaries(pageSizeString, maxPageSize, false);
  if (!(page.isPresent() && pageSize.isPresent()) && !defaultOrFallback.isPresent()) {
    return Pageable.unpaged();
  }
  int p = page
      .orElseGet(() -> defaultOrFallback.map(Pageable::getPageNumber).orElseThrow(IllegalStateException::new));
  int ps = pageSize
      .orElseGet(() -> defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new));
  // Limit lower bound
  ps = ps < 1 ? defaultOrFallback.map(Pageable::getPageSize).orElseThrow(IllegalStateException::new) : ps;
  // Limit upper bound
  ps = ps > maxPageSize ? maxPageSize : ps;
  Sort sort = sortResolver.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
  return PageRequest.of(p, ps,
      sort.isSorted() ? sort : defaultOrFallback.map(Pageable::getSort).orElseGet(Sort::unsorted));
}
origin: spring-projects/spring-data-keyvalue

@SuppressWarnings({ "rawtypes", "unchecked" })
protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) {
  ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
      parameters);
  Object criteria = instance.getCriteria();
  if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {
    SpelExpression spelExpression = getSpelExpression(criteria);
    EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(),
        parameters);
    criteria = new SpelCriteria(spelExpression, context);
  }
  KeyValueQuery<?> query = new KeyValueQuery(criteria);
  Pageable pageable = accessor.getPageable();
  Sort sort = accessor.getSort();
  query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L));
  if (pageable.isPaged()) {
    query.setRows(pageable.getPageSize());
  } else if (instance.getRows() >= 0) {
    query.setRows(instance.getRows());
  }
  query.setSort(sort.isUnsorted() ? instance.getSort() : sort);
  return query;
}
origin: org.springframework.data/spring-data-keyvalue

@SuppressWarnings({ "rawtypes", "unchecked" })
protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) {
  ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
      parameters);
  Object criteria = instance.getCriteria();
  if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {
    SpelExpression spelExpression = getSpelExpression(criteria);
    EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(),
        parameters);
    criteria = new SpelCriteria(spelExpression, context);
  }
  KeyValueQuery<?> query = new KeyValueQuery(criteria);
  Pageable pageable = accessor.getPageable();
  Sort sort = accessor.getSort();
  query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L));
  if (pageable.isPaged()) {
    query.setRows(pageable.getPageSize());
  } else if (instance.getRows() >= 0) {
    query.setRows(instance.getRows());
  }
  query.setSort(sort.isUnsorted() ? instance.getSort() : sort);
  return query;
}
origin: apache/servicemix-bundles

@SuppressWarnings({ "rawtypes", "unchecked" })
protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) {
  ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
      parameters);
  Object criteria = instance.getCriteria();
  if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {
    SpelExpression spelExpression = getSpelExpression(criteria);
    EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(),
        parameters);
    criteria = new SpelCriteria(spelExpression, context);
  }
  KeyValueQuery<?> query = new KeyValueQuery(criteria);
  Pageable pageable = accessor.getPageable();
  Sort sort = accessor.getSort();
  query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L));
  if (pageable.isPaged()) {
    query.setRows(pageable.getPageSize());
  } else if (instance.getRows() >= 0) {
    query.setRows(instance.getRows());
  }
  query.setSort(sort.isUnsorted() ? instance.getSort() : sort);
  return query;
}
org.springframework.data.domainPageabletoOptional

Javadoc

Returns an Optional so that it can easily be mapped on.

Popular methods of Pageable

  • getPageSize
    Returns the number of items to be returned.
  • getSort
    Returns the sorting parameters.
  • getOffset
  • getPageNumber
    Returns the page to be returned.
  • isPaged
  • unpaged
  • isUnpaged
  • previousOrFirst
  • hasPrevious
  • next
  • first
  • getSortOr
    Returns the current Sort or the given one if the current one is unsorted.
  • first,
  • getSortOr

Popular in Java

  • Finding current android device location
  • scheduleAtFixedRate (ScheduledExecutorService)
  • startActivity (Activity)
  • setContentView (Activity)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Dictionary (java.util)
    The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to valu
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now