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

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

The newest version!
package io.sphere.sdk.queries;

import io.sphere.sdk.models.Base;
import io.sphere.sdk.models.Point;
import io.sphere.sdk.models.SphereEnumeration;

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

import static io.sphere.sdk.queries.StringQuerySortingModel.normalize;
import static io.sphere.sdk.utils.SphereInternalUtils.toStream;
import static java.util.stream.Collectors.toList;

public class QueryModelImpl extends Base implements QueryModel {
    @Nullable
    private final QueryModel parent;
    @Nullable
    private final String pathSegment;

    protected QueryModelImpl(@Nullable final QueryModel parent, @Nullable final String pathSegment) {
        this.parent = parent;
        this.pathSegment = pathSegment;
    }

    @Override
    @Nullable
    public String getPathSegment() {
        return pathSegment;
    }

    @Nullable
    @Override
    public QueryModel getParent() {
        return parent;
    }

    protected CurrencyCodeQueryModel currencyCodeModel(final String pathSegment) {
        return new CurrencyCodeQueryModelImpl<>(this, pathSegment);
    }

    protected MoneyQueryModel moneyQueryModel(final String pathSegment) {
        return moneyModel(pathSegment);
    }

    protected MoneyQueryModel moneyModel(final String pathSegment) {
        return new MoneyQueryModelImpl<>(this, pathSegment);
    }

    protected AnyReferenceQueryModel anyReferenceQueryModel(final String pathSegment) {
        return new AnyReferenceQueryModelImpl <>(this, pathSegment);
    }

    protected AnyReferenceQueryModel anyReferenceModel(final String pathSegment) {
        return new AnyReferenceQueryModelImpl <>(this, pathSegment);
    }

    protected  ReferenceQueryModel referenceModel(final String pathSegment) {
        return new ReferenceQueryModelImpl<>(this, pathSegment);
    }

    protected  ReferenceQueryModel referenceQueryModel(final String pathSegment) {
        return new ReferenceQueryModelImpl<>(this, pathSegment);
    }

    protected  ReferenceOptionalQueryModel referenceOptionalModel(final String pathSegment) {
        return new ReferenceOptionalQueryModelImpl<>(this, pathSegment);
    }

    protected  ReferenceOptionalQueryModel referenceOptionalQueryModel(final String pathSegment) {
        return referenceOptionalModel(pathSegment);
    }

    protected  ReferenceCollectionQueryModel referenceCollectionQueryModel(final String pathSegment) {
        return new ReferenceCollectionQueryModelImpl<>(this, pathSegment);
    }

    protected  ReferenceCollectionQueryModel referenceCollectionModel(final String pathSegment) {
        return new ReferenceCollectionQueryModelImpl<>(this, pathSegment);
    }

    protected  SphereEnumerationQueryModelImpl sphereEnumerationQueryModel(final String pathSegment) {
        return enumerationQueryModel(pathSegment);
    }

    protected  SphereEnumerationQueryModelImpl enumerationQueryModel(final String pathSegment) {
        return new SphereEnumerationQueryModelImpl<>(this, pathSegment);
    }

    protected  SphereEnumerationQueryModelImpl sphereEnumerationCollectionQueryModel(final String pathSegment) {
        return enumerationQueryModel(pathSegment);
    }

    protected StringQuerySortingModel stringModel(@Nullable final QueryModel parent, final String pathSegment) {
        return new StringQuerySortingModelImpl<>(parent, pathSegment);
    }

    protected StringQuerySortingModel stringQuerySortingModel(final String pathSegment) {
        return stringModel(pathSegment);
    }

    protected StringQuerySortingModel stringModel(final String pathSegment) {
        return stringModel(this, pathSegment);
    }

    protected StringCollectionQueryModel stringCollectionQueryModel(final String pathSegment) {
        return new StringCollectionQueryModelImpl<>(this, pathSegment);
    }

    protected StringCollectionQueryModel stringCollectionModel(final String pathSegment) {
        return new StringCollectionQueryModelImpl<>(this, pathSegment);
    }

    protected BooleanQueryModel booleanModel(@Nullable final QueryModel parent, final String pathSegment) {
        return new BooleanQueryModelImpl<>(parent, pathSegment);
    }

    protected BooleanQueryModel booleanModel(final String pathSegment) {
        return booleanModel(this, pathSegment);
    }

    protected BooleanQueryModel booleanQueryModel(final String pathSegment) {
        return booleanModel(this, pathSegment);
    }

    protected CountryQueryModel countryQueryModel(final String pathSegment) {
        return new CountryQueryModelImpl<>(this, pathSegment);
    }

    protected LongQuerySortingModel longModel(@Nullable final QueryModel parent, final String pathSegment) {
        return new LongQuerySortingModelImpl<>(parent, pathSegment);
    }

    protected LongQuerySortingModel longQuerySortingModel(final String pathSegment) {
        return longModel(this, pathSegment);
    }

    protected LongQuerySortingModel longModel(final String pathSegment) {
        return longModel(this, pathSegment);
    }

    protected BigDecimalQuerySortingModel bigDecimalModel(@Nullable final QueryModel parent, final String pathSegment) {
        return new BigDecimalQuerySortingModelImpl<>(parent, pathSegment);
    }

    protected BigDecimalQuerySortingModel bigDecimalQuerySortingModel(final String pathSegment) {
        return bigDecimalModel(this, pathSegment);
    }

    protected BigDecimalQuerySortingModel bigDecimalModel(final String pathSegment) {
        return bigDecimalModel(this, pathSegment);
    }


    protected IntegerQuerySortingModel integerQuerySortingModel(final String pathSegment) {
        return integerModel(this, pathSegment);
    }

    protected IntegerQuerySortingModel integerModel(final String pathSegment) {
        return integerModel(this, pathSegment);
    }

    protected IntegerQuerySortingModel integerModel(@Nullable final QueryModel parent, final String pathSegment) {
        return new IntegerQuerySortingModelImpl<>(parent, pathSegment);
    }

    protected DoubleQuerySortingModel doubleModel(final String pathSegment) {
        return new DoubleQuerySortingModelImpl<>(this, pathSegment);
    }

    protected LocalizedStringQuerySortingModelImpl localizedStringQuerySortingModel(final String pathSegment) {
        return new LocalizedStringQuerySortingModelImpl<>(this, pathSegment);
    }

    protected LocalizedStringQuerySortingModel localizedStringQueryModel(final String pathSegment) {
        return new LocalizedStringQuerySortingModelImpl<>(this, pathSegment);
    }

    protected LocalizedStringQuerySortingModelImpl localizedStringOptionalQueryModel(final String pathSegment) {
        return new LocalizedStringQuerySortingModelImpl<>(this, pathSegment);
    }

    protected final TimestampSortingModel timestampSortingModel(final String pathSegment) {
        return new TimestampSortingModelImpl<>(this, pathSegment);
    }

    protected final AddressQueryModel addressModel(final String pathSegment) {
        return new AddressQueryModelImpl<>(this, pathSegment);
    }

    protected final AddressQueryModel addressQueryModel(final String pathSegment) {
        return addressModel(pathSegment);
    }

    protected final AddressCollectionQueryModel addressCollectionQueryModel(final String pathSegment){
        return new AddressCollectionQueryModelImpl<>(parent, pathSegment);
    }

    protected final LocaleQuerySortingModel localeQueryModel(final String pathSegment) {
        return new LocaleQuerySortingModelImpl<>(this, pathSegment);
    }

    protected final LocaleQuerySortingModel localeQuerySortingModel(final String pathSegment) {
        return new LocaleQuerySortingModelImpl<>(this, pathSegment);
    }

    @SuppressWarnings("unchecked")
    protected  QueryPredicate isPredicate(final V value) {
        final V normalizedValue = value instanceof String ? (V) normalize((String) value) : value;
        return ComparisonQueryPredicate.ofIsEqualTo(this, normalizedValue);
    }

    protected  QueryPredicate isNotPredicate(final V value) {
        return ComparisonQueryPredicate.ofIsNotEqualTo(this, value);
    }

    protected QueryPredicate isNotPredicate(final String value) {
        return ComparisonQueryPredicate.ofIsNotEqualTo(this, normalize(value));
    }

    protected  QueryPredicate isInPredicate(final Iterable args) {
        return new IsInQueryPredicate<>(this, args);
    }

    protected QueryPredicate withinCirclePredicate(final Point center, final Double radius) {
        return new WithinCircleQueryPredicate(this, center, radius);
    }

    protected  QueryPredicate isNotInPredicate(final Iterable args) {
        return new IsNotInQueryPredicate<>(this, args);
    }

    protected  QueryPredicate isGreaterThanPredicate(final V value) {
        return ComparisonQueryPredicate.ofIsGreaterThan(this, value);
    }

    protected  QueryPredicate isLessThanPredicate(final V value) {
        return ComparisonQueryPredicate.ofIsLessThan(this, value);
    }

    protected  QueryPredicate isLessThanOrEqualToPredicate(final V value) {
        return ComparisonQueryPredicate.ofIsLessThanOrEqualTo(this, value);
    }

    protected  QueryPredicate isGreaterThanOrEqualToPredicate(final V value) {
        return ComparisonQueryPredicate.ofGreaterThanOrEqualTo(this, value);
    }

    protected QueryPredicate isPresentPredicate() {
        return new OptionalQueryPredicate<>(this, true);
    }

    protected QueryPredicate isNotPresentPredicate() {
        return new OptionalQueryPredicate<>(this, false);
    }

    protected  QueryPredicate embedPredicate(final QueryPredicate embeddedPredicate) {
        return new EmbeddedQueryPredicate<>(this, embeddedPredicate);
    }

    protected QueryPredicate isEmptyCollectionQueryPredicate() {
        return new QueryModelQueryPredicate(this){
            @Override
            protected String render() {
                return " is empty";
            }
        };
    }

    protected QueryPredicate isNotEmptyCollectionQueryPredicate() {
        return new QueryModelQueryPredicate(this){
            @Override
            protected String render() {
                return " is not empty";
            }
        };
    }

    protected List normalizeIterable(final Iterable items) {
        return toStream(items)
                .map(StringQuerySortingModel::normalize).collect(toList());
    }

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

    protected   List transformSphereEnumeration(final Iterable items) {
        return toStream(items)
                .map(enumValue -> enumValue.toSphereName())
                .map(StringQuerySortingModel::normalize)
                .collect(Collectors.toList());
    }

    protected EnumQueryModel enumQueryModel(final String name) {
        return new EnumLikeQueryModelImpl<>(this, name);
    }

    protected LocalizedEnumQueryModel localizedEnumQueryModel(final String name) {
        return new EnumLikeQueryModelImpl<>(this, name);
    }

    protected GeoJSONQueryModel geoJSONQueryModel(final String pathName) {
        return new GeoJSONQueryModelImpl<>(this, pathName);
    }

    protected KeyReferenceQueryModelImpl keyReferenceQueryModel(final String pathSegment){
        return new KeyReferenceQueryModelImpl<>(this, pathSegment);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy