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

io.sphere.sdk.search.model.RangeExpression Maven / Gradle / Ivy

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

import javax.annotation.Nullable;

import java.util.function.Function;

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

abstract class RangeExpression> extends SearchModelExpression {
    private final Iterable> ranges;

    RangeExpression(final SearchModel searchModel, final Function typeSerializer, final Iterable> ranges, @Nullable final String alias) {
        super(searchModel, typeSerializer, alias);
        this.ranges = requireNonEmpty(ranges);
    }

    /**
     * Turns a group of ranges into an expression of the form ":range(e1 to e2),(e3 to e4),..."
     * @return the generated range expression.
     */
    public String value() {
        return ":range" + toStream(ranges)
                .map(r -> r.serialize(serializer()))
                .filter(r -> !r.isEmpty())
                .collect(joining(","));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy