/** * Whether the path is absolute (starts with a slash) or not. * * @param path the path * @return true if it starts with a slash */ public static boolean isAbsolute(String path) { assert isValid(path) : "Invalid path ["+path+"]"; return isAbsolutePath(path); }
/** * Whether the path is absolute (starts with a slash) or not. * * @param path the path * @return true if it starts with a slash */ public static boolean isAbsolute(String path) { assert isValid(path) : "Invalid path ["+path+"]"; return isAbsolutePath(path); }
/** * Whether the path is absolute (starts with a slash) or not. * * @param path the path * @return true if it starts with a slash */ public static boolean isAbsolute(String path) { assert isValid(path) : "Invalid path ["+path+"]"; return isAbsolutePath(path); }
/** * Concatenate path elements. * * @param parentPath the parent path * @param subPath the subPath path to add * @return the concatenated path */ @NotNull public static String concat(String parentPath, String subPath) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; assert isValid(subPath) : "Invalid sub path ["+subPath+"]"; // special cases if (parentPath.isEmpty()) { return subPath; } else if (subPath.isEmpty()) { return parentPath; } else if (isAbsolutePath(subPath)) { throw new IllegalArgumentException("Cannot append absolute path " + subPath); } StringBuilder buff = new StringBuilder(parentPath.length() + subPath.length() + 1); buff.append(parentPath); if (!denotesRootPath(parentPath)) { buff.append('/'); } buff.append(subPath); return buff.toString(); }
/** * Concatenate path elements. * * @param parentPath the parent path * @param subPath the subPath path to add * @return the concatenated path */ @NotNull public static String concat(String parentPath, String subPath) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; assert isValid(subPath) : "Invalid sub path ["+subPath+"]"; // special cases if (parentPath.isEmpty()) { return subPath; } else if (subPath.isEmpty()) { return parentPath; } else if (isAbsolutePath(subPath)) { throw new IllegalArgumentException("Cannot append absolute path " + subPath); } StringBuilder buff = new StringBuilder(parentPath.length() + subPath.length() + 1); buff.append(parentPath); if (!denotesRootPath(parentPath)) { buff.append('/'); } buff.append(subPath); return buff.toString(); }
/** * Concatenate path elements. * * @param parentPath the parent path * @param subPath the subPath path to add * @return the concatenated path */ @Nonnull public static String concat(String parentPath, String subPath) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; assert isValid(subPath) : "Invalid sub path ["+subPath+"]"; // special cases if (parentPath.isEmpty()) { return subPath; } else if (subPath.isEmpty()) { return parentPath; } else if (isAbsolutePath(subPath)) { throw new IllegalArgumentException("Cannot append absolute path " + subPath); } StringBuilder buff = new StringBuilder(parentPath.length() + subPath.length() + 1); buff.append(parentPath); if (!denotesRootPath(parentPath)) { buff.append('/'); } buff.append(subPath); return buff.toString(); }
/** * Concatenate path elements. * * @param parentPath the parent path * @param relativePaths the relative path elements to add * @return the concatenated path */ @NotNull public static String concat(String parentPath, String... relativePaths) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; int parentLen = parentPath.length(); int size = relativePaths.length; StringBuilder buff = new StringBuilder(parentLen + size * 5); buff.append(parentPath); boolean needSlash = parentLen > 0 && !denotesRootPath(parentPath); for (String s : relativePaths) { assert isValid(s); if (isAbsolutePath(s)) { throw new IllegalArgumentException("Cannot append absolute path " + s); } if (!s.isEmpty()) { if (needSlash) { buff.append('/'); } buff.append(s); needSlash = true; } } return buff.toString(); }
/** * Concatenate path elements. * * @param parentPath the parent path * @param relativePaths the relative path elements to add * @return the concatenated path */ @NotNull public static String concat(String parentPath, String... relativePaths) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; int parentLen = parentPath.length(); int size = relativePaths.length; StringBuilder buff = new StringBuilder(parentLen + size * 5); buff.append(parentPath); boolean needSlash = parentLen > 0 && !denotesRootPath(parentPath); for (String s : relativePaths) { assert isValid(s); if (isAbsolutePath(s)) { throw new IllegalArgumentException("Cannot append absolute path " + s); } if (!s.isEmpty()) { if (needSlash) { buff.append('/'); } buff.append(s); needSlash = true; } } return buff.toString(); }
/** * Concatenate path elements. * * @param parentPath the parent path * @param relativePaths the relative path elements to add * @return the concatenated path */ @Nonnull public static String concat(String parentPath, String... relativePaths) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; int parentLen = parentPath.length(); int size = relativePaths.length; StringBuilder buff = new StringBuilder(parentLen + size * 5); buff.append(parentPath); boolean needSlash = parentLen > 0 && !denotesRootPath(parentPath); for (String s : relativePaths) { assert isValid(s); if (isAbsolutePath(s)) { throw new IllegalArgumentException("Cannot append absolute path " + s); } if (!s.isEmpty()) { if (needSlash) { buff.append('/'); } buff.append(s); needSlash = true; } } return buff.toString(); }
/** * Calculate the number of elements in the path. The root path has zero * elements. * * @param path the path * @return the number of elements */ public static int getDepth(String path) { assert isValid(path) : "Invalid path ["+path+"]"; if (path.isEmpty()) { return 0; } int count = 1, i = 0; if (isAbsolutePath(path)) { if (denotesRootPath(path)) { return 0; } i++; } while (true) { i = path.indexOf('/', i) + 1; if (i == 0) { return count; } count++; } }
/** * Calculate the number of elements in the path. The root path has zero * elements. * * @param path the path * @return the number of elements */ public static int getDepth(String path) { assert isValid(path) : "Invalid path ["+path+"]"; if (path.isEmpty()) { return 0; } int count = 1, i = 0; if (isAbsolutePath(path)) { if (denotesRootPath(path)) { return 0; } i++; } while (true) { i = path.indexOf('/', i) + 1; if (i == 0) { return count; } count++; } }
/** * Calculate the number of elements in the path. The root path has zero * elements. * * @param path the path * @return the number of elements */ public static int getDepth(String path) { assert isValid(path) : "Invalid path ["+path+"]"; if (path.isEmpty()) { return 0; } int count = 1, i = 0; if (isAbsolutePath(path)) { if (denotesRootPath(path)) { return 0; } i++; } while (true) { i = path.indexOf('/', i) + 1; if (i == 0) { return count; } count++; } }