Package qupath.lib.io

Class UriUpdater<T extends UriResource>

java.lang.Object
qupath.lib.io.UriUpdater<T>
Type Parameters:
T -

public class UriUpdater<T extends UriResource> extends Object
Helper class for updating URIs, for example whenever files have moved or projects have been transferred between computers.
Author:
Pete Bankhead
  • Method Details

    • create

      public static <T extends UriResource> UriUpdater<T> create(T resource) throws IOException
      Create a new UriUpdater to support updating URIs for a single UriResource.
      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 more UriResource 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 IOException
      Create 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 URIs
      items - collection containing all the distinct URIs from resources, each as a UriUpdater.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 the UriUpdater. Note that any existing contents will be discarded.
      Returns:
      Throws:
      IOException
    • wrap

      public static UriResource wrap(URI... uris)
      Wrap one or more URIs in a UriResource so they can be updated together. Any changes can then be requred from the UriResource.
      Parameters:
      uris -
      Returns:
    • wrap

      public static UriResource wrap(Collection<URI> uris)
      Wrap one or more URIs in a UriResource so they can be updated together. Note that the collection is not used directly. Any changes should be accessed from the UriResource.
      Parameters:
      uris -
      Returns:
    • locateFile

      public static URI locateFile(URI uri, int searchDepth, Path... searchPaths) throws IOException
      Attempt to update a URI to find an existing file using the specified search paths.
      Parameters:
      uri - the URI to search for
      searchDepth - 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 exist
      searchDepth - 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

      public static int fixUris(UriResource resource, Project<?> project)
      Attempt to fix any broken paths by updating URIs based upon the current project.
      Parameters:
      resource - the resource to update
      project -
      Returns:
      number of URIs that were updated
    • searchDepth

      public UriUpdater<T> searchDepth(int maxDepth)
      Maximum search depth when using searchDepth(int) to match filenames in directories and subdirectories.
      Parameters:
      maxDepth -
      Returns:
    • relative

      public UriUpdater<T> relative(URI uriOriginal, URI uriCurrent)
      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

      public UriUpdater<T> relative(Path pathOriginal, Path pathCurrent)
      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

      public UriUpdater<T> searchPath(Path path)
      Search for filenames that match missing URIs, recursively up to the depth specified by searchDepth(int).
      Parameters:
      path - the base directory within which to search
      Returns:
      See Also:
    • makeReplacement

      public UriUpdater<T> makeReplacement(URI originalItem, URI updatedItem)
      Add a single replacement to the replacement map.
      Parameters:
      originalItem - current URI for a missing resource
      updatedItem - updated URI to use instead
      Returns:
    • getReplacements

      public Map<URI,URI> getReplacements()
      Get a map of all replacements.
      Returns:
    • applyReplacements

      public int applyReplacements() throws IOException
      Apply all current replacements, updating the UriResource 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

      public Collection<UriUpdater.SingleUriItem> getMissingItems()
      Get all missing items.
      Returns:
    • getItems

      Get all items with the specified status, or all items is status is null.
      Parameters:
      status -
      Returns: