org.uberfire.java.nio.file.Path.getNameCount()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(74)

本文整理了Java中org.uberfire.java.nio.file.Path.getNameCount()方法的一些代码示例,展示了Path.getNameCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.getNameCount()方法的具体详情如下:
包路径:org.uberfire.java.nio.file.Path
类名称:Path
方法名:getNameCount

Path.getNameCount介绍

暂无

代码示例

代码示例来源:origin: kiegroup/appformer

public boolean isPolicyFile(Path p) {
  String fileName = p.getName(p.getNameCount() - 1).toString();
  return fileName.equals("security-policy.properties") || fileName.startsWith("security-module-");
}

代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-project-explorer-backend

List<FolderItem> getPathSegments(final Path path) {
  org.uberfire.java.nio.file.Path nioSegmentPath = Paths.convert(path);
  final int segmentCount = nioSegmentPath.getNameCount();
  if (segmentCount < 1) {
    return new ArrayList<>();
  }
  final FolderItem[] segments = new FolderItem[segmentCount];
  for (int idx = segmentCount; idx > 0; idx--) {
    nioSegmentPath = nioSegmentPath.getParent();
    segments[idx - 1] = toFolderItem(nioSegmentPath);
  }
  return Arrays.asList(segments);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleBranchedGitRoot() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThat(path.getNameCount()).isEqualTo(0);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleBranchedGitRelative() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "home",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isFalse();
  assertThat(path.toString()).isEqualTo("home");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/:home");
  assertThat(path.getRoot().toString()).isEqualTo("");
  assertThat(path.getNameCount()).isEqualTo(1);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testPathNonBranchNonRooted() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class);
  when(fsProvider.isDefault()).thenReturn(false);
  when(fsProvider.getScheme()).thenReturn("git");
  final Git git = setupGit();
  final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider,
                                 null,
                                 git,
                                 createFSLock(git),
                                 "my-repo",
                                 CredentialsProvider.getDefault(),
                                 null,
                                 null);
  final Path path = fileSystem.getPath("path/to/some/place.txt");
  AssertionsForClassTypes.assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isFalse();
  assertThat(path.toString()).isEqualTo("path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-repo/:path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path");
  assertThat(path.getRoot().toString()).isNotNull().isEqualTo("");
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleBranchedGitRoot2() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/path/to/some/place.txt",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isEqualTo("path");
  assertThat(path.getRoot().toString()).isEqualTo("/");
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testPathBranchNonRooted() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class);
  when(fsProvider.isDefault()).thenReturn(false);
  when(fsProvider.getScheme()).thenReturn("git");
  final Git git = setupGit();
  final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider,
                                 null,
                                 git,
                                 createFSLock(git),
                                 "my-repo",
                                 CredentialsProvider.getDefault(),
                                 null,
                                 null);
  final Path path = fileSystem.getPath("test-branch",
                     "path/to/some/place.txt");
  AssertionsForClassTypes.assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isFalse();
  assertThat(path.toString()).isEqualTo("path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://test-branch@my-repo/:path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path");
  assertThat(path.getRoot().toString()).isNotNull().isEqualTo("");
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleImplicitBranchGit() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/path/to/some/place.txt",
                     "my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isEqualTo("path");
  assertThat(path.getRoot().toString()).isEqualTo("/");
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleBranchedGitRoot() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThat(path.getNameCount()).isEqualTo(0);
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleBranchedGitRelative() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "home",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isFalse();
  assertThat(path.toString()).isEqualTo("home");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/:home");
  assertThat(path.getRoot().toString()).isEqualTo("");
  assertThat(path.getNameCount()).isEqualTo(1);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleBranchedGitRoot2() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/path/to/some/place.txt",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isEqualTo("path");
  assertThat(path.getRoot().toString()).isEqualTo("/");
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleImplicitBranchGit() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/path/to/some/place.txt",
                     "my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isEqualTo("path");
  assertThat(path.getRoot().toString()).isEqualTo("/");
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleBranchedGitRoot2Spaced() throws IllegalStateException {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     EncodingUtil.decode("/path/to/some/some%20place.txt"),
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/some place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/some%20place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isEqualTo("path");
  assertThat(path.getRoot().toString()).isEqualTo("/");
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleImplicitBranchGitRoot() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/",
                     "my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThatThrownBy(() -> path.getName(0))
      .isInstanceOf(IllegalArgumentException.class);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleBranchedGitRoot2Spaced() throws IllegalStateException {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     EncodingUtil.decode("/path/to/some/some%20place.txt"),
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/some place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/some%20place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isEqualTo("path");
  assertThat(path.getRoot().toString()).isEqualTo("/");
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleImplicitBranchGitRoot() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs,
                     "/",
                     "my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThatThrownBy(() -> path.getName(0))
      .isInstanceOf(IllegalArgumentException.class);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void testSimpleBranchedGit() {
  final Path path = JGitPathImpl.create(fs,
                     "",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getRoot()).isEqualTo(path);
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot()).isEqualTo(path);
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleBranchedGit() {
  final Path path = JGitPathImpl.create(fs,
                     "",
                     "master@my-host",
                     false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getRoot()).isEqualTo(path);
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot()).isEqualTo(path);
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleRootWindows() {
  when(fs.getSeparator()).thenReturn("\\");
  final Path path = create(fs,
               "c:\\",
               false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("c:\\");
  assertThat(path.getFileName()).isNull();
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot()).isNotNull().isEqualTo(path);
  try {
    path.getName(0);
    failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
  } catch (Exception e) {
    assertThat(e).isInstanceOf(IllegalArgumentException.class);
  }
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testSimpleRootUnix() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = create(fs,
               "/",
               false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.getFileName()).isNull();
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot()).isNotNull().isEqualTo(path);
  try {
    path.getName(0);
    failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
  } catch (Exception e) {
    assertThat(e).isInstanceOf(IllegalArgumentException.class);
  }
}

相关文章