下面列出了java.util.HashMap#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void replacePlaceholders() throws Exception {
HashMap<String, Object> map = new HashMap<>();
map.put("1", 1);
map.put("2", 1);
map.put("3", 3);
map.put("4", 4);
map.put("5", -1);
String s = map.toString();
Assert.assertEquals(ParameterReplace.orderedParam("(?0)", s.substring(1, s.length() - 1)),
"(1=1, 2=1, 3=3, 4=4, 5=-1)");
String key = map.keySet().toString();
String value = map.values().toString();
Assert.assertEquals(ParameterReplace.orderedParam("(?0), (?1)",
key.substring(1, key.length() - 1), value.substring(1, value.length() - 1)), "(1, 2, 3, 4, 5), (1, 1, 3, 4, -1)");
}
public String getSpeciesNames() {
if (this.taxonIdToSpeciesId.length == this.speciesNameIdMap.taxonCount()) {
return Arrays.toString(this.speciesNameIdMap.getAllTaxonNames());
} else {
HashMap<String, String> stToGtNameMap = new HashMap<String, String>();
int i = 0;
for (List<Integer> set : this.speciesIdtoTaxonId) {
ArrayList<String> gtNames = new ArrayList<String>();
for (Integer gi : set) {
gtNames.add(GlobalMaps.taxonIdentifier.getTaxonName(gi));
}
stToGtNameMap.put(this.getSpeciesName(i++), gtNames.toString());
}
return stToGtNameMap.toString();
}
}
protected HttpUriRequest prepareRequestMethod(URI uri, HttpMethod method, ContentType contentType,
HashMap<String, String> params, Map<String, List<Object>> headers, HttpEntity requestEntity)
throws IOException {
if (params != null) {
URIBuilder builder = new URIBuilder(uri);
for (Entry<String, String> param : params.entrySet()) {
builder.addParameter(param.getKey(), param.getValue());
}
try {
uri = builder.build();
} catch (URISyntaxException e) {
throw new IOException("Invalid param: " + params.toString(), e);
}
}
Map<String, Object> h = prepareRequestHeader(uri, method, contentType);
headers = mergeToHeaders(headers, h);
return createHttpRequest(uri, method, headers, requestEntity);
}
/**
* java.util.AbstractMap#toString()
*/
public void test_toString() {
HashMap m = new HashMap();
m.put(m, m);
String result = m.toString();
assertTrue("should contain self ref", result.indexOf("(this") > -1);
}
@Override
public void commitClickEvent(HashMap<String, Object> commonInfo, String viewName, HashMap<String, Object> viewData) {
String extra = viewData == null ? "" : " extra=" + viewData.toString();
Log.i(TAG, "commitClickEvent: viewName=" + viewName + extra);
}
@Override
public void commitExposureEvent(HashMap<String, Object> commonInfo, String viewName, HashMap<String, Object> viewData, long exposureData, HashMap<String, Object> exposureIndex) {
String extra = viewData == null ? "" : " extra=" + viewData.toString();
Log.i(TAG, "commitExposureEvent: viewName=" + viewName + " exposureTime=" + exposureData + extra);
}
public String toString() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(key, value);
return map.toString();
}