9090public class RequestParams {
9191
9292 public final static String APPLICATION_OCTET_STREAM =
93- "application/octet-stream" ;
93+ "application/octet-stream" ;
9494
9595 protected final static String LOG_TAG = "RequestParams" ;
9696 protected boolean isRepeatable ;
9797 protected boolean useJsonStreamer ;
9898 protected boolean autoCloseInputStreams ;
99- protected final ConcurrentHashMap <String , String > urlParams = new ConcurrentHashMap ();
100- protected final ConcurrentHashMap <String , StreamWrapper > streamParams = new ConcurrentHashMap ();
101- protected final ConcurrentHashMap <String , FileWrapper > fileParams = new ConcurrentHashMap ();
102- protected final ConcurrentHashMap <String , Object > urlParamsWithObjects = new ConcurrentHashMap ();
99+ protected final ConcurrentHashMap <String , String > urlParams = new ConcurrentHashMap < String , String > ();
100+ protected final ConcurrentHashMap <String , StreamWrapper > streamParams = new ConcurrentHashMap < String , StreamWrapper > ();
101+ protected final ConcurrentHashMap <String , FileWrapper > fileParams = new ConcurrentHashMap < String , FileWrapper > ();
102+ protected final ConcurrentHashMap <String , Object > urlParamsWithObjects = new ConcurrentHashMap < String , Object > ();
103103 protected String contentEncoding = HTTP .UTF_8 ;
104104
105105 /**
@@ -307,9 +307,9 @@ public void add(String key, String value) {
307307 this .put (key , params );
308308 }
309309 if (params instanceof List ) {
310- ((List ) params ).add (value );
310+ ((List < Object > ) params ).add (value );
311311 } else if (params instanceof Set ) {
312- ((Set ) params ).add (value );
312+ ((Set < Object > ) params ).add (value );
313313 }
314314 }
315315 }
@@ -334,9 +334,9 @@ public void remove(String key) {
334334 */
335335 public boolean has (String key ) {
336336 return urlParams .get (key ) != null ||
337- streamParams .get (key ) != null ||
338- fileParams .get (key ) != null ||
339- urlParamsWithObjects .get (key ) != null ;
337+ streamParams .get (key ) != null ||
338+ fileParams .get (key ) != null ||
339+ urlParamsWithObjects .get (key ) != null ;
340340 }
341341
342342 @ Override
@@ -391,8 +391,8 @@ public void setUseJsonStreamer(boolean useJsonStreamer) {
391391 }
392392
393393 /**
394- * Set global flag which determines whether to automatically close input
395- * streams on successful upload.
394+ * Set global flag which determines whether to automatically close input streams on successful
395+ * upload.
396396 *
397397 * @param flag boolean whether to automatically close input streams
398398 */
@@ -420,7 +420,7 @@ public HttpEntity getEntity(ResponseHandlerInterface progressHandler) throws IOE
420420
421421 private HttpEntity createJsonStreamerEntity (ResponseHandlerInterface progressHandler ) throws IOException {
422422 JsonStreamerEntity entity = new JsonStreamerEntity (progressHandler ,
423- !fileParams .isEmpty () || !streamParams .isEmpty ());
423+ !fileParams .isEmpty () || !streamParams .isEmpty ());
424424
425425 // Add string params
426426 for (ConcurrentHashMap .Entry <String , String > entry : urlParams .entrySet ()) {
@@ -442,11 +442,12 @@ private HttpEntity createJsonStreamerEntity(ResponseHandlerInterface progressHan
442442 StreamWrapper stream = entry .getValue ();
443443 if (stream .inputStream != null ) {
444444 entity .addPart (entry .getKey (),
445- StreamWrapper .newInstance (
446- stream .inputStream ,
447- stream .name ,
448- stream .contentType ,
449- stream .autoClose ));
445+ StreamWrapper .newInstance (
446+ stream .inputStream ,
447+ stream .name ,
448+ stream .contentType ,
449+ stream .autoClose )
450+ );
450451 }
451452 }
452453
@@ -496,7 +497,7 @@ private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandle
496497 }
497498
498499 protected List <BasicNameValuePair > getParamsList () {
499- List <BasicNameValuePair > lparams = new LinkedList ();
500+ List <BasicNameValuePair > lparams = new LinkedList < BasicNameValuePair > ();
500501
501502 for (ConcurrentHashMap .Entry <String , String > entry : urlParams .entrySet ()) {
502503 lparams .add (new BasicNameValuePair (entry .getKey (), entry .getValue ()));
@@ -508,12 +509,14 @@ protected List<BasicNameValuePair> getParamsList() {
508509 }
509510
510511 private List <BasicNameValuePair > getParamsList (String key , Object value ) {
511- List <BasicNameValuePair > params = new LinkedList ();
512+ List <BasicNameValuePair > params = new LinkedList < BasicNameValuePair > ();
512513 if (value instanceof Map ) {
513514 Map map = (Map ) value ;
514515 List list = new ArrayList <Object >(map .keySet ());
515516 // Ensure consistent ordering in query string
516- Collections .sort (list );
517+ if (list .size () > 0 && list .get (0 ) instanceof Comparable ) {
518+ Collections .sort (list );
519+ }
517520 for (Object nestedKey : list ) {
518521 if (nestedKey instanceof String ) {
519522 Object nestedValue = map .get (nestedKey );
@@ -575,10 +578,10 @@ public StreamWrapper(InputStream inputStream, String name, String contentType, b
575578
576579 static StreamWrapper newInstance (InputStream inputStream , String name , String contentType , boolean autoClose ) {
577580 return new StreamWrapper (
578- inputStream ,
579- name ,
580- contentType == null ? APPLICATION_OCTET_STREAM : contentType ,
581- autoClose );
581+ inputStream ,
582+ name ,
583+ contentType == null ? APPLICATION_OCTET_STREAM : contentType ,
584+ autoClose );
582585 }
583586 }
584587}
0 commit comments