/*
 * @(#) net.bis5.mattermost.client4.QueryBuilder
 * Copyright (c) 2017-present, Maruyama Takayuki
 *
 * Licensed 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.
 */
package net.bis5.mattermost.client4;

import org.apache.commons.lang3.StringUtils;

/**
 * TODO 型の説明
 * 
 * @author Maruyama Takayuki
 */
class QueryBuilder {

	private static final String PREFIX = "?";
	private static final String DELIMITER = "&";
	private static final String EQUALS = "=";
	private final StringBuilder builder = new StringBuilder(PREFIX);

	private boolean isFirst = true;

	public QueryBuilder append(String key, String value) {
		if (StringUtils.isEmpty(key)) {
			throw new IllegalArgumentException("key");
		}
		if (!isFirst) {
			builder.append(DELIMITER);
		} else {
			isFirst = false;
		}
		builder.append(key).append(EQUALS).append(StringUtils.defaultString(value));
		return this;
	}

	public QueryBuilder append(String key, int value) {
		return append(key, String.valueOf(value));
	}

	public QueryBuilder append(String key, boolean value) {
		return append(key, Boolean.toString(value));
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return builder.toString();
	}

}

@@ -720,16 +720,105 @@
 nt4;%0D%0A%0D%0A
+import java.util.HashMap;%0D%0Aimport java.util.Map;%0D%0Aimport java.util.stream.Collectors;%0D%0A%0D%0A
 import o
@@ -855,16 +855,16 @@
 Utils;%0D%0A
-
 %0D%0A/**%0D%0A 
@@ -916,16 +916,23 @@
 i%0D%0A */%0D%0A
+public 
 class Qu
@@ -945,16 +945,16 @@
 lder %7B%0D%0A
-
 %0D%0A%09priva
@@ -1101,93 +1101,56 @@
 nal 
+Map%3C
 String
-Builder builder = new StringBuilder(PREFIX);%0D%0A%0D%0A%09private boolean isFi
+, String%3E paramete
 rs
-t
  = 
-true
+new HashMap%3C%3E()
 ;%0D%0A%0D
@@ -1300,171 +1300,34 @@
 %0D%0A%09%09
-if (!isFirst) %7B%0D%0A%09%09%09builder.append(DELIMITER);%0D%0A%09%09%7D else %7B%0D%0A%09%09%09isFirst = false;%0D%0A%09%09%7D%0D%0A%09%09builder.append(key).append(EQUALS).append(StringUtils.defaultString(
+parameters.put(key, 
 value)
-)
 ;%0D%0A%09
@@ -1669,25 +1669,145 @@
 urn 
-builder.toString(
+parameters.entrySet().stream()%0D%0A%09%09%09%09.map(e -%3E e.getKey() + EQUALS + e.getValue())%0D%0A%09%09%09%09.collect(Collectors.joining(DELIMITER, PREFIX, %22%22)
 );%0D%0A

refactor QueryBuilder