org.springframework.data.domain.Sort.stream()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.springframework.data.domain.Sort.stream()方法的一些代码示例,展示了Sort.stream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.stream()方法的具体详情如下:
包路径:org.springframework.data.domain.Sort
类名称:Sort
方法名:stream

Sort.stream介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Converts the given {@link Sort} to {@link OrderSpecifier}.
 *
 * @param sort
 * @return
 */
protected List<OrderSpecifier<?>> toOrderSpecifiers(Sort sort) {
  if (sort instanceof QSort) {
    return ((QSort) sort).getOrderSpecifiers();
  }
  return sort.stream().map(this::toOrder).collect(Collectors.toList());
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Adds a {@link Sort} to the {@link Query} instance.
 *
 * @param sort
 * @return
 */
public Query with(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (sort.isUnsorted()) {
    return this;
  }
  sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {
    throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
        + "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
  });
  this.sort = this.sort.and(sort);
  return this;
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * @return the sort {@link Document}.
 */
public Document getSortObject() {
  if (this.sort.isUnsorted()) {
    return new Document();
  }
  Document document = new Document();
  this.sort.stream()//
      .forEach(order -> document.put(order.getProperty(), order.isAscending() ? 1 : -1));
  return document;
}

代码示例来源:origin: spring-projects/spring-data-neo4j

private String getSortOrder(Sort sort) {
  return sort.stream()
      .map(order -> order.getProperty() + " " + order.getDirection())
      .collect(Collectors.joining(", "));
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Applies the given {@link Sort} to the given {@link SpringDataMongodbQuery}.
 *
 * @param query
 * @param sort
 * @return
 */
private SpringDataMongodbQuery<T> applySorting(SpringDataMongodbQuery<T> query, Sort sort) {
  // TODO: find better solution than instanceof check
  if (sort instanceof QSort) {
    List<OrderSpecifier<?>> orderSpecifiers = ((QSort) sort).getOrderSpecifiers();
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier<?>[orderSpecifiers.size()]));
    return query;
  }
  sort.stream().map(this::toOrder).forEach(query::orderBy);
  return query;
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Adds a {@link Sort} to the {@link Query} instance.
 *
 * @param sort
 * @return
 */
public Query with(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (sort.isUnsorted()) {
    return this;
  }
  sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {
    throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
        + "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
  });
  this.sort = this.sort.and(sort);
  return this;
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * @return the sort {@link Document}.
 */
public Document getSortObject() {
  if (this.sort.isUnsorted()) {
    return new Document();
  }
  Document document = new Document();
  this.sort.stream()//
      .forEach(order -> document.put(order.getProperty(), order.isAscending() ? 1 : -1));
  return document;
}

代码示例来源:origin: Microsoft/spring-data-cosmosdb

private String generateQuerySort(@NonNull Sort sort) {
  if (sort.isUnsorted()) {
    return "";
  }
  final String queryTail = "ORDER BY";
  final List<String> subjects = sort.stream().map(this::getParameter).collect(Collectors.toList());
  return queryTail + " " + String.join(",", subjects);
}

代码示例来源:origin: hatunet/spring-data-mybatis

protected String buildStandardOrderBy(Sort sort) {
  if (null == sort || sort.isUnsorted()) {
    return "";
  }
  final Map<String, String> map = findNormalColumns().stream()
      .collect(Collectors.toMap(p -> p.getName(), p -> p.getColumnName()));
  return " order by " + sort.stream()
      .map(order -> map.getOrDefault(order.getProperty(), order.getProperty())
          + ' ' + order.getDirection().name().toLowerCase())
      .collect(Collectors.joining(","));
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-datastore

public static void applyQueryOptions(StructuredQuery.Builder builder, DatastoreQueryOptions queryOptions,
    DatastorePersistentEntity<?> persistentEntity) {
  if (queryOptions == null) {
    return;
  }
  if (queryOptions.getLimit() != null) {
    builder.setLimit(queryOptions.getLimit());
  }
  if (queryOptions.getOffset() != null) {
    builder.setOffset(queryOptions.getOffset());
  }
  if (queryOptions.getSort() != null && persistentEntity != null) {
    queryOptions.getSort().stream()
        .map((order) -> createOrderBy(persistentEntity, order))
        .forEachOrdered((orderBy) -> builder.addOrderBy(orderBy));
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

public static void applyQueryOptions(StructuredQuery.Builder builder, DatastoreQueryOptions queryOptions,
    DatastorePersistentEntity<?> persistentEntity) {
  if (queryOptions == null) {
    return;
  }
  if (queryOptions.getLimit() != null) {
    builder.setLimit(queryOptions.getLimit());
  }
  if (queryOptions.getOffset() != null) {
    builder.setOffset(queryOptions.getOffset());
  }
  if (queryOptions.getSort() != null && persistentEntity != null) {
    queryOptions.getSort().stream()
        .map((order) -> createOrderBy(persistentEntity, order))
        .forEachOrdered((orderBy) -> builder.addOrderBy(orderBy));
  }
}

相关文章