All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.queries.StringQuerySortingModelImpl Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.queries;

import javax.annotation.Nullable;
import java.util.List;

import static io.sphere.sdk.utils.IterableUtils.toStream;
import static java.util.stream.Collectors.toList;

final class StringQuerySortingModelImpl extends QueryModelImpl implements StringQuerySortingModel {
    public StringQuerySortingModelImpl(@Nullable final QueryModel parent, final String pathSegment) {
        super(parent, pathSegment);
    }

    @Override
    public QuerySort sort(final QuerySortDirection sortDirection) {
        return new SphereQuerySort<>(this, sortDirection);
    }

    @Override
    public DirectionlessQuerySort sort() {
        return new DirectionlessQuerySort<>(this);
    }

    /**
     * Escapes Strings like that (Scala notation) """query by name " test name"""
     * @param s the unescaped String
     * @return the escaped string
     */
    private static String escape(final String s) {
        return StringQuerySortingModel.escape(s);
    }

    private static String normalize(final String s) {
        return StringQuerySortingModel.normalize(s);
    }

    @Override
    public QueryPredicate is(final String s) {
        return isPredicate(s);
    }

    @Override
    public QueryPredicate isNot(final String s) {
        return isNotPredicate(s);
    }

    @Override
    public QueryPredicate isIn(final Iterable args) {
        return new IsInQueryPredicate<>(this, normalize(args));
    }

    @Override
    public QueryPredicate isGreaterThan(final String s) {
        return ComparisonQueryPredicate.ofIsGreaterThan(this, normalize(s));
    }

    @Override
    public QueryPredicate isLessThan(final String s) {
        return ComparisonQueryPredicate.ofIsLessThan(this, normalize(s));
    }

    @Override
    public QueryPredicate isLessThanOrEqualTo(final String s) {
        return ComparisonQueryPredicate.ofIsLessThanOrEqualTo(this, normalize(s));
    }

    @Override
    public QueryPredicate isGreaterThanOrEqualTo(final String s) {
        return ComparisonQueryPredicate.ofGreaterThanOrEqualTo(this, normalize(s));
    }

    @Override
    public QueryPredicate isNotIn(final Iterable args) {
        return new IsNotInQueryPredicate<>(this, normalize(args));
    }

    @Override
    public QueryPredicate isPresent() {
        return isPresentPredicate();
    }

    @Override
    public QueryPredicate isNotPresent() {
        return isNotPresentPredicate();
    }

    private static List normalize(final Iterable args) {
        return toStream(args).map(x -> normalize(x)).collect(toList());
    }

    private static List escape(final Iterable args) {
        return toStream(args).map(x -> escape(x)).collect(toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy