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

io.sphere.sdk.queries.ReferenceQueryModelImpl 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;

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

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

    @Override
    public QueryPredicate isInIds(final List ids) {
        return new IsInQueryPredicate<>(idSegment(),
                ids.stream()
                .map(StringQuerySortingModel::normalize).collect(toList()));
    }

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy