当前位置: 首页>>代码示例>>Java>>正文


Java Map.size方法代码示例

本文整理汇总了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;  
}
 
开发者ID:stytooldex,项目名称:stynico,代码行数:23,代码来源:Test.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:FilterKey.java

示例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();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:20,代码来源:StringUtils.java

示例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);
	}
}
 
开发者ID:arangodb,项目名称:java-velocypack,代码行数:21,代码来源:VPackSerializeDeserializeTest.java

示例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;
}
 
开发者ID:mmjang,项目名称:quiz_helper,代码行数:10,代码来源:Utils.java

示例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();
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:8,代码来源:AlloyUtilities.java

示例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;
}
 
开发者ID:WasiqB,项目名称:coteafs-services,代码行数:14,代码来源:RequestHandler.java

示例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;
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:40,代码来源:UrlUtils.java

示例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();
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:19,代码来源:ElasticsearchClient.java

示例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;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:17,代码来源:VariableFormatter.java

示例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);
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:15,代码来源:PluginResultHelper.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ModuleDescriptor.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:12,代码来源:AbstractStateMonitor.java

示例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;
}
 
开发者ID:Microsoft,项目名称:azure-maven-plugins,代码行数:16,代码来源:PackageMojo.java

示例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;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:ReplicaMap.java


注:本文中的java.util.Map.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。