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

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

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

HashMap.containsKey介绍

[英]Returns whether this map contains the specified key.
[中]返回此映射是否包含指定的键。

代码示例

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

public final int[] getIntArray(int argLength) {
 if (!aints.containsKey(argLength)) {
  aints.put(argLength, new int[argLength]);
 }
 assert (aints.get(argLength).length == argLength) : "Array not built with correct length";
 return aints.get(argLength);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static final String coarsenUPOSTag(String uPOS) {
  if (coarserUPOSMap.containsKey(uPOS)) {
    return coarserUPOSMap.get(uPOS);
  }
  return uPOS;
}

代码示例来源:origin: Tencent/tinker

void putSanitizeName(RType rType, String sanitizeName, String rawName) {
  HashMap<String, String> sanitizeNameMap;
  if (!sanitizeTypeMap.containsKey(rType)) {
    sanitizeNameMap = new HashMap<>();
    sanitizeTypeMap.put(rType, sanitizeNameMap);
  } else {
    sanitizeNameMap = sanitizeTypeMap.get(rType);
  }
  if (!sanitizeNameMap.containsKey(sanitizeName)) {
    sanitizeNameMap.put(sanitizeName, rawName);
  }
}

代码示例来源:origin: alibaba/jstorm

public static <V> HashMap<V, Integer> multi_set(List<V> list) {
  HashMap<V, Integer> rtn = new HashMap<>();
  for (V v : list) {
    int cnt = 1;
    if (rtn.containsKey(v)) {
      cnt += rtn.get(v);
    }
    rtn.put(v, cnt);
  }
  return rtn;
}

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

HashMap<ByteBuffer, byte[]> kvs = new HashMap<ByteBuffer, byte[]>();
byte[] k1 = new byte[]{1,2 ,3};
byte[] k2 = new byte[]{1,2 ,3};
byte[] val = new byte[]{12,23,43,4};

kvs.put(ByteBuffer.wrap(k1), val);
System.out.println(kvs.containsKey(ByteBuffer.wrap(k2)));

代码示例来源:origin: oracle/opengrok

void addAlias(String alias) throws IllegalArgumentException {
  names.add(alias);
  
  if (options.containsKey(alias)) {
    throw new IllegalArgumentException("** Programmer error! Option " + alias + " already defined");
  }
  
  options.put(alias, this);
}

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

/** Returns the old values of any changed properties. */
public List<Object> getOldValues() {
  List<Object> oldValues = new ArrayList<Object>();
  for (String propertyName : getDirtyProperties()) {
    if (oldCollectionValues().containsKey(propertyName)) {
      oldValues.add(oldCollectionValues.get(propertyName));
    } else {
      try {
        Method g = getter(propertyName);
        if (g == null) {
          throw new IllegalArgumentException("No such property: " + propertyName);
        }
        oldValues.add(g.invoke(proxyObject, null));
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
  return oldValues;
}

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

private void handleUpload(final HttpServletRequest req, final HttpServletResponse resp,
  final Map<String, Object> multipart, final Session session) throws ServletException,
  IOException {
 final HashMap<String, String> ret = new HashMap<>();
 final String projectName = (String) multipart.get("project");
 ajaxHandleUpload(req, resp, ret, multipart, session);
 if (ret.containsKey("error")) {
  setErrorMessageInCookie(resp, ret.get("error"));
 }
 if (ret.containsKey("warn")) {
  setWarnMessageInCookie(resp, ret.get("warn"));
 }
 resp.sendRedirect(req.getRequestURI() + "?project=" + projectName);
}

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

@Override
public ValueNumberFrame getFactAfterLocation(Location location) {
  if (TRACE) {
    System.out.println("getting fact after " + location);
  }
  ValueNumberFrame fact = factAfterLocationMap.get(location);
  if (fact == null) {
    if (TRACE) {
      System.out
      .println("Initialized fact after " + location + " @ "
          + Integer.toHexString(System.identityHashCode(location)) + " in "
          + Integer.toHexString(System.identityHashCode(this)) + " : "
          + factAfterLocationMap.containsKey(location));
    }
    fact = createFact();
    makeFactTop(fact);
    factAfterLocationMap.put(location, fact);
  }
  return fact;
}

代码示例来源:origin: Sable/soot

/**
 * @ast method
 * @aspect InnerClasses
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddJ/Java1.4Backend/InnerClasses.jrag:173
 */
public ASTNode getAccessor(ASTNode source, String name) {
  ArrayList key = new ArrayList(2);
  key.add(source);
  key.add(name);
  if (accessorMap == null || !accessorMap.containsKey(key))
    return null;
  return (ASTNode) accessorMap.get(key);
}

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

public static Request addToNavbar(Request r, String name) {
 assert (!_navbar.containsKey(name));
 ArrayList<MenuItem> arl = new ArrayList();
 boolean useNewTab = false;
 arl.add(new MenuItem(r, name, useNewTab));
 _navbar.put(name, arl);
 _navbarOrdering.add(name);
 return r;
}

代码示例来源:origin: Sable/soot

private soot.SootMethod addGetMethodAccessMeth(soot.SootClass conClass, polyglot.ast.Call call) {
 if ((InitialResolver.v().getPrivateMethodGetAccessMap() != null) && (InitialResolver.v().getPrivateMethodGetAccessMap()
   .containsKey(new polyglot.util.IdentityKey(call.methodInstance())))) {
  return InitialResolver.v().getPrivateMethodGetAccessMap().get(new polyglot.util.IdentityKey(call.methodInstance()));
 }
 String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00";
 ArrayList paramTypes = new ArrayList();
 if (!call.methodInstance().flags().isStatic()) {
  // add this param type
  // paramTypes.add(Util.getSootType(call.methodInstance().container()));
  paramTypes.add(conClass.getType());
 }
 ArrayList sootParamsTypes = getSootParamsTypes(call);
 paramTypes.addAll(sootParamsTypes);
 soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, Util.getSootType(call.methodInstance().returnType()),
   soot.Modifier.STATIC);
 PrivateMethodAccMethodSource pmams = new PrivateMethodAccMethodSource(call.methodInstance());
 conClass.addMethod(meth);
 meth.setActiveBody(pmams.getBody(meth, null));
 InitialResolver.v().addToPrivateMethodGetAccessMap(call, meth);
 meth.addTag(new soot.tagkit.SyntheticTag());
 return meth;
}

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

@Override
  public Double getCost( Relationship relationship, Direction direction )
  {
    if ( !dirs.containsKey( relationship ) )
    {
      dirs.put( relationship, direction );
    }
    return 1.0;
  }
}

代码示例来源:origin: alibaba/jstorm

public static <V> HashMap<V, Integer> multi_set(List<V> list) {
  HashMap<V, Integer> rtn = new HashMap<V, Integer>();
  for (V v : list) {
    int cnt = 1;
    if (rtn.containsKey(v)) {
      cnt += rtn.get(v);
    }
    rtn.put(v, cnt);
  }
  return rtn;
}

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

public synchronized <T> AopFactory addMapping(Class<T> from, Class<? extends T> to) {
  if (from == null || to == null) {
    throw new IllegalArgumentException("The parameter from and to can not be null");
  }
  
  if (mapping == null) {
    mapping = new HashMap<Class<?>, Class<?>>(128, 0.25F);
  } else if (mapping.containsKey(from)) {
    throw new RuntimeException("Class already mapped : " + from.getName());
  }
  
  mapping.put(from, to);
  return this;
}

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

if(getPoints().size() != shape.getPoints().size()) return false;
if(DEBUG) System.out.println("comparing shapes:");
if(DEBUG) System.out.println("points1: ");
HashMap points1 = new HashMap();
Iterator it = getPointsIterator(); 
while(it.hasNext()){
  ShapePoint point = (ShapePoint) it.next(); 
  points1.put( ""+((int) point.x)+","+((int) point.y), null);
  if(DEBUG) System.out.println(((int) point.x)+", "+((int) point.y));
if(DEBUG) System.out.println("points2: ");
HashMap points2 = new HashMap();
it = shape.getPointsIterator(); 
while(it.hasNext()){
  ShapePoint point = (ShapePoint) it.next(); 
  points2.put( ""+((int) point.x)+","+((int) point.y), null);
  if(DEBUG) System.out.println(((int) point.x)+", "+((int) point.y));
while(it.hasNext()){
  String key = (String) it.next();
  if(!points2.containsKey(key)) {
    if (DEBUG)
      System.out.println("\tare not equal");

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

public final float[] getFloatArray(int argLength) {
 if (!afloats.containsKey(argLength)) {
  afloats.put(argLength, new float[argLength]);
 }
 assert (afloats.get(argLength).length == argLength) : "Array not built with correct length";
 return afloats.get(argLength);
}

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

if ( distances.containsKey( node ) )
distances.put( node, (int) depth );
    if ( !distances.containsKey( targetNode ) )
      targetPreds.add( relationship );

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

public void createAndSetScheduleOptions(final Object obj) {
 final HashMap<String, Object> schedObj = (HashMap<String, Object>) obj;
 if (schedObj.containsKey("executionOptions")) {
  final ExecutionOptions execOptions =
    ExecutionOptions.createFromObject(schedObj.get("executionOptions"));
  this.executionOptions = execOptions;
 } else if (schedObj.containsKey("flowOptions")) {
  final ExecutionOptions execOptions =
    ExecutionOptions.createFromObject(schedObj.get("flowOptions"));
  this.executionOptions = execOptions;
  execOptions.setConcurrentOption(ExecutionOptions.CONCURRENT_OPTION_SKIP);
 } else {
  this.executionOptions = new ExecutionOptions();
  this.executionOptions
    .setConcurrentOption(ExecutionOptions.CONCURRENT_OPTION_SKIP);
 }
 if (schedObj.containsKey("slaOptions")) {
  final List<Object> slaOptionsObject = (List<Object>) schedObj.get("slaOptions");
  final List<SlaOption> slaOptions = new ArrayList<>();
  for (final Object slaObj : slaOptionsObject) {
   slaOptions.add(SlaOption.fromObject(slaObj));
  }
  this.slaOptions = slaOptions;
 }
}

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

public static Edge fromObject(final Object obj) {
 final HashMap<String, Object> edgeObj = (HashMap<String, Object>) obj;
 final String source = (String) edgeObj.get("source");
 final String target = (String) edgeObj.get("target");
 final String error = (String) edgeObj.get("error");
 final Edge edge = new Edge(source, target);
 edge.setError(error);
 if (edgeObj.containsKey("guides")) {
  final Map<String, Object> guideMap =
    (Map<String, Object>) edgeObj.get("guides");
  final List<Object> values = (List<Object>) guideMap.get("values");
  final String type = (String) guideMap.get("type");
  final ArrayList<Point2D> valuePoints = new ArrayList<>();
  for (final Object pointObj : values) {
   final Map<String, Double> point = (Map<String, Double>) pointObj;
   final Double x = point.get("x");
   final Double y = point.get("y");
   valuePoints.add(new Point2D.Double(x, y));
  }
  edge.setGuides(type, valuePoints);
 }
 return edge;
}

相关文章