Created
September 9, 2016 08:56
-
-
Save maxmalakhov/8c8f8112f3e39fd5a9697438d5c11f26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import demo.client.OrderTypeEnum; | |
import demo.client.SortTypeEnum; | |
/** | |
* Created by Max Malakhov on 9/7/16. | |
*/ | |
public class QueryBuilder { | |
private static final String PARAM_SOURCE_TYPE = "?site=stackoverflow"; | |
private static final String PARAM_ORDER_TYPE = "order"; | |
private static final String PARAM_SORT_TYPE = "sort"; | |
private static final String PARAM_INTITLE = "intitle"; | |
private StringBuffer query; | |
private QueryBuilder() { | |
query = new StringBuffer(); | |
query.append(PARAM_SOURCE_TYPE); | |
} | |
public static QueryBuilder create() { | |
return new QueryBuilder(); | |
} | |
public QueryBuilder order(OrderTypeEnum type) { | |
query.append(String.format("&%s=%s",PARAM_ORDER_TYPE, type.getValue())); | |
return this; | |
} | |
public QueryBuilder sort(SortTypeEnum type) { | |
query.append(String.format("&%s=%s",PARAM_SORT_TYPE, type.getValue())); | |
return this; | |
} | |
public QueryBuilder intitle(String term) { | |
query.append(String.format("&%s=%s", PARAM_INTITLE, term)); | |
return this; | |
} | |
public String build() { | |
return query.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment