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

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

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

import javax.annotation.Nullable;

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 TypeSerializer typeSerializer, final Iterable> ranges, @Nullable final String alias) {
        super(searchModel, typeSerializer, alias);
        this.ranges = ranges;
    }

    @Override
    protected String serializedValue() {
        return ":range" + toRangeExpression(ranges);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy