private static Properties getValue(String[] variants) throws NoKeyException
{
Properties properties = new Properties();
for (String variant : variants) {
String key = variant;
String value = monitorClient.getValue(key);
if(value == null)
throw new NoKeyException(variant);
     properties.put(variant, value);
}
return properties;
}读不懂这个方法里的每一行意思,求解!

解决方案 »

  1.   

    感觉像是在写properties 文件。“monitorClient”这个类在哪定义的? 
      

  2.   

    传入一组key
    然后获取这些key在monitorClient里是否存在
    不存在就抛出NoKey异常 存在就put进properties里
      

  3.   

    供楼主参考!private static Properties getValue(String[] variants) throws NoKeyException
    {
    Properties properties = new Properties();//创建properties对象,Properties类是HashMap的子类,其最大的特点是Key和Value都是String
    for (String variant : variants) {//通过遍历传进来的variants数组中的每一个元素
    String key = variant;//设置key
    String value = monitorClient.getValue(key);//取出monitorClient中与key对应的value
    if(value == null)//判断value是否为空,若不为空,将对应的key和value添加至properties对象中。若为空,抛出NoKeyException异常
    throw new NoKeyException(variant);
    properties.put(variant, value);
    }
    return properties;
    }
      

  4.   

    参数为记录KEY的数组,使用monitorClient能找到每个KEY对应的值,最后再把key和值存到properties里。就是用参数封装出一个properties然后作为返回值,properties用来做什么就不知道了。
      

  5.   

    供楼主参考!
    private static Properties getValue(String[] variants) throws NoKeyException
    {
    Properties properties = new Properties();// 创建properties对象,Properties类是HashMap的子类,其最大的特点是Key和Value都是String
    for (String variant : variants)
    {// 通过遍历传进来的variants数组中的每一个元素
    String key = variant;// 设置key
    String value = monitorClient.getValue(key);// 取出monitorClient中与key对应的value
    if (value == null) // 判断value是否为空,若不为空,将对应的key和value添加至properties对象中。若为空,抛出NoKeyException异常
    throw new NoKeyException(variant);
    properties.put(variant, value);
    }
    return properties;
    }
      

  6.   

    通过key找出一个数组variants里面是否有key对应的value,没有就抛出一个异常