com.github.longhorn.fastball.net.UriBuilderUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastball Show documentation
Show all versions of fastball Show documentation
Frequency used JVM libraries
The newest version!
package com.github.longhorn.fastball.net;
import com.google.common.base.Joiner;
import org.apache.commons.collections.CollectionUtils;
import javax.ws.rs.core.UriBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
public final class UriBuilderUtil {
private static final String COMMA = ",";
private UriBuilderUtil() {
}
/**
* Append a query parameter to the existing set of query parameters if match the condition. If multiple values are
* supplied the parameter will be added once per value.
*
* @param builder instance of UriBuilder
* @param condition condition
* @param name the query parameter name, may contain URI template parameters.
* @param values the query parameter value(s), each object will be converted to a {@code String} using its
* {@code toString()} method. Stringified values may contain URI template parameters.
* @return the updated UriBuilder.
*/
public static UriBuilder queryParamWithCondition(
UriBuilder builder, boolean condition, String name, Object... values
) {
if (condition) {
return builder.queryParam(name, values);
}
return builder;
}
/**
* Append a query parameter to the existing set of query parameters if the value is not null. If multiple values are
* supplied the parameter will be added once per value.
*
* @param builder instance of UriBuilder
* @param name the query parameter name, may contain URI template parameters.
* @param values the query parameter value(s), each object will be converted to a {@code String} using its
* {@code toString()} method. Stringified values may contain URI template parameters.
* @return the updated UriBuilder.
*/
public static UriBuilder queryParamIfNotNull(UriBuilder builder, String name, Object... values) {
if (!Objects.isNull(values)) {
List