io.sphere.sdk.search.model.SortExpressionImpl Maven / Gradle / Ivy
package io.sphere.sdk.search.model;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.search.SearchSortDirection;
import io.sphere.sdk.search.SortExpression;
import io.sphere.sdk.search.model.SearchModel;
import static io.sphere.sdk.utils.IterableUtils.toStream;
import static java.util.stream.Collectors.joining;
class SortExpressionImpl extends Base implements SortExpression {
private final SearchModel searchModel;
private final SearchSortDirection direction;
protected SortExpressionImpl(final SearchModel searchModel, final SearchSortDirection direction) {
this.searchModel = searchModel;
this.direction = direction;
}
@Override
public String expression() {
return renderPath() + " " + direction;
}
@Override
public final String attributePath() {
return toStream(searchModel.buildPath()).collect(joining("."));
}
@Override
public final boolean equals(Object o) {
return o != null && o instanceof SortExpression && expression().equals(((SortExpression) o).expression());
}
@Override
public final int hashCode() {
return expression().hashCode();
}
private String renderPath() {
return toStream(searchModel.buildPath()).collect(joining("."));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy