Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/main/java/loci/common/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
import com.google.common.collect.MapMaker;

/**
* Pseudo-extension of java.io.File that supports reading over HTTP (among
* other things).
* Pseudo-extension of {@link java.io.File} that supports reading over HTTP
* (among other things).
* It is strongly recommended to use this instead of java.io.File.
*/
public class Location {
Expand Down Expand Up @@ -246,7 +246,7 @@ public Location(String parent, String child) {
* @see #Location(String, String)
*/
public Location(Location parent, String child) {
this(parent.getAbsolutePath(), child);
this(parent == null ? (String) null : parent.getAbsolutePath(), child);
}

// -- Location API methods --
Expand Down Expand Up @@ -842,9 +842,13 @@ public String getName() {
}

/**
* Returns the name of this file's parent directory, i.e. the path name prefix
* and every name in the path name sequence except for the last.
* If this file does not have a parent directory, then null is returned.
* Returns the pathname string of this abstract pathname's parent, or null if
* this pathname does not have a parent directory.
*
* The parent of an abstract pathname consists of the pathname's prefix, if
* any, and each name in the pathname's name sequence except for the last.
* If the name sequence is empty then the pathname does not name a parent
* directory.
*
* @return see above
* @see java.io.File#getParent()
Expand All @@ -864,13 +868,22 @@ public String getParent() {
}

/**
* Returns this file's parent directory.
* Returns the abstract pathname of this abstract pathname's parent, or null
* if this pathname does not name a parent directory.
*
* The parent of an abstract pathname consists of the pathname's prefix, if
* any, and each name in the pathname's name sequence except for the last.
* If the name sequence is empty then the pathname does not name a parent
* directory.
*
* @return the Location representing {@link #getParent()}
* @return The abstract pathname of the parent directory named by this
* abstract pathname, or null if this pathname does not name a parent
* @see java.io.File#getParentFile()
*/
public Location getParentFile() {
return new Location(getParent());
String parent = this.getParent();
if (parent == null) return null;
return new Location(parent);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/loci/common/utests/LocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package loci.common.utests;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -272,6 +273,14 @@ public void testParentRoot() {
}
}

@Test
public void testParentNull() {
Location nullParent = new Location((String) null, "nullParentFile");
assertNull(nullParent.getParentFile());
nullParent = new Location((Location) null, "nullParentFile");
assertNull(nullParent.getParentFile());
}

@Test
public void testIsDirectory() {
for (int i=0; i<files.length; i++) {
Expand Down