本文整理匯總了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);
}
示例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());
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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);
}