Skip to content

Commit b31db2e

Browse files
authored
Merge pull request #322 from scijava/fix-filelocation-to-string
FileLocation improvements
2 parents 904e4b9 + d9eac4e commit b31db2e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/main/java/org/scijava/io/location/AbstractLocation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
package org.scijava.io.location;
3434

35+
import java.net.URI;
3536
import java.util.Objects;
3637

3738
/**
@@ -58,4 +59,13 @@ public boolean equals(final Object obj) {
5859
return Objects.equals(getURI(), other.getURI());
5960
}
6061

62+
@Override
63+
public String toString() {
64+
final String prefix = getClass().getSimpleName() + ":";
65+
final URI uri = getURI();
66+
if (uri != null) return prefix + uri;
67+
final String name = getName();
68+
if (name != null) return prefix + name;
69+
return prefix + defaultName();
70+
}
6171
}

src/main/java/org/scijava/io/location/FileLocation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.net.URI;
3838
import java.util.Collections;
3939
import java.util.HashSet;
40+
import java.util.Objects;
4041
import java.util.Set;
4142

4243
/**
@@ -52,6 +53,7 @@ public class FileLocation extends AbstractLocation implements
5253
private final File file;
5354

5455
public FileLocation(final File file) {
56+
Objects.requireNonNull(file);
5557
this.file = file;
5658
}
5759

0 commit comments

Comments
 (0)