java.util.HashMap.size()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中java.util.HashMap.size()方法的一些代码示例,展示了HashMap.size()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.size()方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:size

HashMap.size介绍

[英]The number of mappings in this hash map.
[中]此哈希映射中的映射数。

代码示例

代码示例来源:origin: prestodb/presto

/**
 * @since 2.3
 */
public Iterable<Annotation> annotations() {
  if (_annotations == null || _annotations.size() == 0) {
    return Collections.emptyList();
  }
  return _annotations.values();
}

代码示例来源:origin: oblac/jodd

/**
 * Returns all profiles names.
 */
public String[] getAllProfiles() {
  String[] profiles = new String[data.profileProperties.size()];
  int index = 0;
  for (String profileName : data.profileProperties.keySet()) {
    profiles[index] = profileName;
    index++;
  }
  return profiles;
}

代码示例来源:origin: apache/flink

@Override
public Map<String, String> toMap() {
  synchronized (this.confData){
    Map<String, String> ret = new HashMap<>(this.confData.size());
    for (Map.Entry<String, Object> entry : confData.entrySet()) {
      ret.put(entry.getKey(), entry.getValue().toString());
    }
    return ret;
  }
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * <code><pre>
 * type ::= string
 *      ::= int
 * </code></pre>
 */
private void writeType(String type)
    throws IOException {
  flushIfFull();
  int len = type.length();
  if (len == 0) {
    throw new IllegalArgumentException("empty type is not allowed");
  }
  if (_typeRefs == null)
    _typeRefs = new HashMap();
  Integer typeRefV = (Integer) _typeRefs.get(type);
  if (typeRefV != null) {
    int typeRef = typeRefV.intValue();
    writeInt(typeRef);
  } else {
    _typeRefs.put(type, Integer.valueOf(_typeRefs.size()));
    writeString(type);
  }
}

代码示例来源:origin: grandcentrix/tray

@Override
  protected void setUp() throws Exception {
    super.setUp();
    System.setProperty("dexmaker.dexcache",
        "/data/data/" + BuildConfig.APPLICATION_ID + ".test/cache");
    mDataStore = new HashMap<>();
    mDataStore.put(OLD_KEY, DATA);
    assertEquals(1, mDataStore.size());

    mTrayPreference = new MockSimplePreferences(1);
    assertEquals(0, mTrayPreference.getAll().size());
  }
}

代码示例来源:origin: geoserver/geoserver

public String[][] getHeaders(Object value, Operation operation) throws ServiceException {
  Response delegate = (Response) value;
  HashMap map = new HashMap();
  if (delegate.getContentDisposition() != null) {
    map.put("Content-Disposition", delegate.getContentDisposition());
  }
  HashMap m = delegate.getResponseHeaders();
  if (m != null && !m.isEmpty()) {
    map.putAll(m);
  }
  if (map == null || map.isEmpty()) return null;
  String[][] headers = new String[map.size()][2];
  List keys = new ArrayList(map.keySet());
  for (int i = 0; i < headers.length; i++) {
    headers[i][0] = (String) keys.get(i);
    headers[i][1] = (String) map.get(keys.get(i));
  }
  return headers;
}

代码示例来源:origin: brianfrankcooper/YCSB

private HashMap<String, ByteIterator> extractResult(Document item) {
 if (null == item) {
  return null;
 }
 HashMap<String, ByteIterator> rItems = new HashMap<>(item.getHashMap().size());
 for (Entry<String, Object> attr : item.getHashMap().entrySet()) {
  LOGGER.trace("Result- key: {}, value: {}", attr.getKey(), attr.getValue().toString());
  rItems.put(attr.getKey(), new StringByteIterator(attr.getValue().toString()));
 }
 return rItems;
}

代码示例来源:origin: com.h2database/h2

/**
 * Update session meta data information and get the information in a map.
 *
 * @return a map containing the session meta data
 */
HashMap<String, Object> getInfo() {
  HashMap<String, Object> m = new HashMap<>(map.size() + 5);
  m.putAll(map);
  m.put("lastAccess", new Timestamp(lastAccess).toString());
  try {
    m.put("url", conn == null ?
        "${text.admin.notConnected}" : conn.getMetaData().getURL());
    m.put("user", conn == null ?
        "-" : conn.getMetaData().getUserName());
    m.put("lastQuery", commandHistory.isEmpty() ?
        "" : commandHistory.get(0));
    m.put("executing", executingStatement == null ?
        "${text.admin.no}" : "${text.admin.yes}");
  } catch (SQLException e) {
    DbException.traceThrowable(e);
  }
  return m;
}

代码示例来源:origin: stackoverflow.com

private HashMap<String, String> mData = new HashMap<String, String>();
private String[] mKeys;
public HashMapAdapter(HashMap<String, String> data){
  mData  = data;
  mKeys = mData.keySet().toArray(new String[data.size()]);
  return mData.size();
  return mData.get(mKeys[position]);

代码示例来源:origin: redisson/redisson

public CtMethod[] getMethods() {
  HashMap h = new HashMap();
  getMethods0(h, this);
  return (CtMethod[])h.values().toArray(new CtMethod[h.size()]);
}

代码示例来源:origin: geotools/geotools

eForm = s1.isElementFormDefault() || s2.isElementFormDefault();
HashMap m = new HashMap();
for (int i = 0; i < ag1.length; i++) m.put(ag1[i].getName(), ag1[i]);
attributeGroups = new AttributeGroup[m.size()];
Object[] obj = m.values().toArray();
attributes = new Attribute[m.size()];
obj = m.values().toArray();
complexTypes = new ComplexType[m.size()];
obj = m.values().toArray();
simpleTypes = new SimpleType[m.size()];
obj = m.values().toArray();
elements = new Element[m.size()];
obj = m.values().toArray();
groups = new Group[m.size()];
obj = m.values().toArray();
imports = new Schema[m.size()];
obj = m.values().toArray();

代码示例来源:origin: com.h2database/h2

/**
 * Get the class id, or null if not found.
 *
 * @param clazz the class
 * @return the class id or null
 */
static Integer getCommonClassId(Class<?> clazz) {
  HashMap<Class<?>, Integer> map = COMMON_CLASSES_MAP;
  if (map.size() == 0) {
    // lazy initialization
    // synchronized, because the COMMON_CLASSES_MAP is not
    synchronized (map) {
      if (map.size() == 0) {
        for (int i = 0, size = COMMON_CLASSES.length; i < size; i++) {
          map.put(COMMON_CLASSES[i], i);
        }
      }
    }
  }
  return map.get(clazz);
}

代码示例来源:origin: cmusphinx/sphinx4

/**
   * Convert a HashMap to string array
   * 
   * @param syms the input HashMap
   * @return the strings array
   */
  public static String[] toStringArray(HashMap<String, Integer> syms) {
    String[] res = new String[syms.size()];
    for (String sym : syms.keySet()) {
      res[syms.get(sym)] = sym;
    }
    return res;
  }
}

代码示例来源:origin: FudanNLP/fnlp

private void calcAV() {
  System.out.println("count: "+left.size());
  Iterator<String> it = left.keySet().iterator();		
  while(it.hasNext()){
    String key = it.next();
    Double l = Math.log(left.get(key).size());
    Double r = Math.log(right.get(key).size());
    av.put(key, (int)Math.min(l, r));
  }
  System.out.println("av count: "+av.size());
}

代码示例来源:origin: com.h2database/h2

private static int increment(HashMap<String, Integer> map, String trace,
    int minCount) {
  Integer oldCount = map.get(trace);
  if (oldCount == null) {
    map.put(trace, 1);
  } else {
    map.put(trace, oldCount + 1);
  }
  while (map.size() > MAX_ELEMENTS) {
    for (Iterator<Map.Entry<String, Integer>> ei =
        map.entrySet().iterator(); ei.hasNext();) {
      Map.Entry<String, Integer> e = ei.next();
      if (e.getValue() <= minCount) {
        ei.remove();
      }
    }
    if (map.size() > MAX_ELEMENTS) {
      minCount++;
    }
  }
  return minCount;
}

代码示例来源:origin: org.apache.lucene/lucene-core

FieldInfos finish() {
  finished = true;
  return new FieldInfos(byName.values().toArray(new FieldInfo[byName.size()]));
 }
}

代码示例来源:origin: org.apache.poi/poi

@Override
public Set<Entry<String, Object>> entrySet() {
  Map<String,Object> set = new LinkedHashMap<>(props.size());
  for (Entry<Long,String> se : dictionary.entrySet()) {
    set.put(se.getValue(), props.get(se.getKey()).getValue());
  }
  return Collections.unmodifiableSet(set.entrySet());
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

protected void generateAlias(String name, byte type) {
  byte alias = (byte) cObj.nameFields.size();
  cObj.nameFields.put(name, new BinaryClassField(name, alias, type));
}

代码示例来源:origin: h2oai/h2o-2

@Override void apply(Env env, int argcnt, ASTApply apply) {
 final boolean warn_missing = env.popDbl() == 1;
 final String replace = env.popStr();
 String skey = env.key();
 Frame fr = env.popAry();
 if (fr.numCols() != 1) throw new IllegalArgumentException("revalue works on a single column at a time.");
 String[] old_dom = fr.anyVec()._domain;
 if (old_dom == null) throw new IllegalArgumentException("Column is not a factor column. Can only revalue a factor column.");
 HashMap<String, String> dom_map = hashMap(replace);
 for (int i = 0; i < old_dom.length; ++i) {
  if (dom_map.containsKey(old_dom[i])) {
   old_dom[i] = dom_map.get(old_dom[i]);
   dom_map.remove(old_dom[i]);
  }
 }
 if (dom_map.size() > 0 && warn_missing) {
  for (String k : dom_map.keySet()) {
   env._warnings = Arrays.copyOf(env._warnings, env._warnings.length + 1);
   env._warnings[env._warnings.length - 1] = "Warning: old value " + k + " not a factor level.";
  }
 }
}

代码示例来源:origin: plutext/docx4j

int nextId = getAbstractListDefinitions().size();		
do {
  nextId++;            
} while (getAbstractListDefinitions().containsKey( "" + nextId ));    	
abstractNum.setAbstractNumId( BigInteger.valueOf(nextId) );
abstractListDefinitions.put(absNumDef.getID(), absNumDef);
num.setAbstractNumId(abstractNumId);
nextId = getInstanceListDefinitions().size();		
do {
  nextId++;            
} while (getInstanceListDefinitions().containsKey( "" + nextId ));    	
num.setNumId( BigInteger.valueOf(nextId) );  
instanceListDefinitions.put(listDef.getListNumberId(), listDef);

相关文章