本文整理汇总了Java中java.util.Map.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java Map.containsKey方法的具体用法?Java Map.containsKey怎么用?Java Map.containsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Map
的用法示例。
在下文中一共展示了Map.containsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillShardCacheWithDataNodes
import java.util.Map; //导入方法依赖的package包/类
/**
* Fills the shard fetched data with new (data) nodes and a fresh NodeEntry, and removes from
* it nodes that are no longer part of the state.
*/
private void fillShardCacheWithDataNodes(Map<String, NodeEntry<T>> shardCache, DiscoveryNodes nodes) {
// verify that all current data nodes are there
for (ObjectObjectCursor<String, DiscoveryNode> cursor : nodes.getDataNodes()) {
DiscoveryNode node = cursor.value;
if (shardCache.containsKey(node.getId()) == false) {
shardCache.put(node.getId(), new NodeEntry<T>(node.getId()));
}
}
// remove nodes that are not longer part of the data nodes set
for (Iterator<String> it = shardCache.keySet().iterator(); it.hasNext(); ) {
String nodeId = it.next();
if (nodes.nodeExists(nodeId) == false) {
it.remove();
}
}
}
示例2: doDifference
import java.util.Map; //导入方法依赖的package包/类
private static <K, V> void doDifference(
Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right,
Equivalence<? super V> valueEquivalence,
Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth,
Map<K, MapDifference.ValueDifference<V>> differences) {
for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
K leftKey = entry.getKey();
V leftValue = entry.getValue();
if (right.containsKey(leftKey)) {
V rightValue = onlyOnRight.remove(leftKey);
if (valueEquivalence.equivalent(leftValue, rightValue)) {
onBoth.put(leftKey, leftValue);
} else {
differences.put(
leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
}
} else {
onlyOnLeft.put(leftKey, leftValue);
}
}
}
示例3: p
import java.util.Map; //导入方法依赖的package包/类
private static void p (Map m, String i, PrintWriter writer, Language language) {
Iterator it = m.keySet ().iterator ();
while (it.hasNext ()) {
Object e = it.next ();
if ("&".equals (e)) continue;
if ("#".equals (e)) continue;
if ("*".equals (e)) continue;
T t = (T) e;
Map m1 = (Map) m.get (e);
String s = m1.containsKey ("#") ? ("#" + m1.get ("#").toString ()) : "";
if (writer == null)
System.out.println (i + t.toString (language) + " " + m1.get ("&") + " " + s);
else
writer.println (i + t.toString (language) + " " + m1.get ("&") + " " + s);
p (m1, i + " ", writer, language);
}
}
示例4: getScoredMutationsIN
import java.util.Map; //导入方法依赖的package包/类
private static List<String> getScoredMutationsIN(Map<Gene, GeneDR> resistanceResults) {
List<String> scoredMutations = new ArrayList<>();
String inMajor = "NA";
String inAccessory = "NA";
if (resistanceResults.containsKey(Gene.IN)) {
GeneDR inResults = resistanceResults.get(Gene.IN);
if (inResults.groupMutationsByTypes().containsKey(MutType.Major)) {
MutationSet major = inResults.groupMutationsByTypes().get(MutType.Major);
inMajor = major.join();
} else {
inMajor = "None";
}
if (inResults.groupMutationsByTypes().containsKey(MutType.Accessory)) {
MutationSet accessory = inResults.groupMutationsByTypes().get(MutType.Accessory);
inAccessory = accessory.join();
} else {
inAccessory = "None";
}
}
scoredMutations.add(inMajor);
scoredMutations.add(inAccessory);
return scoredMutations;
}
示例5: main
import java.util.Map; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<Character, Integer> counter = new HashMap<>();
String line = scanner.nextLine();
for (int i = 0; i < line.length(); i++) {
char a = line.charAt(i);
if (counter.containsKey(a)) {
int w = counter.get(a);
counter.put(a, w+1);
} else {
counter.put(a, 1);
}
}
for (Entry<Character, Integer> entry : counter.entrySet()) {
System.out.println(entry.getKey() + " => " + entry.getValue());
}
}
示例6: getModelRenderer
import java.util.Map; //导入方法依赖的package包/类
public ModelRenderer getModelRenderer(ModelBase model, String modelPart)
{
if (!(model instanceof ModelHorse))
{
return null;
}
else
{
ModelHorse modelhorse = (ModelHorse)model;
Map<String, Integer> map = getMapPartFields();
if (map.containsKey(modelPart))
{
int i = ((Integer)map.get(modelPart)).intValue();
return (ModelRenderer)Reflector.getFieldValue(modelhorse, Reflector.ModelHorse_ModelRenderers, i);
}
else
{
return null;
}
}
}
示例7: get
import java.util.Map; //导入方法依赖的package包/类
public static <V> Optional<V> get(Object owner, Object key) {
Map<Object, Object> map = getMap(owner);
if (map.containsKey(key)) {
return Optional.of((V) map.get(key));
}
return Optional.empty();
}
示例8: parseModule
import java.util.Map; //导入方法依赖的package包/类
private CompilationUnitTree parseModule(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
final Map<?, ?> map = Objects.requireNonNull(scriptObj);
if (map.containsKey("script") && map.containsKey("name")) {
final String script = JSType.toString(map.get("script"));
final String name = JSType.toString(map.get("name"));
final Source src = Source.sourceFor(name, script);
return makeModule(src, listener);
} else {
throw new IllegalArgumentException("can't find 'script' and 'name' properties");
}
}
示例9: getSrcDirTrees
import java.util.Map; //导入方法依赖的package包/类
public Set<DirectoryTree> getSrcDirTrees() {
// This implementation is broken. It does not consider include and exclude patterns
Map<File, DirectoryTree> trees = new LinkedHashMap<File, DirectoryTree>();
for (DirectoryTree tree : doGetSrcDirTrees()) {
if (!trees.containsKey(tree.getDir())) {
trees.put(tree.getDir(), tree);
}
}
return new LinkedHashSet<DirectoryTree>(trees.values());
}
示例10: writeAnyCell
import java.util.Map; //导入方法依赖的package包/类
/**
* Writes out an XML cell based on coordinates and provided value
*
* @param row
* the row index of the cell
* @param col
* the column index
* @param cellValue
* value of the cell, can be null for an empty cell
* @param out
* the XML output stream
* @param columns
* the Map with column titles
*/
private void writeAnyCell(final int row, final int col, final String cellValue, final XMLStreamWriter out,
final Map<String, String> columns) {
try {
out.writeStartElement("cell");
String colNum = String.valueOf(col);
out.writeAttribute("row", String.valueOf(row));
out.writeAttribute("col", colNum);
if (columns.containsKey(colNum)) {
out.writeAttribute("title", columns.get(colNum));
}
if (cellValue != null) {
if (cellValue.contains("<") || cellValue.contains(">")) {
out.writeCData(cellValue);
} else {
out.writeCharacters(cellValue);
}
} else {
out.writeAttribute("empty", "true");
}
out.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
示例11: checkUrl
import java.util.Map; //导入方法依赖的package包/类
/**
* Check the hash for the given user against the stored value from the data
* base.
*/
private String checkUrl(final String user, final String hashData, final Map<String, Object> settings) {
if (settings.containsKey(PREFERRED_HASH)) {
// User has selected a preferred URL, check the corresponding hash
if (hashData.equals(settings.get(PREFERRED_HASH))) {
// Hash matches, return the URL
return (String) settings.get(PREFERRED_URL);
}
// Attempt or bug? report it.
log.error("Attempt to access preferred URL with cookie value : {}|{}", user, hashData);
}
return null;
}
示例12: createInnerFactory
import java.util.Map; //导入方法依赖的package包/类
@Override
protected PredictionAggregationBuilder createInnerFactory(final String aggregationName,
final Map<ParseField, Object> otherOptions) {
final PredictionAggregationBuilder builder = new PredictionAggregationBuilder(aggregationName);
if (otherOptions.containsKey(INPUTS)) {
final List<Double> inputsList = (List<Double>) otherOptions.get(INPUTS);
final double[] inputs = new double[inputsList.size()];
int i = 0;
for (final Double input : inputsList) {
inputs[i++] = input;
}
builder.inputs(inputs);
}
return builder;
}
示例13: getNamesIndex
import java.util.Map; //导入方法依赖的package包/类
private static Map<String,Integer> getNamesIndex(String[] names) {
Map<String,Integer> result = new LinkedHashMap<String,Integer>();
for (String s : names) {
if (!result.containsKey(s)) {
result.put(s, result.size());
}
}
return result;
}
示例14: getXmlnsAttr
import java.util.Map; //导入方法依赖的package包/类
void getXmlnsAttr(Collection<Attr> col) {
int size = levels.size() - 1;
if (cur == null) {
cur = new XmlsStackElement();
cur.level = currentLevel;
lastlevel = currentLevel;
levels.add(cur);
}
boolean parentRendered = false;
XmlsStackElement e = null;
if (size == -1) {
parentRendered = true;
} else {
e = levels.get(size);
if (e.rendered && e.level + 1 == currentLevel) {
parentRendered = true;
}
}
if (parentRendered) {
col.addAll(cur.nodes);
cur.rendered = true;
return;
}
Map<String, Attr> loa = new HashMap<String, Attr>();
for (; size >= 0; size--) {
e = levels.get(size);
Iterator<Attr> it = e.nodes.iterator();
while (it.hasNext()) {
Attr n = it.next();
if (!loa.containsKey(n.getName())) {
loa.put(n.getName(), n);
}
}
}
cur.rendered = true;
col.addAll(loa.values());
}
示例15: handleUserInputWithMoreTokens
import java.util.Map; //导入方法依赖的package包/类
private String handleUserInputWithMoreTokens(String[] part, Collection<String> userRoles) throws
InterruptedException, ShellException {
Map<String, CommandExecutableDetails> commandExecutables = commandMap.get(part[0]);
if (!commandExecutables.containsKey(part[1])) {
throw new ShellException("Unknown subcommand '" + part[1] + "'. Type '" + part[0]
+ "' for supported subcommands");
}
CommandExecutableDetails ced = commandMap.get(part[0]).get(part[1]);
validateExecutableWithUserRole(ced, userRoles);
return ced.executeWithArg(part.length == 2 ? null : part[2]);
}