Java多重判断的简化

[url]http://my.oschina.net/u/1455908/blog/398481[/url]
package com.bjs.test;

import java.util.Map;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
public class TestIf {
public static void main(String[] args) {
TestIf t = new TestIf();
int result = t.testMapReturn("A");
System.out.println(result);
}

private int testMapReturn(String gradle){
Map configs = ImmutableMap.of("A",200,"B",4);
Preconditions.checkNotNull(gradle);
Integer result = configs.get(gradle);
if(result==null){
return 0;
}
return result;
}
}

你可能感兴趣的:(开源应用)