Example #1
0
 /**
  * Join each element in paths in order, separated by {@code TachyonURI.SEPARATOR}.
  *
  * <p>For example, {@code concatPath("/myroot/", "dir", 1L, "filename")} returns {@code
  * "/myroot/dir/1/filename"}, or {@code concatPath("tachyon://myroot", "dir", "filename")} returns
  * {@code "tachyon://myroot/dir/filename"}. Note that a null element in paths is treated as empty
  * string, i.e., "".
  *
  * @param paths to concatenate
  * @return joined path
  * @throws IllegalArgumentException
  */
 public static String concatPath(Object... paths) throws IllegalArgumentException {
   if (null == paths) {
     throw new IllegalArgumentException("Can not concatenate a null set of paths.");
   }
   String path;
   String trimmedPath;
   List<String> trimmedPathList = new ArrayList<String>();
   if (paths.length > 0 && paths[0] != null && !paths[0].toString().isEmpty()) {
     path = paths[0].toString().trim();
     trimmedPath = CharMatcher.is(TachyonURI.SEPARATOR.charAt(0)).trimTrailingFrom(path);
     trimmedPathList.add(trimmedPath);
   }
   for (int k = 1; k < paths.length; k++) {
     if (null == paths[k]) {
       continue;
     }
     path = paths[k].toString().trim();
     trimmedPath = CharMatcher.is(TachyonURI.SEPARATOR.charAt(0)).trimFrom(path);
     if (!trimmedPath.isEmpty()) {
       trimmedPathList.add(trimmedPath);
     }
   }
   if (trimmedPathList.size() == 1 && trimmedPathList.get(0).isEmpty()) {
     // paths[0] must be "[/]+"
     return TachyonURI.SEPARATOR;
   }
   return Joiner.on(TachyonURI.SEPARATOR).join(trimmedPathList);
 }
Example #2
0
 public String getName() {
   if (TachyonURI.SEPARATOR.equals(mAbsolutePath)) {
     return "root";
   } else {
     return mName;
   }
 }
Example #3
0
 /**
  * Check if the given path is the root.
  *
  * @param path The path to check
  * @return true if the path is the root
  * @throws InvalidPathException
  */
 public static boolean isRoot(String path) throws InvalidPathException {
   return TachyonURI.SEPARATOR.equals(cleanPath(path));
 }