package com.r11.tools.controller.internal.path;

public final class PathBuilder {

    private static final String PATH_SEPARATOR = "/";

    private PathBuilder() {

    }

    public static String resolvePathOf(String globalPath, String scopedPath) {
        String resolvedPath =
                PathBuilder.removeTrailingPathSeparator(globalPath) +
                        PathBuilder.removeTrailingPathSeparator(scopedPath);

        if (resolvedPath.endsWith(PATH_SEPARATOR)) {
            resolvedPath = resolvedPath.substring(0, resolvedPath.length() - 1);
        }

        return PATH_SEPARATOR + resolvedPath;
    }

    private static String removeTrailingPathSeparator(String path) {
        if (path.endsWith(PATH_SEPARATOR)) {
            return path.substring(0, path.length() - 1);
        }

        return path;
    }
}