String (@NotNull String path) { final int end = path.endsWith("/") ? path.length() - 1 : path.length(); final int slashIndex = path.lastIndexOf("/", end - 1); if (slashIndex != -1) { return path.substring(slashIndex + 1, end); } if (end != path.length()) { return path.substring(0, end); } return path; }