本文整理了Java中java.util.Map.size()
方法的一些代码示例,展示了Map.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.size()
方法的具体详情如下:
包路径:java.util.Map
类名称:Map
方法名:size
[英]Returns the number of mappings in this Map.
[中]返回此映射中的映射数。
代码示例来源:origin: google/guava
/**
* Stores the contents of a map in an output stream, as part of serialization. It does not support
* concurrent maps whose content may change while the method is running.
*
* <p>The serialized output consists of the number of entries, first key, first value, second key,
* second value, and so on.
*/
static <K, V> void writeMap(Map<K, V> map, ObjectOutputStream stream) throws IOException {
stream.writeInt(map.size());
for (Map.Entry<K, V> entry : map.entrySet()) {
stream.writeObject(entry.getKey());
stream.writeObject(entry.getValue());
}
}
代码示例来源:origin: bumptech/glide
private Map<String, List<LazyHeaderFactory>> copyHeaders() {
Map<String, List<LazyHeaderFactory>> result = new HashMap<>(headers.size());
for (Map.Entry<String, List<LazyHeaderFactory>> entry : headers.entrySet()) {
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
List<LazyHeaderFactory> valueCopy = new ArrayList<>(entry.getValue());
result.put(entry.getKey(), valueCopy);
}
return result;
}
代码示例来源:origin: hankcs/HanLP
@Override
public int idOf(String string)
{
Integer id = featureIdMap.get(string);
if (id == null)
{
id = featureIdMap.size();
featureIdMap.put(string, id);
}
return id;
}
代码示例来源:origin: google/guava
final void assertNonNullValues(Object... expectedValues) {
assertEquals(expectedValues.length, arguments.size());
for (int i = 0; i < expectedValues.length; i++) {
assertEquals("Default value for parameter #" + i, expectedValues[i], arguments.get(i));
}
}
代码示例来源:origin: spring-projects/spring-framework
private StompHeaders(Map<String, List<String>> headers, boolean readOnly) {
Assert.notNull(headers, "'headers' must not be null");
if (readOnly) {
Map<String, List<String>> map = new LinkedMultiValueMap<>(headers.size());
headers.forEach((key, value) -> map.put(key, Collections.unmodifiableList(value)));
this.headers = Collections.unmodifiableMap(map);
}
else {
this.headers = headers;
}
}
代码示例来源:origin: google/guava
static <N, V> DirectedGraphConnections<N, V> ofImmutable(
Set<N> predecessors, Map<N, V> successorValues) {
Map<N, Object> adjacentNodeValues = new HashMap<>();
adjacentNodeValues.putAll(successorValues);
for (N predecessor : predecessors) {
Object value = adjacentNodeValues.put(predecessor, PRED);
if (value != null) {
adjacentNodeValues.put(predecessor, new PredAndSucc(value));
}
}
return new DirectedGraphConnections<>(
ImmutableMap.copyOf(adjacentNodeValues), predecessors.size(), successorValues.size());
}
代码示例来源:origin: hankcs/HanLP
public int add(String tag)
{
// assertUnlock();
Integer id = stringIdMap.get(tag);
if (id == null)
{
id = stringIdMap.size();
stringIdMap.put(tag, id);
idStringMap.add(tag);
}
return id;
}
代码示例来源:origin: spring-projects/spring-framework
private Map<String, Class<?>> toClassMap(Map<String, ?> map) throws ClassNotFoundException {
Map<String, Class<?>> result = new LinkedHashMap<>(map.size());
for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Class<?> type;
if (value instanceof Class) {
type = (Class<?>) value;
}
else if (value instanceof String) {
String className = (String) value;
type = ClassUtils.forName(className, this.beanClassLoader);
}
else {
throw new IllegalArgumentException("Unknown value [" + value + "] - expected String or Class");
}
result.put(key, type);
}
return result;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testGroupByWithElementSelector() {
Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
Observable<GroupedObservable<Integer, Integer>> grouped = source.groupBy(length, length);
Map<Integer, Collection<Integer>> map = toMap(grouped);
assertEquals(3, map.size());
assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray());
assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray());
assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray());
}
代码示例来源:origin: jenkinsci/jenkins
private PackedMap(Map<? extends K,? extends V> src) {
kvpairs = new Object[src.size()*2];
int i=0;
for (Entry<? extends K, ? extends V> e : src.entrySet()) {
kvpairs[i++] = e.getKey();
kvpairs[i++] = e.getValue();
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy constructor which allows for ignoring certain entries.
* Used for serialization without non-serializable entries.
* @param original the MessageHeaders to copy
* @param keysToIgnore the keys of the entries to ignore
*/
private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) {
this.headers = new HashMap<>(original.headers.size());
original.headers.forEach((key, value) -> {
if (!keysToIgnore.contains(key)) {
this.headers.put(key, value);
}
});
}
代码示例来源:origin: hankcs/HanLP
public int addCategory(String category)
{
Integer id = categoryId.get(category);
if (id == null)
{
id = categoryId.size();
categoryId.put(category, id);
assert idCategory.size() == id;
idCategory.add(category);
}
return id;
}
代码示例来源:origin: apache/kafka
private static Map<TopicPartition, Integer> createPartitionSizes(Map<TopicPartition, MemoryRecords> partitionRecords) {
Map<TopicPartition, Integer> result = new HashMap<>(partitionRecords.size());
for (Map.Entry<TopicPartition, MemoryRecords> entry : partitionRecords.entrySet())
result.put(entry.getKey(), entry.getValue().sizeInBytes());
return result;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testGroupByWithElementSelector2() {
Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
Observable<GroupedObservable<Integer, Integer>> grouped = source.groupBy(length, length);
Map<Integer, Collection<Integer>> map = toMap(grouped);
assertEquals(3, map.size());
assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray());
assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray());
assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray());
}
代码示例来源:origin: jenkinsci/jenkins
private String[] toAttributeList(Map<String, String> attributes) {
String[] r = new String[attributes.size()*2];
int i=0;
for (Entry<String, String> e : attributes.entrySet()) {
r[i++] = e.getKey();
r[i++] = e.getValue();
}
return r;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* For each element in the managed map, resolve reference if necessary.
*/
private Map<?, ?> resolveManagedMap(Object argName, Map<?, ?> mm) {
Map<Object, Object> resolved = new LinkedHashMap<>(mm.size());
mm.forEach((key, value) -> {
Object resolvedKey = resolveValueIfNecessary(argName, key);
Object resolvedValue = resolveValueIfNecessary(new KeyedArgName(argName, key), value);
resolved.put(resolvedKey, resolvedValue);
});
return resolved;
}
代码示例来源:origin: alibaba/druid
public WallSqlTableStat getTableStat(String tableName) {
if (tableStats == null) {
tableStats = new HashMap<String, WallSqlTableStat>(2);
}
String lowerCaseName = tableName.toLowerCase();
WallSqlTableStat stat = tableStats.get(lowerCaseName);
if (stat == null) {
if (tableStats.size() > 100) {
return null;
}
stat = new WallSqlTableStat();
tableStats.put(tableName, stat);
}
return stat;
}
代码示例来源:origin: apache/kafka
private Map<String, Object> unprefixed(Map<String, Object> parsedConfig) {
final Map<String, Object> unprefixedParsedConfig = new HashMap<>(parsedConfig.size());
for (Map.Entry<String, Object> e : parsedConfig.entrySet()) {
if (e.getKey().startsWith(keyPrefix)) {
unprefixedParsedConfig.put(unprefixed(e.getKey()), e.getValue());
}
}
return unprefixedParsedConfig;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testGroupBy() {
Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
Observable<GroupedObservable<Integer, String>> grouped = source.groupBy(length);
Map<Integer, Collection<String>> map = toMap(grouped);
assertEquals(3, map.size());
assertArrayEquals(Arrays.asList("one", "two", "six").toArray(), map.get(3).toArray());
assertArrayEquals(Arrays.asList("four", "five").toArray(), map.get(4).toArray());
assertArrayEquals(Arrays.asList("three").toArray(), map.get(5).toArray());
}
代码示例来源:origin: jenkinsci/jenkins
public String[] getEnv() {
Map<String,String> envs = System.getenv();
String[] envp = new String[envs.size()];
int i = 0;
for (Map.Entry<String,String> e : envs.entrySet()) {
envp[i++] = e.getKey()+'+'+e.getValue();
}
return envp;
}
内容来源于网络,如有侵权,请联系作者删除!