Java Code Examples for java.nio.file.Path#getName()

The following examples show how to use java.nio.file.Path#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From jdt2famix with Eclipse Public License 1.0 6 votes vote down vote up
public static void main(String[] args) {
	InJavaImporter importer = new InJavaImporter();
	String pathName;
	if (args.length > 0)
		pathName = args[0];
	else 
		pathName = ".";
	Path path = Paths.get(pathName).toAbsolutePath().normalize();
	String mseFileName = path.getName(path.getNameCount() - 1) + ".mse";
	JavaFiles javaFiles = new JavaFiles();
	javaFiles.deepJavaFiles(path.toString());
	Classpath classpath = new Classpath();
	classpath.deepJarFiles(path.toString());
	logger.trace("importing root folder - " + path.toString());
	importer.run(javaFiles, classpath);
	logger.trace("exporting - " + mseFileName);
	importer.exportMSE(mseFileName);
	logger.trace("done");
}
 
Example 2
Source File: FolderComposite.java    From PeerWasp with MIT License 6 votes vote down vote up
public synchronized FileComponent getComponent(Path remainingPath) {
	if (remainingPath.equals(getPath())) {
		return this;
	}
	remainingPath = stripOffPrefix(remainingPath, getPath());

	Path nextLevelPath = remainingPath.getName(0);
	FileComponent nextLevel = children.get(nextLevelPath);

	if (nextLevel == null) {
		// next level child not found
		return null;
	} else if (remainingPath.getNameCount() == 1) {
		// nextLevel is the last level of path: return it
		return nextLevel;
	} else if (nextLevel.isFolder()) {
		// go to next level if it is a folder
		Path newRemainingPath = remainingPath.subpath(1, remainingPath.getNameCount());
		return ((FolderComposite)nextLevel).getComponent(newRemainingPath);
	} else {
		// not possible to contintue recursion.
		return null;
	}
}
 
Example 3
Source File: FolderComposite.java    From PeerWasp with MIT License 6 votes vote down vote up
/**
 * Appends a new component to the FolderComposite. Inexistent folders are added on the
 * fly. Existing items are replaced. Triggers updates of content and name hashes.
 */
public synchronized void putComponent(Path remainingPath, FileComponent component) {
	remainingPath = stripOffPrefix(remainingPath, getPath());

	Path nextLevelPath = remainingPath.getName(0);

	// if we are at the last recursion, perform the add, else recursively continue
	if (remainingPath.getNameCount() == 1) {
		deleteComponent(nextLevelPath);
		addComponentToChildren(nextLevelPath, component);
	} else {
		FileComponent nextLevel = children.get(nextLevelPath);
		if (nextLevel == null) {
			// next level does not exist yet, create it
			Path childPath = constructFullPath(nextLevelPath);
			nextLevel = new FolderComposite(childPath, updateContentHash);
			nextLevel.getAction().setFileEventManager(getAction().getFileEventManager());
			addComponentToChildren(nextLevelPath, nextLevel);
		}
		Path newRemainingPath = remainingPath.subpath(1, remainingPath.getNameCount());
		((FolderComposite) nextLevel).putComponent(newRemainingPath, component);
	}
}
 
Example 4
Source File: TestFolderComposite.java    From PeerWasp with MIT License 6 votes vote down vote up
/**
 * Appends a new component to the FolderComposite. Inexistent folders are added on the
 * fly. Existing items are replaced. Triggers updates of content and name hashes.
 */
@Override
public synchronized void putComponent(Path remainingPath, FileComponent component) {
	remainingPath = stripOffPrefix(remainingPath, getPath());

	Path nextLevelPath = remainingPath.getName(0);

	// if we are at the last recursion, perform the add, else recursively continue
	if (remainingPath.getNameCount() == 1) {
		addComponentToChildren(nextLevelPath, component);
	} else {
		FileComponent nextLevel = getChildren().get(nextLevelPath);
		if (nextLevel == null) {
			// next level does not exist yet, create it
			Path childPath = constructFullPath(nextLevelPath);
			nextLevel = new TestFolderComposite(childPath, updateContentHash);
			addComponentToChildren(nextLevelPath, nextLevel);
		}
		Path newRemainingPath = remainingPath.subpath(1, remainingPath.getNameCount());
		((FolderComposite)nextLevel).putComponent(newRemainingPath, component);
	}
}
 
Example 5
Source File: AggregationTreeNode.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Adding a new child doing all necessary adjustments to the structure of the nodes to keep the
 * tree valid.
 */
public void addChild(Path newNodePathComponents, AggregationModule module, Path moduleBasePath) {
  Path firstPathComponent = newNodePathComponents.getName(0);
  for (Path childPathComponents : children.keySet()) {
    if (childPathComponents.startsWith(firstPathComponent)) {
      if (newNodePathComponents.equals(childPathComponents)) {
        replaceCurrentModule(childPathComponents, module, moduleBasePath);
      } else if (newNodePathComponents.startsWith(childPathComponents)) {
        putNewNodeAfterChild(newNodePathComponents, childPathComponents, module, moduleBasePath);
      } else if (childPathComponents.startsWith(newNodePathComponents)) {
        putNewNodeBeforeChild(newNodePathComponents, childPathComponents, module, moduleBasePath);
      } else {
        addModuleWithCommonSubpath(
            newNodePathComponents, childPathComponents, module, moduleBasePath);
      }
      return;
    }
  }

  children.put(newNodePathComponents, new AggregationTreeNode(module, moduleBasePath));
}
 
Example 6
Source File: GeneratedJSFilesCounter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
static private boolean pathContainsSrcGen(Path path) {
	if (path == null || path.getNameCount() == 0) {
		return false;
	}
	Path pathName = path.getName(path.getNameCount() - 1);
	if ("src-gen".equals(pathName.toString())) {
		return true;
	}
	return pathContainsSrcGen(path.getParent());
}
 
Example 7
Source File: TestPath.java    From jsr203-hadoop with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void getNameInvalidIndex() throws IOException {
  Path rootPath = Paths.get(clusterUri);

  Path p = rootPath.resolve("tmp/testNormalize/test");
  p.getName(-1);
}
 
Example 8
Source File: TestPath.java    From jsr203-hadoop with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void getNameInvalidIndex2() throws IOException {
  Path rootPath = Paths.get(clusterUri);

  Path p = rootPath.resolve("tmp/testNormalize/test");
  p.getName(p.getNameCount());
}
 
Example 9
Source File: ExternalModuleSpecService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private int compareBySameLevel(Path path1, Path path2) {
    int i = 0;
    int comparison = 0;
    for (Iterator<Path> iterPath1 = path1.iterator(); iterPath1.hasNext(); i++) {
        Path levelPath1 = iterPath1.next();
        Path levelPath2 = path2.getName(i);
        comparison = levelPath1.compareTo(levelPath2);
        if (comparison!=0) {
            break;
        }
    }
    return comparison;
}
 
Example 10
Source File: FolderComposite.java    From PeerWasp with MIT License 5 votes vote down vote up
/**
 * Deletes the FileComponent at location remainingPath. Triggers updates of
 * content and name hashes.
 *
 * @return The deleted component. If it does not exist, null is returned
 */
public synchronized FileComponent deleteComponent(Path remainingPath) {
	remainingPath = stripOffPrefix(remainingPath, getPath());

	Path nextLevelPath = remainingPath.getName(0);

	FileComponent removed = null;
	if (remainingPath.getNameCount() == 1) {

		children.get(nextLevelPath);
		FileComponent toRemove = children.get(nextLevelPath);
		if(toRemove != null){
			if(toRemove instanceof FolderComposite){
				removeBottomUp((FolderComposite)toRemove);
			}
			removed = children.remove(nextLevelPath);
		}
		if (updateContentHash) {
			updateContentHash();
		}
		updateStructureHash();
	} else {
		FileComponent nextLevel = children.get(nextLevelPath);
		if (nextLevel != null && nextLevel.isFolder()) {
			Path newRemainingPath = remainingPath.subpath(1, remainingPath.getNameCount());
			removed = ((FolderComposite)nextLevel).deleteComponent(newRemainingPath);
		}
	}
	return removed;
}
 
Example 11
Source File: ResourceFilters.java    From buck with Apache License 2.0 5 votes vote down vote up
private static Path getResourceFolder(Path resourceFile) {
  for (int i = 0; i < resourceFile.getNameCount(); i++) {
    Path part = resourceFile.getName(i);
    if (SUPPORTED_RESOURCE_DIRECTORIES.contains(getResourceType(part))) {
      return resourceFile.subpath(0, i + 1);
    }
  }
  throw new HumanReadableException(
      "Resource file at %s is not in a valid resource folder.  See "
          + "http://developer.android.com/guide/topics/resources/providing-resources.html#table1 "
          + "for a list of valid resource folders.",
      resourceFile);
}
 
Example 12
Source File: BuckUnixPathTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
@Parameters({"a,-1", "/a,-1", ",0", "/,0", "a/b,2", "/a/b,2", "/a/b/c/d,1000"})
public void getNameMethodException(String data, int index) {
  Path path = BuckUnixPathUtils.createPath(data);
  path.getName(index);
}
 
Example 13
Source File: DirectoryCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Create standard name = topCollectionName + last directory
 * 
 * @param topCollectionName from config, name of the collection
 * @param dir directory for this
 * @return standard collection name, to name the index file
 */
public static String makeCollectionName(String topCollectionName, Path dir) {
  int last = dir.getNameCount() - 1;
  Path lastDir = dir.getName(last);
  String lastDirName = lastDir.toString();
  return topCollectionName + "-" + lastDirName;
}