本文整理匯總了Java中java.util.Map.size方法的典型用法代碼示例。如果您正苦於以下問題:Java Map.size方法的具體用法?Java Map.size怎麽用?Java Map.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Map
的用法示例。
在下文中一共展示了Map.size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: chanceSelect
import java.util.Map; //導入方法依賴的package包/類
public static String chanceSelect(Map<String, Integer> keyChanceMap) {
if(keyChanceMap == null || keyChanceMap.size() == 0)
return null;
Integer sum = 0;
for (Integer value : keyChanceMap.values()) {
sum += value;
}
// 從1開始
Integer rand = new Random().nextInt(sum) + 1;
for (Map.Entry<String, Integer> entry : keyChanceMap.entrySet()) {
rand -= entry.getValue();
// 選中
if (rand <= 0) {
String item = entry.getKey();
return item;
}
}
return null;
}
示例2: createFilterKeys
import java.util.Map; //導入方法依賴的package包/類
/**
* Constructs a number of FilterKey instances, given the currently enabled filters
*
* @param enabledFilters The currently enabled filters
*
* @return The filter keys, one per enabled filter
*/
public static Set<FilterKey> createFilterKeys(Map<String,Filter> enabledFilters) {
if ( enabledFilters.size() == 0 ) {
return null;
}
final Set<FilterKey> result = new HashSet<FilterKey>();
for ( Filter filter : enabledFilters.values() ) {
final FilterKey key = new FilterKey(
filter.getName(),
( (FilterImpl) filter ).getParameters(),
filter.getFilterDefinition().getParameterTypes()
);
result.add( key );
}
return result;
}
示例3: toQueryString
import java.util.Map; //導入方法依賴的package包/類
public static String toQueryString(Map<String, String> ps) {
StringBuilder buf = new StringBuilder();
if (ps != null && ps.size() > 0) {
for (Map.Entry<String, String> entry : new TreeMap<String, String>(ps).entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key != null && key.length() > 0
&& value != null && value.length() > 0) {
if (buf.length() > 0) {
buf.append("&");
}
buf.append(key);
buf.append("=");
buf.append(value);
}
}
}
return buf.toString();
}
示例4: directFromObjectMap
import java.util.Map; //導入方法依賴的package包/類
@Test
public void directFromObjectMap() throws VPackException {
final Map<TestEntityString, TestEntityString> map = new HashMap<VPackSerializeDeserializeTest.TestEntityString, VPackSerializeDeserializeTest.TestEntityString>();
map.put(new TestEntityString(), new TestEntityString());
map.put(new TestEntityString(), new TestEntityString());
final VPackSlice vpack = new VPack.Builder().build().serialize(map,
new SerializeOptions().type(new Type<Map<TestEntityString, TestEntityString>>() {
}.getType()));
assertThat(vpack, is(notNullValue()));
assertThat(vpack.isArray(), is(true));
assertThat(vpack.getLength(), is(map.size()));
for (int i = 0; i < map.size(); i++) {
final VPackSlice entry = vpack.get(i);
final VPackSlice key = entry.get("key");
checkStringEntity(key);
final VPackSlice value = entry.get("value");
checkStringEntity(value);
}
}
示例5: getMapKeyArray
import java.util.Map; //導入方法依賴的package包/類
public static long[] getMapKeyArray(Map<Long, String> map) {
long[] keyArr = new long[map.size()];
int i = 0;
for (long id : map.keySet()) {
keyArr[i] = id;
i++;
}
return keyArr;
}
示例6: getTotalTargetCount
import java.util.Map; //導入方法依賴的package包/類
public static int getTotalTargetCount(final IMarker marker) {
final Map<IMarker, String> fieldsTargets = AlloyUtilities.getRelationsOfFirstSideMarker(marker);
final ArrayList<IMarker> relationsTargets =
AlloyUtilities.getTargetsOfMarkerAtRelations(marker);
return fieldsTargets.size() + relationsTargets.size();
}
示例7: pathParams
import java.util.Map; //導入方法依賴的package包/類
/**
* @author wasiq.bhamla
* @since Sep 5, 2017 10:16:01 PM
* @param parameters
* @return instance
*/
public RequestHandler pathParams (final Map <String, Object> parameters) {
if (parameters != null && parameters.size () > 0) {
logMap ("Path Params", parameters);
this.request = this.request.pathParams (parameters);
}
return this;
}
示例8: revertNotify
import java.util.Map; //導入方法依賴的package包/類
public static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify) {
if (notify != null && notify.size() > 0) {
Map<String, Map<String, String>> newNotify = new HashMap<String, Map<String, String>>();
for (Map.Entry<String, Map<String, String>> entry : notify.entrySet()) {
String serviceName = entry.getKey();
Map<String, String> serviceUrls = entry.getValue();
if (!serviceName.contains(":") && !serviceName.contains("/")) {
if (serviceUrls != null && serviceUrls.size() > 0) {
for (Map.Entry<String, String> entry2 : serviceUrls.entrySet()) {
String url = entry2.getKey();
String query = entry2.getValue();
Map<String, String> params = StringUtils.parseQueryString(query);
String group = params.get("group");
String version = params.get("version");
// params.remove("group");
// params.remove("version");
String name = serviceName;
if (group != null && group.length() > 0) {
name = group + "/" + name;
}
if (version != null && version.length() > 0) {
name = name + ":" + version;
}
Map<String, String> newUrls = newNotify.get(name);
if (newUrls == null) {
newUrls = new HashMap<String, String>();
newNotify.put(name, newUrls);
}
newUrls.put(url, StringUtils.toQueryString(params));
}
}
} else {
newNotify.put(serviceName, serviceUrls);
}
}
return newNotify;
}
return notify;
}
示例9: deleteBulk
import java.util.Map; //導入方法依賴的package包/類
/**
* Delete a list of documents for a given set of ids
* ATTENTION: read about the time-out of version number checking in the method above.
*
* @param ids
* a map from the unique identifier of a document to the document type
* @return the number of deleted documents
*/
public int deleteBulk(String indexName, Map<String, String> ids) {
// bulk-delete the ids
if (ids == null || ids.size() == 0) return 0;
BulkRequestBuilder bulkRequest = elasticsearchClient.prepareBulk();
for (Map.Entry<String, String> id : ids.entrySet()) {
bulkRequest.add(new DeleteRequest().id(id.getKey()).index(indexName).type(id.getValue()));
}
bulkRequest.execute().actionGet();
return ids.size();
}
示例10: getDefaultOptions
import java.util.Map; //導入方法依賴的package包/類
/**
* Get the default options for all formatters registered.
* @return The default options.
*/
@Override
public Map<String, Object> getDefaultOptions() {
Map<String, Object> defaultOptions = new HashMap<>();
int count1 = valueFormatterMap.keySet().stream().mapToInt(
formatter -> this.mergeDefaultOptions(formatter, defaultOptions)).sum();
int count2 = typeFormatterMap.keySet().stream().mapToInt(
formatter -> this.mergeDefaultOptions(formatter, defaultOptions)).sum();
if (count1 + count2 != defaultOptions.size()) {
throw new IllegalStateException("There is some configuration conflicts on type and value formatters.");
}
return defaultOptions;
}
示例11: createPluginResult
import java.util.Map; //導入方法依賴的package包/類
public static PluginResult createPluginResult(String actionName, Map<String, Object> data, ChcpError error) {
JsonNode errorNode = null;
JsonNode dataNode = null;
if (error != null) {
errorNode = createErrorNode(error.getErrorCode(), error.getErrorDescription());
}
if (data != null && data.size() > 0) {
dataNode = createDataNode(data);
}
return getResult(actionName, dataNode, errorNode);
}
示例12: emptyOrUnmodifiableMap
import java.util.Map; //導入方法依賴的package包/類
private static <K,V> Map<K,V> emptyOrUnmodifiableMap(Map<K,V> map) {
if (map.isEmpty()) {
return Collections.emptyMap();
} else if (map.size() == 1) {
Map.Entry<K, V> entry = map.entrySet().iterator().next();
return Collections.singletonMap(entry.getKey(), entry.getValue());
} else {
return Collections.unmodifiableMap(map);
}
}
示例13: setStringAttributes
import java.util.Map; //導入方法依賴的package包/類
protected synchronized void setStringAttributes ( final Map<String, String> attributes )
{
final Map<String, Variant> convertedAttributes = new HashMap<String, Variant> ( attributes.size () );
for ( final Map.Entry<String, String> entry : attributes.entrySet () )
{
convertedAttributes.put ( entry.getKey (), Variant.valueOf ( entry.getValue () ) );
}
setAttributes ( convertedAttributes );
}
示例14: getFunctionConfigurations
import java.util.Map; //導入方法依賴的package包/類
protected Map<String, FunctionConfiguration> getFunctionConfigurations(final AnnotationHandler handler,
final Set<Method> methods) throws Exception {
info("");
info(GENERATE_CONFIG);
final Map<String, FunctionConfiguration> configMap = handler.generateConfigurations(methods);
if (configMap.size() == 0) {
info(GENERATE_SKIP);
} else {
final String scriptFilePath = getScriptFilePath();
configMap.values().forEach(config -> config.setScriptFile(scriptFilePath));
info(GENERATE_DONE);
}
return configMap;
}
示例15: size
import java.util.Map; //導入方法依賴的package包/類
/**
* Get the size of the map for given block pool
* @param bpid block pool id
* @return the number of replicas in the map
*/
int size(String bpid) {
Map<Long, ReplicaInfo> m = null;
synchronized(mutex) {
m = map.get(bpid);
return m != null ? m.size() : 0;
}
}