Java如果条件检查空值和空值

时间:2016-02-01 23:09:11

标签: java

如何在java中为webservice请求编写条件,在我的webservice请求中,我传递的元素为self.userPassword = textField.text; 。在SpeedInfo元素中,有两个子元素SpeedInfoBandwidth

这是我在SoapUI中的请求:

AccessSpeed

我的Java条件:

 <sch:SpeedInfo>
    <ns:Bandwidth xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">4000000</ns:Bandwidth>
    <ns:AccessSpeed xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">4000000</ns:AccessSpeed>
 </sch:SpeedInfo>

我需要我的条件来检查3种情况:

if (request.getSpeedInfo() == null || (request.getSpeedInfo() == null && request.getSpeedInfo().getBandwidth() == null)){
    throw new Exception(" SpeedInfo Bandwidth must be passed in the request ");
}

错误我得到了:

 1. if <speedInfo> itself is not present

 2. <sch:SpeedInfo> is present, but bandwidth not present:

  <sch:SpeedInfo>
      <ns:AccessSpeed xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">40000000</ns:AccessSpeed>
  </sch:SpeedInfo>

 3. Bandwidth is present but no value  
   <sch:SpeedInfo>
      <ns:Bandwidth xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1"></ns:Bandwidth>
      <ns:AccessSpeed xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">40000000</ns:AccessSpeed>
   </sch:SpeedInfo>

2 个答案:

答案 0 :(得分:4)

CurrentCellChanged

if (request.getSpeedInfo() == null || (request.getSpeedInfo() == null && request.getSpeedInfo().getBandwidth() == null)){ getSpeedInfo()进行两次测试是毫无意义的。当然这很明显?而且,这并不能测试单独null为空的情况。

根据您的要求:

  
      
  1. 如果getBandwidth()本身不存在
  2.   
<speedInfo>
  
      
  1. request.getSpeedInfo() == null 存在,但带宽不存在:
  2.   
<sch:SpeedInfo>
  
      
  1. 带宽已存在,但没有值
  2.   
|| request.getSpeedInfo().getBandwidth() == null

全部放在一起:

|| request.getSpeedInfo().getBandwidth().isEmpty() // or whatever API call is appropriate to the datatype

答案 1 :(得分:0)

var newActiveCell = table.rows[activeRowIndex].cells[activeColumnIndex].focus();
activeCell = document.activeElement;

console.log(activeCell);