io.sphere.sdk.search.SearchModel Maven / Gradle / Ivy
package io.sphere.sdk.search;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public interface SearchModel {
@Nullable
String getPathSegment();
@Nullable
SearchModel getParent();
default List buildPath() {
final List pathSegments = new ArrayList<>();
Optional.ofNullable(getParent()).ifPresent(p -> pathSegments.addAll(p.buildPath()));
Optional.ofNullable(getPathSegment()).ifPresent(ps -> pathSegments.add(ps));
return pathSegments;
}
/**
* Checks if the given pathSegments matches the path of the parents and the current one of this search model.
*
* @param pathSegments the path segments, the most closer element is one the right side
* @return true, if the path segments of this matches exactly pathSegments
*/
default boolean hasPath(final List pathSegments) {
return buildPath().equals(pathSegments);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy