當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。