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

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

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

import io.sphere.sdk.models.Referenceable;

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

import static java.util.stream.Collectors.toList;

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

    @Override
    public  QueryPredicate is(final Referenceable reference) {
        return id().is(reference.toReference().getId());
    }

    @Override
    public  QueryPredicate isIn(final List> elements) {
        final List ids = elements.stream().map(elem -> elem.toReference().getId()).collect(toList());
        return isInIds(ids);
    }

    @Override
    public QueryPredicate isInIds(final List ids) {
        return new IsInQueryPredicate<>(idSegment(), ids);
    }

    @Override
    public StringQueryModel id() {
        return stringModel("id");
    }

    @Override
    public StringQueryModel typeId() {
        return stringModel("typeId");
    }

    private QueryModelImpl idSegment() {
        return new QueryModelImpl<>(this, "id");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy