/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 BlueSkyFish
 */
package de.blueskyfish.httpclient;

import java.text.DateFormat;
import java.util.Date;

/**
 * A helper class to build urls.
 */
public final class PathBuilder {

    public static String toUrl(Object... segments) {

        StringBuilder sb = new StringBuilder();
        for (Object segment : segments) {
            if (segment == null) {
                continue;
            }
            if (segment instanceof Date) {
                DateFormat dateFormat = Definition.DEFAULT_DATE_FORMAT;
                sb.append(Definition.PATH_SEPARATOR).append(dateFormat.format((Date) segment));
            } else if (segment instanceof String) {
                sb.append(Definition.PATH_SEPARATOR).append(StringUtils.urlEncode((String) segment, Definition.DEFAULT_ENCODING));
            } else {
                sb.append(Definition.PATH_SEPARATOR).append(segment);
            }
        }
        return sb.toString();
    }
}

@@ -283,54 +283,226 @@
 ) %7B%0A
-%0A        StringBuilder sb = new StringBuilder(
+        return toUrl(null, segments);%0A   %7D%0A%0A    public static String toUrl(String baseUrl, Object... segments) %7B%0A        StringBuilder sb = StringUtils.isEmpty(baseUrl) ? new StringBuilder() : new StringBuilder(baseUrl
 );%0A 
@@ -940,16 +940,41 @@
 .append(
+%0A                        
 StringUt
@@ -1033,16 +1033,33 @@
 NCODING)
+%0A                
 );%0A     

add PathBuilder.toUrl(baseUrl, Object... segments)