io.sphere.sdk.queries.SphereQuerySort Maven / Gradle / Ivy
package io.sphere.sdk.queries;
import java.util.Optional;
public class SphereQuerySort extends QuerySortBase {
private final QueryModel path;
private final QuerySortDirection direction;
protected SphereQuerySort(QueryModel path, QuerySortDirection direction) {
this.path = path;
this.direction = direction;
}
public String toSphereSort() {
return renderPath(path) + " " + direction.toString().toLowerCase();
}
private String renderPath(final QueryModel model) {
if (model.getParent() != null) {
final String beginning = renderPath(model.getParent());
return beginning +
(model.getPathSegment() != null ?
(beginning.isEmpty() ? "" : ".") + model.getPathSegment() : "");
} else {
return Optional.ofNullable(model.getPathSegment()).orElse("");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy