/** * Get the index of the next slash. * * @param path the path * @param index the starting index * @return the index of the next slash (possibly the starting index), or -1 * if not found */ public static int getNextSlash(String path, int index) { assert isValid(path) : "Invalid path ["+path+"]"; return path.indexOf('/', index); }
/** * Get the index of the next slash. * * @param path the path * @param index the starting index * @return the index of the next slash (possibly the starting index), or -1 * if not found */ public static int getNextSlash(String path, int index) { assert isValid(path) : "Invalid path ["+path+"]"; return path.indexOf('/', index); }
/** * Get the index of the next slash. * * @param path the path * @param index the starting index * @return the index of the next slash (possibly the starting index), or -1 * if not found */ public static int getNextSlash(String path, int index) { assert isValid(path) : "Invalid path ["+path+"]"; return path.indexOf('/', index); }
/** * 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); }
/** * Whether the path is the root path ("/"). * * @param path the path * @return whether this is the root */ public static boolean denotesRoot(String path) { assert isValid(path) : "Invalid path ["+path+"]"; return denotesRootPath(path); }
private static String[] checkPaths(String[] paths) throws CliArgumentException { if (paths == null) { return paths; } for (String p : paths) { if (!PathUtils.isValid(p)) { throw new CliArgumentException("Following path is not valid: " + p, 1); } } return paths; }
/** * Whether the path is the root path ("/"). * * @param path the path * @return whether this is the root */ public static boolean denotesRoot(String path) { assert isValid(path) : "Invalid path ["+path+"]"; return denotesRootPath(path); }
/** * Whether the path is the root path ("/"). * * @param path the path * @return whether this is the root */ public static boolean denotesRoot(String path) { assert isValid(path) : "Invalid path ["+path+"]"; return denotesRootPath(path); }
private static String[] checkPaths(String[] paths) throws CliArgumentException { if (paths == null) { return paths; } for (String p : paths) { if (!PathUtils.isValid(p)) { throw new CliArgumentException("Following path is not valid: " + p, 1); } } return paths; }
/** * Relativize a path wrt. a parent path such that * {@code relativize(parentPath, concat(parentPath, path)) == paths} * holds. * * @param parentPath parent pth * @param path path to relativize * @return relativized path */ @NotNull public static String relativize(String parentPath, String path) { assert isValid(parentPath) : "Invalid parent path ["+parentPath+"]"; assert isValid(path) : "Invalid path ["+path+"]"; if (parentPath.equals(path)) { return ""; } String prefix = denotesRootPath(parentPath) ? parentPath : parentPath + '/'; if (path.startsWith(prefix)) { return path.substring(prefix.length()); } throw new IllegalArgumentException("Cannot relativize " + path + " wrt. " + parentPath); }
/** * Get the last element of the (absolute or relative) path. The name of the * root node ("/") and the name of the empty path ("") is the empty path. * * @param path the complete path * @return the last element */ @NotNull public static String getName(String path) { assert isValid(path) : "Invalid path ["+path+"]"; if (path.isEmpty() || denotesRootPath(path)) { return ROOT_NAME; } int end = path.length() - 1; int pos = path.lastIndexOf('/', end); if (pos != -1) { return path.substring(pos + 1, end + 1); } return path; }
/** * Get the last element of the (absolute or relative) path. The name of the * root node ("/") and the name of the empty path ("") is the empty path. * * @param path the complete path * @return the last element */ @NotNull public static String getName(String path) { assert isValid(path) : "Invalid path ["+path+"]"; if (path.isEmpty() || denotesRootPath(path)) { return ROOT_NAME; } int end = path.length() - 1; int pos = path.lastIndexOf('/', end); if (pos != -1) { return path.substring(pos + 1, end + 1); } return path; }
/** * Get the last element of the (absolute or relative) path. The name of the * root node ("/") and the name of the empty path ("") is the empty path. * * @param path the complete path * @return the last element */ @Nonnull public static String getName(String path) { assert isValid(path) : "Invalid path ["+path+"]"; if (path.isEmpty() || denotesRootPath(path)) { return ROOT_NAME; } int end = path.length() - 1; int pos = path.lastIndexOf('/', end); if (pos != -1) { return path.substring(pos + 1, end + 1); } return path; }
/** * Check if a path is a (direct or indirect) ancestor of another path. * * @param ancestor the ancestor path * @param path the potential offspring path * @return true if the path is an offspring of the ancestor */ public static boolean isAncestor(String ancestor, String path) { assert isValid(ancestor) : "Invalid parent path ["+ancestor+"]"; assert isValid(path) : "Invalid path ["+path+"]"; if (ancestor.isEmpty() || path.isEmpty()) { return false; } if (denotesRoot(ancestor)) { if (denotesRoot(path)) { return false; } } else { ancestor += "/"; } return path.startsWith(ancestor); }
/** * Check if a path is a (direct or indirect) ancestor of another path. * * @param ancestor the ancestor path * @param path the potential offspring path * @return true if the path is an offspring of the ancestor */ public static boolean isAncestor(String ancestor, String path) { assert isValid(ancestor) : "Invalid parent path ["+ancestor+"]"; assert isValid(path) : "Invalid path ["+path+"]"; if (ancestor.isEmpty() || path.isEmpty()) { return false; } if (denotesRoot(ancestor)) { if (denotesRoot(path)) { return false; } } else { ancestor += "/"; } return path.startsWith(ancestor); }
public boolean isEnabled() { if (useIfExists == null) { return true; } if (!PathUtils.isValid(useIfExists)) { return false; } NodeState nodeState = root; for (String element : PathUtils.elements(useIfExists)) { if (element.startsWith("@")) { return nodeState.hasProperty(element.substring(1)); } nodeState = nodeState.getChildNode(element); if (!nodeState.exists()) { return false; } } return true; }
private static boolean isEnabled(NodeState definition, NodeState root) { String useIfExists = definition.getString(IndexConstants.USE_IF_EXISTS); if (useIfExists == null) { return true; } if (!PathUtils.isValid(useIfExists)) { return false; } NodeState nodeState = root; for (String element : PathUtils.elements(useIfExists)) { if (element.startsWith("@")) { return nodeState.hasProperty(element.substring(1)); } nodeState = nodeState.getChildNode(element); if (!nodeState.exists()) { return false; } } return true; }
private static boolean isEnabled(NodeState definition, NodeState root) { String useIfExists = definition.getString(IndexConstants.USE_IF_EXISTS); if (useIfExists == null) { return true; } if (!PathUtils.isValid(useIfExists)) { return false; } NodeState nodeState = root; for (String element : PathUtils.elements(useIfExists)) { if (element.startsWith("@")) { return nodeState.hasProperty(element.substring(1)); } nodeState = nodeState.getChildNode(element); if (!nodeState.exists()) { return false; } } return true; }