使用java命名约定

时间:2014-08-12 04:54:20

标签: java eclipse loops soap while-loop

所以我一直在构建一个soap消息,它接受元素并构建一个soap结构。如果您对此内容不确定,请不要害怕对此进行抨击。我正在寻找某种变化的变量名称。下面的所有内容都是一行的一部分。它们可以是xml文件中的几行,所以我决定将它循环到一个数组中,并将它们作为元素单独插入。在第二块代码中,您可以看到“CHANGINGVARIABLE”但是我不知道如何避免这种情况,并根据没有预定义变量的数量来保持插入元素。任何提示或帮助将非常感谢使这项工作!

boolean finished = false; // true if there is no more item to process 

while(!finished) {
    String itemNumberz = eElement.getElementsByTagName("ItemNumber").item(cnt).getTextContent();
    String receiptTypez = eElement.getElementsByTagName("ReceiptType").item(cnt).getTextContent();
    String descriptionz = eElement.getElementsByTagName("ReceiptType").item(cnt).getTextContent();
    String locationCodez = eElement.getElementsByTagName("ReceiptType").item(cnt).getTextContent();
    String quantityz = eElement.getElementsByTagName("ReceiptType").item(cnt).getTextContent();
    String UnitOfMeasurez = eElement.getElementsByTagName("ReceiptType").item(cnt).getTextContent();
    String UnitCostz = eElement.getElementsByTagName("ReceiptType").item(cnt).getTextContent();

    listItemNumbers.add(itemNumberz);
    listReceiptTypes.add(receiptTypez);
    listDescriptions.add(descriptionz);
    listLocationCodes.add(locationCodez);
    listQuantitys.add(quantityz);
    listUnitOfMeasures.add(UnitOfMeasurez);
    listUnitCosts.add(UnitCostz);

    ++cnt;

    finished = (cnt >= eElement.getElementsByTagName("ItemNumber").getLength());
    //finished = (cnt >= eElement.getElementsByTagName("ReceiptType").getLength());
    System.out.println(cnt);
}

// use them :
int indexYouNeed = 1;
String itemNumber44 = listItemNumbers.get(indexYouNeed);
//System.out.println(itemNumber44);

以下是我如何将它们应用到肥皂信息中。

while(cnt < 0) {
    String name = (cnt + "add");
    int[] CHANGINGVARIABLE = new int[cnt];
    CHANGINGVARIABLE[x] = someValue;


    SOAPElement CHANGINGVARIABLE = soapBodyElem7.addChildElement("LineItem");

    SOAPElement soapBodyElem9 = CHANGINGVARIABLE.addChildElement("ItemNumber");
    soapBodyElem9.addTextNode(listItemNumbers.get(cnt - 1));
    SOAPElement soapBodyElemaa = CHANGINGVARIABLE.addChildElement("ReceiptType");
    soapBodyElemaa.addTextNode(listReceiptTypes.get(cnt - 1));
    SOAPElement soapBodyElemaaa = CHANGINGVARIABLE.addChildElement("Description");
    soapBodyElemaaa.addTextNode(listDescriptions.get(cnt - 1));
    SOAPElement soapBodyElemaaaa = CHANGINGVARIABLE.addChildElement("Quantity");
    soapBodyElemaaaa.addTextNode(listQuantitys.get(cnt - 1));
    SOAPElement soapBodyElemaaaaa = CHANGINGVARIABLE.addChildElement("UnitOfMeasurement");
    soapBodyElemaaaaa.addTextNode(listUnitOfMeasures.get(cnt - 1));
    SOAPElement soapBodyElemaaaaaa = CHANGINGVARIABLE.addChildElement("UnitPrice");
    soapBodyElemaaaaaa.addTextNode(listUnitCosts.get(cnt - 1));
    SOAPElement soapBodyElemaaaaaaa = CHANGINGVARIABLE.addChildElement("LocationCode");
    soapBodyElemaaaaaaa.addTextNode(listLocationCodes.get(cnt - 1));

1 个答案:

答案 0 :(得分:0)

根据您的解释,您可以选择使用列表还是数组。然后通过循环将新的SOAPElements添加到列表或数组中。

**For Array:**
SOAPElement[] soapArr = new SOAPElement[size];
for(int i=0; i < size; i++) {
    soapArr[i] = new SOAPElement();
}

**For List:**
List soapList = new LinkedList();
for(int i=0; i < size; i++){
    soapList.add(new SOAPElement());
}

然后在引用CHANGINGVARIABLEs时循环遍历第二个代码块,如下所示:

soapArr[i]soapList.get(i)

我希望我能正确理解你的需要。