这是现有代码:
private void mapLeadingNumber() throws Exception
{
if ( logger.isDebugEnabled() ) logger.debug( "[" + this.orderId + "] mapLeadingNumber HTS - start" );
String leadingNumber = "";
try
{
Product[] products = this.order.mapProducts("LeadingNumber", null, "LeadingNumberAttribute");
for (int i=0; i<products.length; i++)
{
Product htsProduct = products[i];
if (htsProduct.getAttribute().length > 0)
{
leadingNumber = htsProduct.getAttribute()[0].getAttributeValue();
this.spcRequest.getSpcRequest().addNewNpstnLeadingNumberAvail().setNpstnLeadingNumberPtr(leadingNumber);
}
}
if ( logger.isDebugEnabled() ) logger.debug( "[" + this.orderId + "] mapLeadingNumber HTS mapped value " + leadingNumber );
}
catch (Exception e)
{
throw new MappingException("Exception in mapLeadingNumber: " + e.getMessage(), e);
}
if ( logger.isDebugEnabled() ) logger.debug( "[" + this.orderId + "] mapLeadingNumber HTS - end" );
String parent_Id = "";
try
{
Product[] products = this.order.mapProducts("Parent_Id", null, "Parent_IdAttribute");
for (int i=0; i<products.length; i++)
{
Product htsProduct = products[i];
if (htsProduct.getAttribute().length > 0)
{
parent_Id = htsProduct.getAttribute()[0].getAttributeValue();
this.spcRequest.getSpcRequest().addNewNpstnLeadingNumberAvail().setNpstnLeadingNumberPtr(parent_Id);
}
}
if ( logger.isDebugEnabled() ) logger.debug( "[" + this.orderId + "] mapLeadingNumber HTS mapped value " + parent_Id );
}
catch (Exception e)
{
throw new MappingException("Exception in mapLeadingNumber: " + e.getMessage(), e);
}
if ( logger.isDebugEnabled() ) logger.debug( "[" + this.orderId + "] mapLeadingNumber HTS - end" );
}
答案 0 :(得分:0)
您可以使用以下内容:
public static void main(String [] args) {
String parentId = "parentId";
String leadingNumber = "leadingNumber";
System.out.println(join(parentId, leadingNumber));
parentId = null;
System.out.println(join(parentId, leadingNumber));
parentId = "";
System.out.println(join(parentId, leadingNumber));
}
public static String join(String parentId, String leadingNumber) {
List<String> list = (List<String>)Arrays.asList(new String[]{parentId, leadingNumber}).stream().filter(s -> s != null && s != "").collect(Collectors.toList());
return String.join(":", list);
}