本文整理汇总了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);
}