Java多重判断的简化

http://my.oschina.net/u/1455908/blog/398481
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<String, Integer> configs = ImmutableMap.of("A",200,"B",4);
        Preconditions.checkNotNull(gradle);
        Integer result = configs.get(gradle);
        if(result==null){
            return 0;
        }
        return result;
    }
}

你可能感兴趣的:(java)