Class NodeFileSeparator


  • public class NodeFileSeparator
    extends Object
    This class implements the ability to efficiently look up the file separator used for each Node.

    This is relevant for determining the correct path to the workspace and avoids using "/" on Windows or "\" on Unix.

    It is a singleton, because there's no point to individual instances.

    Author:
    mhschroe
    • Method Detail

      • ensurePathCorrect

        public String ensurePathCorrect​(Node n,
                                        String path)
        Ensures that the given path uses the right file separator for the given node.

        If the separator can't be determined, is invalid, or the node is null, the path is returned unmodified.

        Parameters:
        n - the node
        path - the path to ensure correctness for
        Returns:
        a path with correct separators, or the original, if the separator could not be determined.
      • getSepFor

        public String getSepFor​(Node n)
        Returns the separator for that node -- if possible to be retrieved.

        Guaranteed to always be either "/", "\\" or null.

        The result is cached, so that repeated lookups are sped-up and random node offlining does not affect the separator calculation as much.

        Parameters:
        n - the node to check.
        Returns:
        the separator, one of "/", "\\" or null.