Java Path Resolve nio resolve(final Optional parent, final String child)

Here you can find the source of resolve(final Optional parent, final String child)

Description

Attempts to resolve the child against the parent.

License

Open Source License

Return

The resolved path

Declaration

public static Path resolve(final Optional<Path> parent, final String child) 

Method Source Code

//package com.java2s;
/*//w  ww.  ja  v  a  2  s.co  m
 * eXist Open Source Native XML Database
 * Copyright (C) 2001-2015 The eXist Project
 * http://exist-db.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

import java.nio.file.*;

import java.util.*;

public class Main {
    /**
     * Attempts to resolve the child
     * against the parent.
     *
     * If there is no parent, then the child
     * is resolved relative to the CWD
     *
     * @return The resolved path
     */
    public static Path resolve(final Optional<Path> parent, final String child) {
        return parent.map(p -> p.resolve(child)).orElse(Paths.get(child));
    }
}

Related

  1. getResolvableFilePath(String path)
  2. resolve(Path base, String one, String... more)
  3. resolve(Path directory, String... parts)
  4. resolve(Path file, Path srcDir, Path destDir)
  5. resolve(Path path1, Path path2)