removed MapUtils
This commit is contained in:
1 parent
ce531cdc38
commit
b380b3af3d
6 files changed
+46
-131
No files matched your search
@@ -35,8 +35,7 @@ public class BaseStringExtractorImpl implements BaseStringExtractor
|
||||
params.addAll(request.getQueryStringParams());
|
||||
params.addAll(request.getBodyParams());
|
||||
params.addAll(new ParameterList(request.getOauthParameters()));
|
||||
params.sort();
|
||||
return params.asOauthBaseString();
|
||||
return params.sort().asOauthBaseString();
|
||||
}
|
||||
|
||||
private void checkPreconditions(OAuthRequest request)
|
||||
|
||||
@@ -26,7 +26,12 @@ public class ParameterList
|
||||
{
|
||||
params = new ArrayList<Parameter>();
|
||||
}
|
||||
|
||||
|
||||
ParameterList(List<Parameter> params)
|
||||
{
|
||||
this.params = new ArrayList<Parameter>(params);
|
||||
}
|
||||
|
||||
public ParameterList(Map<String, String> map)
|
||||
{
|
||||
this();
|
||||
@@ -110,8 +115,10 @@ public class ParameterList
|
||||
return params.size();
|
||||
}
|
||||
|
||||
public void sort()
|
||||
public ParameterList sort()
|
||||
{
|
||||
Collections.sort(params);
|
||||
ParameterList sorted = new ParameterList(params);
|
||||
Collections.sort(sorted.params);
|
||||
return sorted;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package org.scribe.utils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Utils for {@link Map} manipulation
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*/
|
||||
public class MapUtils
|
||||
{
|
||||
private static final String EMPTY_STRING = "";
|
||||
private static final String PAIR_SEPARATOR = "=";
|
||||
private static final String PARAM_SEPARATOR = "&";
|
||||
|
||||
/**
|
||||
* Sorts a Map
|
||||
*
|
||||
* @param map unsorted map
|
||||
* @return sorted map
|
||||
*/
|
||||
public static final Map<String, String> sort(Map<String, String> map)
|
||||
{
|
||||
Preconditions.checkNotNull(map, "Cannot sort a null object.");
|
||||
|
||||
Map<String, String> sorted = new LinkedHashMap<String, String>();
|
||||
for (String key : getSortedKeys(map))
|
||||
{
|
||||
sorted.put(key, map.get(key));
|
||||
}
|
||||
return sorted;
|
||||
}
|
||||
|
||||
private static List<String> getSortedKeys(Map<String, String> map)
|
||||
{
|
||||
List<String> keys = new ArrayList<String>(map.keySet());
|
||||
Collections.sort(keys);
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form-urlDecodes and appends all keys from the source {@link Map} to the
|
||||
* target {@link Map}
|
||||
*
|
||||
* @param source Map from where the keys get copied and decoded
|
||||
* @param target Map where the decoded keys are copied to
|
||||
*/
|
||||
public static void decodeAndAppendEntries(Map<String, String> source, Map<String, String> target)
|
||||
{
|
||||
for (String key: source.keySet())
|
||||
{
|
||||
target.put(URLUtils.percentEncode(key), URLUtils.percentEncode(source.get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Concats a key-value map into a querystring-like String
|
||||
*
|
||||
* @param params key-value map
|
||||
* @return querystring-like String
|
||||
*/
|
||||
public static String concatSortedPercentEncodedParams(Map<String, String> params)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String key : params.keySet())
|
||||
{
|
||||
result.append(key).append(PAIR_SEPARATOR);
|
||||
result.append(params.get(key)).append(PARAM_SEPARATOR);
|
||||
}
|
||||
return result.toString().substring(0, result.length() - 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user