当前位置: 首页>>代码示例>>Java>>正文


Java HashMap.getOrDefault方法代码示例

本文整理汇总了Java中java.util.HashMap.getOrDefault方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.getOrDefault方法的具体用法?Java HashMap.getOrDefault怎么用?Java HashMap.getOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.HashMap的用法示例。


在下文中一共展示了HashMap.getOrDefault方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analyze

import java.util.HashMap; //导入方法依赖的package包/类
public String analyze(String phrase){
    ArrayList<String> words= TextOperations.simplifyWords(TextOperations.extractWordsLower(phrase));
    float max=0;
    int index=-1;
    int count=0;
    HashMap<Integer,Float> phrase_meanings=new HashMap<>();
    HashMap<Integer,Integer> mp;
    for(String word : words){
        mp=meanings.getOrDefault(word,null);
        if(mp==null || mp.size()==0) continue;
        count++;
        for(HashMap.Entry<Integer,Float> entry : normalizeMeaningTable(mp).entrySet()){
            float f=phrase_meanings.getOrDefault(entry.getKey(),0f)+entry.getValue();
            phrase_meanings.put(entry.getKey(),f);
            if(f>max) {
                max = f;
                index = entry.getKey();
            }
        }
    }
    if(index<0 || max/count<0.5) return null;
    return meaningNames.get(index);
}
 
开发者ID:DeskChan,项目名称:DeskChan,代码行数:24,代码来源:MeaningExtractor.java

示例2: testComputeState

import java.util.HashMap; //导入方法依赖的package包/类
@Test
public void testComputeState() {
  HashMap<UUID, JobDefinition> jobMap = new HashMap<>();
  HashMap<UUID, InstanceInfo> instanceMap = new HashMap<>();
  mockState1(jobMap, instanceMap);

  JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobMap, instanceMap);

  HashMap<UUID, List<InstanceInfo>> jobInstances = new HashMap<>();
  HashMap<UUID, UUID> instanceToJob = new HashMap<>();

  for (Map.Entry<UUID, InstanceInfo> e : instanceMap.entrySet()) {
    UUID jobId = e.getValue().metadata().jobDefinition();
    instanceToJob.put(e.getKey(), jobId);
    List<InstanceInfo> li = jobInstances.getOrDefault(jobId, new ArrayList<>());
    li.add(e.getValue());
    jobInstances.put(jobId, li);
  }

  assertEquals(jobMap, v.jobs());
  assertEquals(instanceMap, v.instances());
  assertEquals(instanceToJob, v.instanceToJob());
  assertEquals(jobInstances, v.jobInstances());
}
 
开发者ID:uber,项目名称:AthenaX,代码行数:25,代码来源:JobWatcherUtilTest.java

示例3: teach

import java.util.HashMap; //导入方法依赖的package包/类
public void teach(String phrase,String meaning){
    ArrayList<String> words=TextOperations.simplifyWords(TextOperations.extractWordsLower(phrase));
    meaning=meaning.toUpperCase();
    int meanIndex=meaningNames.indexOf(meaning);
    if(meanIndex<0){
        meanIndex=meaningNames.size();
        meaningNames.add(meaning);
    }
    HashMap<Integer,Integer> mp;
    for(String word : words){
        mp=meanings.getOrDefault(word,null);
        if(mp==null){
            mp=new HashMap<Integer,Integer>();
            meanings.put(word,mp);
        }
        int a=mp.getOrDefault(meanIndex,0)+1;
        mp.put(meanIndex,a);
    }
}
 
开发者ID:DeskChan,项目名称:DeskChan,代码行数:20,代码来源:MeaningExtractor.java

示例4: justAte

import java.util.HashMap; //导入方法依赖的package包/类
private static boolean justAte(PlayerDataRPG pd, String id) {
    if (!eatTimers.containsKey(pd.getUUID()))
        eatTimers.put(pd.getUUID(), new HashMap<String, Long>());
    HashMap<String, Long> map = eatTimers.get(pd.getUUID());
    long diff = System.currentTimeMillis() - map.getOrDefault(id, 0l);
    if (diff < 10000) {
        pd.sendMessage(ChatColor.GRAY + "> " + ChatColor.RED + "You just ate a stackable food! Try again in " + String.format("%.1f", 10 - (diff / 1000.0)) + "s.");
        return true;
    }
    map.put(id, System.currentTimeMillis());
    return false;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:13,代码来源:EtcItem.java

示例5: getSegmentClass

import java.util.HashMap; //导入方法依赖的package包/类
private static Class<? extends Segment> getSegmentClass(String segmentName, HashMap<String, Class<? extends Segment>> zSegmentDefinitions) {
    Class<? extends Segment> segmentClass = SegmentName.getSegmentClass(segmentName);

    if (segmentClass == null)
        if (zSegmentDefinitions != null)
            segmentClass = zSegmentDefinitions.getOrDefault(segmentName, null);

    if (segmentClass == null)
        segmentClass = Segment.class;

    return segmentClass;
}
 
开发者ID:endeavourhealth,项目名称:HL7Receiver,代码行数:13,代码来源:Segment.java

示例6: getMode

import java.util.HashMap; //导入方法依赖的package包/类
private void getMode(){
	HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
	modeCount = 0;
	mode = -1;
	for(int num: nums){
		int count = counts.getOrDefault(num, 0);
		counts.put(num, count+1);
		if(count+1 > modeCount){
			modeCount = count+1;
			mode = num;
		}
	}
	
}
 
开发者ID:justhalf,项目名称:weak-semi-crf-naacl2016,代码行数:15,代码来源:SMSNPUtil.java

示例7: hasPermission

import java.util.HashMap; //导入方法依赖的package包/类
@Override
public boolean hasPermission(JavaPlugin plugin, Permission permission) {
    WurstSDK sdk = (WurstSDK) SDK.getClient();
    HashMap<String, Boolean> perms = sdk.getConfig().getPermissions(plugin, token);
    return perms != null && perms.getOrDefault(permission.getName(), false);
}
 
开发者ID:WurstSDK-Team,项目名称:WurstSDK,代码行数:7,代码来源:Kernel.java


注:本文中的java.util.HashMap.getOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。