java.util.Map.containsValue()方法的使用及代码示例

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

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

Map.containsValue介绍

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

代码示例

代码示例来源:origin: hankcs/HanLP

@Override
public boolean contains(Object o)
{
  if (o instanceof String)
    return termFrequencyMap.containsKey(o);
  else if (o instanceof TermFrequency)
    return termFrequencyMap.containsValue(o);
  return false;
}

代码示例来源:origin: groovy/groovy-core

private static String findNamespaceTag(final Map tagMap, final Object namespaceURI) {
  if (tagMap.containsValue(namespaceURI)) {
    for (Object o : tagMap.entrySet()) {
      final Map.Entry entry = (Map.Entry) o;
      if (namespaceURI.equals(entry.getValue())) {
        return (String) entry.getKey();
      }
    }
  }
  return null;
}

代码示例来源:origin: skylot/jadx

private String getValidTagAttributeName(String originalName) {
  if (XMLChar.isValidName(originalName)) {
    return originalName;
  }
  if (tagAttrDeobfNames.containsKey(originalName)) {
    return tagAttrDeobfNames.get(originalName);
  }
  String generated;
  do {
    generated = generateTagAttrName();
  }
  while (tagAttrDeobfNames.containsValue(generated));
  tagAttrDeobfNames.put(originalName, generated);
  return generated;
}

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

private String changeWord(final String word) {
  final String lower = word.toLowerCase();
  if (except.contains(lower) || lower.matches("^[a-f0-9]{6}$")) {
    return word;
  }
  String res = convert.get(word);
  if (res != null) {
    return res;
  }
  int len = word.length();
  if (len < 4) {
    len = 4;
  }
  while (true) {
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < len; i++) {
      final char letter = (char) ('a' + rnd.nextInt(26));
      sb.append(letter);
    }
    res = sb.toString();
    if (convert.containsValue(res) == false) {
      convert.put(word, res);
      return res;
    }
  }
}

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

/**
 * Add the specified mapping if the namespace URI has not been mapped before.
 * 
 * <p>This method will ensure that the mapping is actually unique, that is that
 * the namespace URI correspond to one and only one prefix and that the prefix only
 * corresponds to one and only one namespace URI.
 * 
 * @param uri    The namespace URI to map.
 * @param prefix The prefix to use.
 * 
 * @throws NullPointerException if the URI or prefix is <code>null</code>
 */
public void add(String uri, String prefix) throws NullPointerException {
 if (!this.mappings.containsKey(uri)) {
  int count = 0;
  String actualPrefix = prefix;
  while (this.mappings.containsValue(actualPrefix)) {
   actualPrefix = prefix + count++;
  }
  this.mappings.put(uri, actualPrefix);
 }
}

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

@ExpectWarning("DMI")
public static void main(String args[]) {
  Set s = new HashSet();
  s.contains(s);
  s.remove(s);
  s.removeAll(s);
  s.retainAll(s);
  s.containsAll(s);
  Map m = new HashMap();
  m.get(m);
  m.remove(m);
  m.containsKey(m);
  m.containsValue(m);
  List lst = new LinkedList();
  lst.indexOf(lst);
  lst.lastIndexOf(lst);
}

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

/**
 * If a {@link NameCommentRecord} is added or the name it references
 *  is renamed, then this will update the lookup cache for it.
 *
 * @param commentRecord the comment record
 */
public void updateNameCommentRecordCache(final NameCommentRecord commentRecord) {
  if(commentRecords.containsValue(commentRecord)) {
   for(Entry<String,NameCommentRecord> entry : commentRecords.entrySet()) {
     if(entry.getValue().equals(commentRecord)) {
      commentRecords.remove(entry.getKey());
      break;
     }
   }
  }
  commentRecords.put(commentRecord.getNameText(), commentRecord);
}

代码示例来源:origin: skylot/jadx

public void bindArg(RegisterArg arg, BlockNode pred) {
  if (blockBinds.containsValue(pred)) {
    throw new JadxRuntimeException("Duplicate predecessors in PHI insn: " + pred + ", " + this);
  }
  addArg(arg);
  blockBinds.put(arg, pred);
}

代码示例来源:origin: google/guava

public void testPutAllExistingKey() {
 final Map<K, V> map;
 final K keyToPut;
 final V valueToPut;
 try {
  map = makePopulatedMap();
  valueToPut = getValueNotInPopulatedMap();
 } catch (UnsupportedOperationException e) {
  return;
 }
 keyToPut = map.keySet().iterator().next();
 final Map<K, V> mapToPut = Collections.singletonMap(keyToPut, valueToPut);
 int initialSize = map.size();
 if (supportsPut) {
  map.putAll(mapToPut);
  assertEquals(valueToPut, map.get(keyToPut));
  assertTrue(map.containsKey(keyToPut));
  assertTrue(map.containsValue(valueToPut));
 } else {
  try {
   map.putAll(mapToPut);
   fail("Expected UnsupportedOperationException.");
  } catch (UnsupportedOperationException expected) {
  }
 }
 assertEquals(initialSize, map.size());
 assertInvariants(map);
}

代码示例来源:origin: loklak/loklak_server

String transport = configMap.get("elasticsearch_transport.enabled");
if (transport != null && "true".equals(transport)) {
  String cluster_name = configMap.get("elasticsearch_transport.cluster.name");
  String transport_addresses_string = configMap.get("elasticsearch_transport.addresses");
  if (transport_addresses_string != null && transport_addresses_string.length() > 0) {
  for (Map.Entry<String, String> entry: config.entrySet()) {
    String key = entry.getKey();
    if (key.startsWith("elasticsearch.")) settings.put(key.substring(14), entry.getValue());
boolean noio = configMap.containsValue("noio") && configMap.get("noio").equals("true");
messages = new MessageFactory(noio ? null : elasticsearch_client, IndexName.messages.name(), CACHE_MAXSIZE, EXIST_MAXSIZE);
messages_hour = new MessageFactory(noio ? null : elasticsearch_client, IndexName.messages_hour.name(), CACHE_MAXSIZE, EXIST_MAXSIZE);

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

public void recalculatePermissionDefaults(Permission perm) {
  if (permissions.containsValue(perm)) {
    defaultPerms.get(true).remove(perm);
    defaultPerms.get(false).remove(perm);
    calculatePermissionDefault(perm);
  }
}

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

/**
 * Checks map emptiness.
 *
 * @param map Map to check.
 * @throws Exception If failed.
 */
private void checkEmptyMap(Map<?, ?> map) throws Exception {
  assert map.isEmpty();
  assert !map.containsKey("key");
  assert !map.containsValue("value");
  assertEquals(0, map.size());
  assert map.keySet().isEmpty();
  assert map.entrySet().isEmpty();
  assert map.values().isEmpty();
  assert !map.keySet().iterator().hasNext();
  assert !map.entrySet().iterator().hasNext();
  assert !map.values().iterator().hasNext();
}

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

private String getNewPackageNamePart(String oldPackageNamePart) {
 if (oldPackageNamePart != null && oldToNewPackageNames.containsKey(oldPackageNamePart)) {
  return oldToNewPackageNames.get(oldPackageNamePart);
 }
 int size = 5;
 int tries = 0;
 String newPackageNamePart = "";
 while (newPackageNamePart.length() < NameGenerator.NAME_MAX_LENGTH) {
  synchronized (packageNamesMapLock) {
   if (oldToNewPackageNames.containsValue(newPackageNamePart)) {
    return oldToNewPackageNames.get(newPackageNamePart);
   }
   newPackageNamePart = nameGenerator.generateName(size);
   if (!oldToNewPackageNames.containsValue(newPackageNamePart)) {
    final String key = oldPackageNamePart == null ? newPackageNamePart : oldPackageNamePart;
    oldToNewPackageNames.put(key, newPackageNamePart);
    return newPackageNamePart;
   }
  }
  if (tries++ > size) {
   size++;
   tries = 0;
  }
 }
 throw new IllegalStateException("Cannot generate unique package name part: too long for JVM.");
}

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

/**
 * Method setDefaultPrefix
 *
 * @param namespace
 * @param prefix
 * @throws XMLSecurityException
 * @throws SecurityException if a security manager is installed and the
 *    caller does not have permission to set the default prefix
 */
public static void setDefaultPrefix(String namespace, String prefix)
  throws XMLSecurityException {
  JavaUtils.checkRegisterPermission();
  if (prefixMappings.containsValue(prefix)) {
    String storedPrefix = prefixMappings.get(namespace);
    if (!storedPrefix.equals(prefix)) {
      Object exArgs[] = { prefix, namespace, storedPrefix };
      throw new XMLSecurityException("prefix.AlreadyAssigned", exArgs);
    }
  }
  
  if (Constants.SignatureSpecNS.equals(namespace)) {
    XMLUtils.setDsPrefix(prefix);
  }
  if (EncryptionConstants.EncryptionSpecNS.equals(namespace)) {
    XMLUtils.setXencPrefix(prefix);
  }
  prefixMappings.put(namespace, prefix);
}

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

/**
 * Adds mapping for class name.
 *
 * @param classNameSource
 *          the class name to rename
 * @param classNameTarget
 *          the new class name
 */
public void addClassNameMapping(String classNameSource, String classNameTarget) {
 synchronized (classNamesMapLock) {
  if (!oldToNewClassNames.containsKey(classNameSource) && !oldToNewClassNames.containsValue(classNameTarget)
    && !BodyBuilder.nameList.contains(classNameTarget)) {
   oldToNewClassNames.put(classNameSource, classNameTarget);
   BodyBuilder.nameList.add(classNameTarget);
   return;
  }
 }
 throw new IllegalStateException("Cannot generate unique name: too long for JVM.");
}

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

public static boolean entityHaveDifferentLocation(Mention m, Mention a, Dictionaries dict) {
 if ((dict.statesAbbreviation.containsKey(a.spanToString()) || dict.statesAbbreviation.containsValue(a.spanToString()))
    && (m.headString.equalsIgnoreCase("country") || m.headString.equalsIgnoreCase("nation"))) {
  return true;
  if (w.get(CoreAnnotations.NamedEntityTagAnnotation.class).equals("LOCATION")) {
   String loc = text;
   if(dict.statesAbbreviation.containsKey(loc)) loc = dict.statesAbbreviation.get(loc);
   locationM.add(lowercased);
  if (w.get(CoreAnnotations.NamedEntityTagAnnotation.class).equals("LOCATION")) {
   String loc = text;
   if(dict.statesAbbreviation.containsKey(loc)) loc = dict.statesAbbreviation.get(loc);
   locationA.add(lowercased);

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

public static String getJsonWithUpdatedResources(String jsonConf, Map<String, Double> resourceUpdates) {
  try {
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(jsonConf);
    JSONObject jsonObject = (JSONObject) obj;
    Map<String, Double> componentResourceMap =
      (Map<String, Double>) jsonObject.getOrDefault(
        Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, new HashMap<String, Double>()
      );
    for (Map.Entry<String, Double> resourceUpdateEntry : resourceUpdates.entrySet()) {
      if (NormalizedResources.RESOURCE_NAME_NORMALIZER.getResourceNameMapping().containsValue(resourceUpdateEntry.getKey())) {
        // if there will be legacy values they will be in the outer conf
        jsonObject.remove(getCorrespondingLegacyResourceName(resourceUpdateEntry.getKey()));
        componentResourceMap.remove(getCorrespondingLegacyResourceName(resourceUpdateEntry.getKey()));
      }
      componentResourceMap.put(resourceUpdateEntry.getKey(), resourceUpdateEntry.getValue());
    }
    jsonObject.put(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, componentResourceMap);
    return jsonObject.toJSONString();
  } catch (ParseException ex) {
    throw new RuntimeException("Failed to parse component resources with json: " + jsonConf);
  }
}

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

/**
 * Mark that a task has become active and should be tracked by its container
 * ID. Prior to this, the task is not associated with a container.
 *
 * @param task
 */
public void containerAllocated(Task task) {
 assert !activeContainers.containsValue(task);
 assert !allocatingTasks.contains(task);
 assert !pendingTasks.contains(task);
 activeContainers.put(task.getContainerId(), task);
 controller.containerAllocated(task);
}

代码示例来源:origin: google/guava

public void testPutAllNewKey() {
 final Map<K, V> map = makeEitherMap();
 final K keyToPut;
 final V valueToPut;
 try {
  keyToPut = getKeyNotInPopulatedMap();
  valueToPut = getValueNotInPopulatedMap();
 } catch (UnsupportedOperationException e) {
  return;
 }
 final Map<K, V> mapToPut = Collections.singletonMap(keyToPut, valueToPut);
 if (supportsPut) {
  int initialSize = map.size();
  map.putAll(mapToPut);
  assertEquals(valueToPut, map.get(keyToPut));
  assertTrue(map.containsKey(keyToPut));
  assertTrue(map.containsValue(valueToPut));
  assertEquals(initialSize + 1, map.size());
 } else {
  try {
   map.putAll(mapToPut);
   fail("Expected UnsupportedOperationException.");
  } catch (UnsupportedOperationException expected) {
  }
 }
 assertInvariants(map);
}

代码示例来源:origin: ben-manes/caffeine

@Test(dataProvider = "caches")
@CacheSpec(requiresWeakOrSoft = true, expireAfterAccess = Expire.DISABLED,
  expireAfterWrite = Expire.DISABLED, maximumSize = Maximum.DISABLED,
  weigher = CacheWeigher.DEFAULT, population = Population.FULL, stats = Stats.ENABLED,
  removalListener = Listener.CONSUMING)
public void containsValue(Map<Integer, Integer> map, CacheContext context) {
 Integer key = context.firstKey();
 Integer value = context.original().get(key);
 context.clear();
 GcFinalization.awaitFullGc();
 assertThat(map.containsValue(value), is(true));
 key = null;
 GcFinalization.awaitFullGc();
 assertThat(map.containsValue(value), is(not(context.isWeakKeys())));
}

相关文章