MCPcopy Create free account
hub / github.com/davidgiven/luje / getParent

Method getParent

lib/java/io/File.java:698–715  ·  view source on GitHub ↗

Returns the pathname of the parent of this file. This is the path up to but not including the last name. null is returned if there is no parent. @return this file's parent pathname or null.

()

Source from the content-addressed store, hash-verified

696 * @return this file's parent pathname or {@code null}.
697 */
698 public String getParent() {
699 int length = path.length(), firstInPath = 0;
700 if (separatorChar == '\\' && length > 2 && path.charAt(1) == ':') {
701 firstInPath = 2;
702 }
703 int index = path.lastIndexOf(separatorChar);
704 if (index == -1 && firstInPath > 0) {
705 index = 2;
706 }
707 if (index == -1 || path.charAt(length - 1) == separatorChar) {
708 return null;
709 }
710 if (path.indexOf(separatorChar) == index
711 && path.charAt(firstInPath) == separatorChar) {
712 return path.substring(0, index + 1);
713 }
714 return path.substring(0, index);
715 }
716
717 /**
718 * Returns a new file made from the pathname of the parent of this file.

Callers 2

getParentFileMethod · 0.95
mkdirsMethod · 0.95

Calls 5

lengthMethod · 0.65
charAtMethod · 0.65
lastIndexOfMethod · 0.65
indexOfMethod · 0.65
substringMethod · 0.45

Tested by

no test coverage detected