Java Path Combine combine(final String path, final String suffix)

Here you can find the source of combine(final String path, final String suffix)

Description

combine

License

Apache License

Declaration

public static String combine(final String path, final String suffix) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w. ja  v a  2 s  . c o m*/
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

public class Main {
    public static String combine(final String path, final String suffix) {
        if (isEmpty(path) && isEmpty(suffix)) {
            return "";
        }
        if (isEmpty(path)) {
            return suffix;
        }
        if (isEmpty(suffix)) {
            return path;
        }
        if (path.endsWith("/") || suffix.startsWith("/")) {
            return path + suffix;
        }
        return path + "/" + suffix;
    }

    private static boolean isEmpty(final String str) {
        return str == null || str.length() == 0;
    }
}

Related

  1. combine(final String path1, final String path2)
  2. combine(String directory, String filename)
  3. combineDisplayPaths(String parent_display, String display_path)
  4. combinePath(java.io.File parentDir, String... childDirs)