當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。