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

io.sphere.sdk.queries.SphereQuerySort Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
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