我正在做一個REST調用,如果該字段是不是有在哈希表更新這些3場,以更新其現場決定,默認情況下它會更新「AA」循環依賴於天數
每次撥打電話時,服務器上的計數器也會增加。所以在3次運行後,所有字段都在服務器上,並且它總是更新「AA」,因爲它是默認值,現在我希望字段更新由計數器選擇。因此,流程繼續爲AA,BB,CC - AA,BB,CC - AA,BB,CC。如何?
//on 1st update call,it updates AA and Counter is set to =1
//2nd update call,it update BB = Counter is set to =2
//3rd update call,it update CC = Counter is set to =3
//4th update call,it update AA = Counter is set to =4
//5th update call,it update AA = Counter is set to =5
//6th update call,it update AA = Counter is set to =6
if (fieldValues.containsKey("COUNTER")) {
counter= fieldValues.get("COUNTER");
}// how can we use this counter to select the next field
HashMap<String, String> fieldValues = [{key,value},{key,value},{key,value}......]
String [] FieldsToUpdate = ["AA","BB","CC"];
String xxxFieldToUpdate = FieldsToUpdate[0];// so default is "AA"
for(String Field : FieldsToUpdate){
if(!fieldValues.containsKey(Field)){
xxxFieldToUpdate = Field.trim();
break;
}
}
// Solved by calling a new method which reset the Iterator //
String fieldToUpdate = "";
counter= fieldValues.get("COUNTER");
Iterator it = fieldsToUpdate.iterator();
for(int i=0; i<counter; i++) {
if(!it.hasNext()) // if you are at the end of the list reset iterator
it = fieldsToUpdate.iterator();
String res = it.next().toString();
fieldToUpdate = res;
}
return fieldToUpdate;
的新方法,我解決我的問題解決了,請參閱在原來的問題我的編輯。謝謝所有 – Lucky