当前位置: 首页>>代码示例>>Java>>正文


Java Path.getNameCount方法代码示例

本文整理汇总了Java中java.nio.file.Path.getNameCount方法的典型用法代码示例。如果您正苦于以下问题:Java Path.getNameCount方法的具体用法?Java Path.getNameCount怎么用?Java Path.getNameCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Path的用法示例。


在下文中一共展示了Path.getNameCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSuiteName

import java.nio.file.Path; //导入方法依赖的package包/类
private String getSuiteName(Description description) {
    Test test = (Test) TestAttributes.get("test_object");
    if (test == null) {
        return "<ERROR GETTING TEST>";
    }
    if (test instanceof MarathonTestCase) {
        try {
            Path path = ((MarathonTestCase) test).getFile().toPath();
            Path testPath = Constants.getMarathonDirectory(Constants.PROP_TEST_DIR).toPath();
            if (!path.isAbsolute()) {
                return "root";
            }
            Path relativePath = testPath.relativize(path);
            int nameCount = relativePath.getNameCount();
            StringBuilder sb = new StringBuilder("root");
            for (int i = 0; i < nameCount - 1; i++) {
                sb.append("::").append(relativePath.getName(i));
            }
            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return "My Own Test Cases";
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:26,代码来源:AllureMarathonRunListener.java

示例2: isSessionFile

import java.nio.file.Path; //导入方法依赖的package包/类
private static boolean isSessionFile(Path path) {
    if (!Files.isRegularFile(path)) {
        return false;
    }
    final int nameCount = path.getNameCount();
    if (nameCount < 2) {
        return false;
    }

    final String first = path.getName(nameCount - 2).toString();
    if (!SESSION_ID_1ST_PART_PATTERN.matcher(first).matches()) {
        return false;
    }

    final String second = path.getName(nameCount - 1).toString();
    return SESSION_ID_2ND_PART_PATTERN.matcher(second).matches();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:FileBasedSessionDAO.java

示例3: addMedia

import java.nio.file.Path; //导入方法依赖的package包/类
public synchronized void addMedia(PhotatoMedia media) {
    for (Path virtualPath : media.virtualPaths) {
        PhotatoFolder currentFolder = this.virtualRootFolder;

        for (int i = 0; i < virtualPath.getNameCount(); i++) {
            String folderName = virtualPath.getName(i).toString();
            String normalizedFolderName = SearchQueryHelper.normalizeString(folderName);

            PhotatoFolder folder = currentFolder.subFolders.get(normalizedFolderName);
            if (folder == null) {
                folder = new PhotatoFolder(virtualRootPath, currentFolder.fsPath.resolve(folderName));
                currentFolder.subFolders.put(normalizedFolderName, folder);
            }

            currentFolder = folder;
        }

        currentFolder.medias.add(media);
    }
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:21,代码来源:AlbumsManager.java

示例4: processDirectory

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Processes named class files in the given directory. The directory
 * should be the root of a package hierarchy. If classNames is
 * empty, walks the directory hierarchy to find all classes.
 *
 * @param dirname the name of the directory to process
 * @param classNames the names of classes to process
 * @return true for success, false for failure
 * @throws IOException if an I/O error occurs
 */
boolean processDirectory(String dirname, Collection<String> classNames) throws IOException {
    if (!Files.isDirectory(Paths.get(dirname))) {
        err.printf("%s: not a directory%n", dirname);
        return false;
    }

    classPath.add(0, new File(dirname));

    if (classNames.isEmpty()) {
        Path base = Paths.get(dirname);
        int baseCount = base.getNameCount();
        try (Stream<Path> paths = Files.walk(base)) {
            Stream<String> files =
                paths.filter(p -> p.getNameCount() > baseCount)
                     .map(p -> p.subpath(baseCount, p.getNameCount()))
                     .map(Path::toString);
            return doFileNames(files);
        }
    } else {
        return doClassNames(classNames);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:Main.java

示例5: mergeDifferences

import java.nio.file.Path; //导入方法依赖的package包/类
private Path mergeDifferences(Path path, Path newPath) {
    int start = newPath.relativize(path).getNameCount();
    int end = path.getNameCount();
    Path subPath = path.subpath(start, end);

    return newPath.resolve(subPath);
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:8,代码来源:TabUpdater.java

示例6: getBundleSubDir

import java.nio.file.Path; //导入方法依赖的package包/类
private String getBundleSubDir(final Path relChangedDir) {
    if (relChangedDir.getNameCount() == 1) {
        return StringUtils.EMPTY;
    }
    final Path subPath = relChangedDir.subpath(1, relChangedDir.getNameCount());
    // ensure that we use '/' as the JCR path separator, even if the filesystem path uses something else
    return StringUtils.join(subPath.iterator(), '/');
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:9,代码来源:GroovyFilesWatcher.java

示例7: getParentPath

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Returns a path to the parent directory of the given path. If the path actually has a parent
 * path, this is simple. Otherwise, we need to do some trickier things. Returns null if the path
 * is a root or is the empty path.
 */
@Nullable
private static Path getParentPath(Path path) {
  Path parent = path.getParent();

  // Paths that have a parent:
  if (parent != null) {
    // "/foo" ("/")
    // "foo/bar" ("foo")
    // "C:\foo" ("C:\")
    // "\foo" ("\" - current drive for process on Windows)
    // "C:foo" ("C:" - working dir of drive C on Windows)
    return parent;
  }

  // Paths that don't have a parent:
  if (path.getNameCount() == 0) {
    // "/", "C:\", "\" (no parent)
    // "" (undefined, though typically parent of working dir)
    // "C:" (parent of working dir of drive C on Windows)
    //
    // For working dir paths ("" and "C:"), return null because:
    //   A) it's not specified that "" is the path to the working directory.
    //   B) if we're getting this path for recursive delete, it's typically not possible to
    //      delete the working dir with a relative path anyway, so it's ok to fail.
    //   C) if we're getting it for opening a new SecureDirectoryStream, there's no need to get
    //      the parent path anyway since we can safely open a DirectoryStream to the path without
    //      worrying about a symlink.
    return null;
  } else {
    // "foo" (working dir)
    return path.getFileSystem().getPath(".");
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:39,代码来源:MoreFiles.java

示例8: watch

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public PathWatcherHandle watch(Path path, Executor executor, PathWatcher callback) throws IOException {
    path = path.toAbsolutePath();
    if(path.getNameCount() == 0) {
        throw new IllegalArgumentException("Cannot watch the root directory");
    }
    return watchedDirs.getUnchecked(path.getParent()).new WatchedPath(path, executor, callback);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:9,代码来源:PathWatcherServiceImpl.java

示例9: removeMedia

import java.nio.file.Path; //导入方法依赖的package包/类
public synchronized void removeMedia(PhotatoMedia media) {
    for (Path virtualPath : media.virtualPaths) {
        List<PhotatoFolder> foldersStack = new ArrayList<>();
        foldersStack.add(this.virtualRootFolder);

        for (int i = 0; i < virtualPath.getNameCount(); i++) {
            String folderName = virtualPath.getName(i).toString();

            PhotatoFolder folder = foldersStack.get(foldersStack.size() - 1).subFolders.get(folderName);
            if (folder == null) {
                break;
            }

            foldersStack.add(folder);
        }

        // Remove from all parents folders
        for (int i = 0; i < foldersStack.size(); i++) {
            foldersStack.get(i).medias.remove(media);
        }

        // Remove empty folders
        for (int i = foldersStack.size() - 1; i >= 1; i--) {
            if (foldersStack.get(i).isEmpty()) {
                foldersStack.get(i - 1).subFolders.remove(SearchQueryHelper.normalizeString(foldersStack.get(i).filename));
            }
        }
    }
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:30,代码来源:AlbumsManager.java

示例10: names

import java.nio.file.Path; //导入方法依赖的package包/类
public static Iterable<String> names(final Path path) {
    Objects.requireNonNull(path);
    return () -> new Iterator<String>() {
        int index = 0;
        @Override
        public boolean hasNext() {
            return index < path.getNameCount();
        }
        @Override
        public String next() {
            index++;
            return path.getName(index - 1).getFileName().toString();
        }
    };
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:16,代码来源:MorePaths.java

示例11: preVisitDirectory

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public FileVisitResult preVisitDirectory(Path sourceDirectory, BasicFileAttributes attrs) throws IOException {
    if (sourceRoot.equals(sourceDirectory)) {
        return CONTINUE;
    }
    if (sourceDirectory.getNameCount() == 1) {
        return CONTINUE;
    }
    String sourcePath = sourceDirectory.subpath(1, sourceDirectory.getNameCount()).toString();
    Path destinationDirectory = destinationRoot.resolve(sourcePath);
    createDirectories(destinationDirectory);
    return CONTINUE;
}
 
开发者ID:webfolderio,项目名称:cdp4j,代码行数:14,代码来源:ChromiumDownloader.java

示例12: getParentPath

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Returns a path to the parent directory of the given path. If the path actually has a parent
 * path, this is simple. Otherwise, we need to do some trickier things. Returns null if the path
 * is a root or is the empty path.
 */
@Nullable
private static Path getParentPath(Path path) throws IOException {
  Path parent = path.getParent();

  // Paths that have a parent:
  if (parent != null) {
    // "/foo" ("/")
    // "foo/bar" ("foo")
    // "C:\foo" ("C:\")
    // "\foo" ("\" - current drive for process on Windows)
    // "C:foo" ("C:" - working dir of drive C on Windows)
    return parent;
  }

  // Paths that don't have a parent:
  if (path.getNameCount() == 0) {
    // "/", "C:\", "\" (no parent)
    // "" (undefined, though typically parent of working dir)
    // "C:" (parent of working dir of drive C on Windows)
    //
    // For working dir paths ("" and "C:"), return null because:
    //   A) it's not specified that "" is the path to the working directory.
    //   B) if we're getting this path for recursive delete, it's typically not possible to
    //      delete the working dir with a relative path anyway, so it's ok to fail.
    //   C) if we're getting it for opening a new SecureDirectoryStream, there's no need to get
    //      the parent path anyway since we can safely open a DirectoryStream to the path without
    //      worrying about a symlink.
    return null;
  } else {
    // "foo" (working dir)
    return path.getFileSystem().getPath(".");
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:39,代码来源:MoreFiles.java

示例13: testCreateGroup

import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void testCreateGroup() {

	try {
		n5.createGroup(groupName);
	} catch (final IOException e) {
		fail(e.getMessage());
	}

	final Path groupPath = Paths.get(groupName);
	for (int i = 0; i < groupPath.getNameCount(); ++i)
		if (!n5.exists(groupPath.subpath(0, i + 1).toString()))
			fail("Group does not exist");
}
 
开发者ID:saalfeldlab,项目名称:n5,代码行数:15,代码来源:AbstractN5Test.java

示例14: compareTo

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public int compareTo(@Nullable final ResourceElement other) {
    if (other == null) return -1;

    final Path file = getFile();
    final Path otherFile = other.getFile();

    return file.getNameCount() - otherFile.getNameCount();
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:10,代码来源:ResourceElement.java

示例15: findChipKitPathIndex

import java.nio.file.Path; //导入方法依赖的package包/类
private int findChipKitPathIndex( Path p ) {
    int pic32Index = -1;
    for ( int i=p.getNameCount()-1; i>=0; i-- ) {
        String dir = p.getName(i).toString();            
        if ( dir.equals("pic32") ) {
            pic32Index = i;
        } else if ( pic32Index != -1 && dir.toLowerCase().contains("chipkit") ) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:13,代码来源:ChipKitBoardConfigNavigator.java


注:本文中的java.nio.file.Path.getNameCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。