Package qupath.lib.io
Class UriUpdater<T extends UriResource>
java.lang.Object
qupath.lib.io.UriUpdater<T>
- Type Parameters:
T
-
Helper class for updating URIs, for example whenever files have moved or projects have been transferred between computers.
- Author:
- Pete Bankhead
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Wrapper for a URI, providing access to aPath
if available.static enum
Enum representing the status of a URI, i.e. -
Method Summary
Modifier and TypeMethodDescriptionint
Apply all current replacements, updating theUriResource
objects.int
Get a count of the items flagged as missing.int
Get a count of the number of replacements for missing items.static <T extends UriResource>
UriUpdater<T> create
(Collection<T> resources) Create a new UriUpdater to support updating URIs for one or moreUriResource
objects.static <T extends UriResource>
UriUpdater<T> create
(Collection<T> resources, Collection<UriUpdater.SingleUriItem> items, Map<UriUpdater.SingleUriItem, UriUpdater.SingleUriItem> replacements) Create a new UriUpdater using the specified collections.static <T extends UriResource>
UriUpdater<T> create
(T resource) Create a new UriUpdater to support updating URIs for a singleUriResource
.static int
fixUris
(UriResource resource, Project<?> project) Attempt to fix any broken paths by updating URIs based upon the current project.getItems
(UriUpdater.UriStatus status) Get all items with the specified status, or all items is status is null.Get all missing items.Get a map of all replacements.static String
locateFile
(String path, int searchDepth, Path... searchPaths) Attempt to update a file using the specified search paths.static URI
locateFile
(URI uri, int searchDepth, Path... searchPaths) Attempt to update a URI to find an existing file using the specified search paths.makeReplacement
(URI originalItem, URI updatedItem) Add a single replacement to the replacement map.Identify replacements for missing URIs by relativizing URI.Identify replacements for missing URIs by relativizing paths.searchDepth
(int maxDepth) Maximum search depth when usingsearchDepth(int)
to match filenames in directories and subdirectories.searchPath
(Path path) Search for filenames that match missing URIs, recursively up to the depth specified bysearchDepth(int)
.static UriResource
Wrap one or more URIs in aUriResource
so they can be updated together.static UriResource
wrap
(Collection<URI> uris) Wrap one or more URIs in aUriResource
so they can be updated together.
-
Method Details
-
create
Create a new UriUpdater to support updating URIs for a singleUriResource
.- Parameters:
resource
-- Returns:
- Throws:
IOException
-
create
public static <T extends UriResource> UriUpdater<T> create(Collection<T> resources) throws IOException Create a new UriUpdater to support updating URIs for one or moreUriResource
objects.- Parameters:
resources
-- Returns:
- Throws:
IOException
-
create
public static <T extends UriResource> UriUpdater<T> create(Collection<T> resources, Collection<UriUpdater.SingleUriItem> items, Map<UriUpdater.SingleUriItem, UriUpdater.SingleUriItem> replacements) throws IOExceptionCreate a new UriUpdater using the specified collections. The main use of this is as a convenience to build a UI using observable collections.- Parameters:
resources
- collection of resources that may include URIsitems
- collection containing all the distinct URIs from resources, each as aUriUpdater.SingleUriItem
. Note that this collection will be regenerated, so any existing items in the collection will be removed.replacements
- map used to store any replacements identified by theUriUpdater
. Note that any existing contents will be discarded.- Returns:
- Throws:
IOException
-
wrap
Wrap one or more URIs in aUriResource
so they can be updated together. Any changes can then be requred from theUriResource
.- Parameters:
uris
-- Returns:
-
wrap
Wrap one or more URIs in aUriResource
so they can be updated together. Note that the collection is not used directly. Any changes should be accessed from theUriResource
.- Parameters:
uris
-- Returns:
-
locateFile
Attempt to update a URI to find an existing file using the specified search paths.- Parameters:
uri
- the URI to search forsearchDepth
- the depth of the search (i.e. how many subdirectories)searchPaths
- the base directories to search, in order- Returns:
- a new URI corresponding to an existing file with the same name, or the original URI if no replacement was found or required
- Throws:
IOException
-
locateFile
public static String locateFile(String path, int searchDepth, Path... searchPaths) throws IOException Attempt to update a file using the specified search paths.- Parameters:
path
- the path to a file that may or may not existsearchDepth
- the depth of the search (i.e. how many subdirectories)searchPaths
- the base directories to search, in order- Returns:
- the path to a file with the same name as 'path' that does exist, or path unchanged if no existing file could be found.
- Throws:
IOException
-
fixUris
Attempt to fix any broken paths by updating URIs based upon the current project.- Parameters:
resource
- the resource to updateproject
-- Returns:
- number of URIs that were updated
-
searchDepth
Maximum search depth when usingsearchDepth(int)
to match filenames in directories and subdirectories.- Parameters:
maxDepth
-- Returns:
-
relative
Identify replacements for missing URIs by relativizing URI. This is generally used to make corrections whenever a project has been moved.- Parameters:
uriOriginal
- the previous path (usually for the project)uriCurrent
- the current path- Returns:
-
relative
Identify replacements for missing URIs by relativizing paths. This is generally used to make corrections whenever a project has been moved.- Parameters:
pathOriginal
- the previous path (usually for the project)pathCurrent
- the current path- Returns:
-
searchPath
Search for filenames that match missing URIs, recursively up to the depth specified bysearchDepth(int)
.- Parameters:
path
- the base directory within which to search- Returns:
- See Also:
-
makeReplacement
Add a single replacement to the replacement map.- Parameters:
originalItem
- current URI for a missing resourceupdatedItem
- updated URI to use instead- Returns:
-
getReplacements
Get a map of all replacements.- Returns:
-
applyReplacements
Apply all current replacements, updating theUriResource
objects.- Returns:
- Throws:
IOException
-
countMissing
public int countMissing()Get a count of the items flagged as missing.- Returns:
-
countReplacements
public int countReplacements()Get a count of the number of replacements for missing items.- Returns:
-
getMissingItems
Get all missing items.- Returns:
-
getItems
Get all items with the specified status, or all items is status is null.- Parameters:
status
-- Returns:
-