class Directory implements Serializable {

  static File relativePath(final File from,
                           final File to,
                           final boolean mustBeChild) {
    final String[] fromPaths;
    final String[] toPaths;

    try {
      fromPaths = splitPath(from.getCanonicalPath());
      toPaths = splitPath(to.getCanonicalFile().getPath());
    }
    catch (final IOException e) {
      throw new UnexpectedIOException(e);
    }

    int i = 0;

    while (i < fromPaths.length &&
           i < toPaths.length &&
           fromPaths[i].equals(toPaths[i])) {
      ++i;
    }

    if (mustBeChild && i != fromPaths.length) {
      return null;
    }

    // i == 0: The root file is different.
    // i == 1: The root file is the same, but there's no common path.
    if (i <= 1) {
      return null;
    }

    final StringBuilder result = new StringBuilder();

    for (int j = i; j < fromPaths.length; ++j) {
      result.append("..");
      result.append(File.separator);
    }

    for (int j = i; j < toPaths.length; ++j) {
      result.append(toPaths[j]);

      if (j != toPaths.length - 1) {
        result.append(File.separator);
      }
    }

    if (result.length() == 0) {
      return new File(".");
    }

    return new File(result.toString());
  }

  public  Directory();
  public  Directory(final File directory);

}