Java Code Examples for io.micronaut.core.util.CollectionUtils#isEmpty()

The following examples show how to use io.micronaut.core.util.CollectionUtils#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sort.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * Create a sort from the given list of orders.
 *
 * @param orderList The order list
 * @return The sort
 */
@JsonCreator
static @NonNull Sort of(
        @JsonProperty("orderBy") @Nullable List<Order> orderList) {
    if (CollectionUtils.isEmpty(orderList)) {
        return UNSORTED;
    }
    return new DefaultSort(orderList);
}
 
Example 2
Source File: PageDelegate.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public Sort getSort() {
    List<io.micronaut.data.model.Sort.Order> orderBy = delegate.getSort().getOrderBy();
    if (CollectionUtils.isEmpty(orderBy)) {
        return Sort.unsorted();
    } else {
        return new SortDelegate(delegate.getSort());
    }
}
 
Example 3
Source File: UpdateByMethod.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected MethodMatchInfo buildInfo(
        MethodMatchContext matchContext,
        @NonNull ClassElement queryResultType,
        @Nullable QueryModel query) {
    if (query == null) {
        matchContext.fail("Cannot implement batch update operation that doesn't perform a query");
        return null;
    }
    if (CollectionUtils.isNotEmpty(query.getProjections())) {
        matchContext.fail("Projections are not supported on batch updates");
        return null;
    }
    String[] updateProperties;
    if (!(query instanceof RawQuery)) {

        List<QueryModel.Criterion> criterionList = query.getCriteria().getCriteria();
        if (CollectionUtils.isEmpty(criterionList)) {
            matchContext.fail("Cannot implement batch update operation that doesn't perform a query");
            return null;
        }
        Set<String> queryParameters = new HashSet<>();
        for (QueryModel.Criterion criterion : criterionList) {
            if (criterion instanceof QueryModel.PropertyCriterion) {
                QueryModel.PropertyCriterion pc = (QueryModel.PropertyCriterion) criterion;
                Object v = pc.getValue();
                if (v instanceof QueryParameter) {
                    queryParameters.add(((QueryParameter) v).getName());
                }
            }
        }
        List<Element> updateParameters = Arrays.stream(matchContext.getParameters()).filter(p -> !queryParameters.contains(p.getName()))
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(updateParameters)) {
            matchContext.fail("At least one parameter required to update");
            return null;
        }
        Element element = matchContext.getParametersInRole().get(TypeRole.LAST_UPDATED_PROPERTY);
        if (element instanceof PropertyElement) {
            updateParameters.add(element);
        }
        SourcePersistentEntity entity = matchContext.getRootEntity();
        updateProperties = new String[updateParameters.size()];
        for (int i = 0; i < updateProperties.length; i++) {
            Element parameter = updateParameters.get(i);
            String parameterName = parameter.stringValue(Parameter.class).orElse(parameter.getName());
            Optional<String> path = entity.getPath(parameterName);
            if (path.isPresent()) {
                updateProperties[i] = path.get();
            } else {
                matchContext.fail("Cannot perform batch update for non-existent property: " + parameterName);
                return null;
            }
        }
    } else {
        updateProperties = StringUtils.EMPTY_STRING_ARRAY;
    }
    return new MethodMatchInfo(
            queryResultType,
            query,
            getInterceptorElement(matchContext, UpdateMethod.pickUpdateInterceptor(matchContext.getReturnType())),
            MethodMatchInfo.OperationType.UPDATE,
            updateProperties
    );
}
 
Example 4
Source File: DefaultSlice.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * Default constructor.
 * @param content The content
 * @param pageable The pageable
 */
DefaultSlice(List<T> content, Pageable pageable) {
    ArgumentUtils.requireNonNull("pageable", pageable);
    this.content = CollectionUtils.isEmpty(content) ? Collections.emptyList() : content;
    this.pageable = pageable;
}