chaitu chaitu
asked on
adding particular value in arraylist
when i click refresh when the charge list is null i will add 045 charge code in houseDocumentCharges object and added into arraylist;
in the else block if the charge list is there and chargecodes r there other than 045 chargecode, then i add 045 charge code in houseDocumentCharges object ,if exists in chargelist i won't add 045 chargecode in houseDocumentCharges object
finally i will set the list breakBulkHouseModel.setCha
Is this logic fine;
if(breakBulkHouseModel.get
{
if(helper.nextOperation.eq
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
}
else
{
if(helper.nextOperation.eq
{
for(int i=0;i<breakBulkHouseModel.
{
houseDocumentCharges =(HouseDocumentCharges) breakBulkHouseModel.getCha
if(houseDocumentCharges.ch
{
break;
}else
{
houseDocumentCharges.charg
houseDocumentCharges.charg
houseDocumentCharges.payme
chargesList.add(houseDocum
break;
}
}
}
}
//end
breakBulkHouseModel.setCha
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then u must check for null first like this
ArrayList hoursesArray = breakBulkHouseModel.getCha rgesList() ;
if(hoursesArray != null)
{
//then continue
}
ArrayList hoursesArray = breakBulkHouseModel.getCha
if(hoursesArray != null)
{
//then continue
}
replace
>> if(hoursesArray.indexOf("0 45") == -1)
by
if(hoursesArray!=null && hoursesArray.indexOf("045" ) == -1)
>> if(hoursesArray.indexOf("0
by
if(hoursesArray!=null && hoursesArray.indexOf("045"
mmm... that's what petmagdy just said.
You see: we agree ;°)
You see: we agree ;°)
ASKER
if block is ok but in the else block chargelist is not null ,and chargecode 045 is not then add ;other wise dont add 045 charge code;
but 045 value coming twice ;
if(breakBulkHouseModel.get
{
if(helper.nextOperation.eq
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
}
else
{
if(helper.nextOperation.eq
{
ArrayList hoursesArray = breakBulkHouseModel.getCha
if(hoursesArray.indexOf("0
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
}
}
ASKER
i changed in else block 045 charge codes coming twice
if(hoursesArray.indexOf("0 45") == -1)
{
houseDocumentCharges.charg eId="045";
houseDocumentCharges.charg eDescripti on="COLLEC T INTERNATIONAL AIR FREIGHT";
chargesList.add(houseDocum entCharges );
}
if(hoursesArray.indexOf("0
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
ASKER
now in my hoursesArray 162,205 charge codes r there but only one 045 charge code should added but it is adding twice;why?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Wooops, you have to know: when I posted my previous comment, I didn't read you last three comments.
I can't understand ur last comment chaituu
>> I didn't read you last three comments
Although it is no answer to you Q about the doubles, it is still valid ;°)
Although it is no answer to you Q about the doubles, it is still valid ;°)
Answer:
replace
>> if(hoursesArray.indexOf("0 45") != -1)
by
if(hoursesArray.indexOf("0 45") == -1)
replace
>> if(hoursesArray.indexOf("0
by
if(hoursesArray.indexOf("0
ASKER
if breakBulkHouseModel.getCha rgesList() is null ia m just adding 045 chargecode in the arraylist its ok;
but if breakBulkHouseModel.getCha rgesList() is not null say in the breakBulkHouseModel.getCha rgesList() (in this arraylist i have HouseDocumentChargesobject ;) i have charge code 162,205 other than 045 chargecode then i want to add 045 chargecode;
if(breakBulkHouseModel.get ChargesLis t() == null || breakBulkHouseModel.getCha rgesList() .size() == 0)
{
if(helper.nextOperation.eq uals("Refr esh") && breakBulkHouseModel.origin StationTyp e.equals(" N") && breakBulkHouseModel.houseF reightTerm s.equals(" Collect"))
{
houseDocumentCharges.charg eId="045";
houseDocumentCharges.charg eDescripti on="COLLEC T INTERNATIONAL AIR FREIGHT";
chargesList.add(houseDocum entCharges );
}
}
else
{
if(helper.nextOperation.eq uals("Refr esh") && breakBulkHouseModel.origin StationTyp e.equals(" N") && breakBulkHouseModel.houseF reightTerm s.equals(" Collect"))
{
ArrayList hoursesArray = breakBulkHouseModel.getCha rgesList() ;
if(hoursesArray.indexOf("0 45") == -1)
{
houseDocumentCharges.charg eId="045";
houseDocumentCharges.charg eDescripti on="COLLEC T INTERNATIONAL AIR FREIGHT";
chargesList.add(houseDocum entCharges );
}
}
}
but if breakBulkHouseModel.getCha
if(breakBulkHouseModel.get
{
if(helper.nextOperation.eq
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
}
else
{
if(helper.nextOperation.eq
{
ArrayList hoursesArray = breakBulkHouseModel.getCha
if(hoursesArray.indexOf("0
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
}
}
Explanation:
>> if(hoursesArray.indexOf("0 45") == -1) means "045" is NOT in
you had:
>> if(hoursesArray.indexOf("0 45") != -1) meaning "045" is already in (so as a result you had it twice :)
>> if(hoursesArray.indexOf("0
you had:
>> if(hoursesArray.indexOf("0
Don't forget my previous remark...
ASKER
how the compiler knows that Housedocumentcharges .chargeId 045 is there
because hoursesArray is the Arraylis of Housedocumentcharges Object
if(hoursesArray.indexOf("0 45") == -1) how this works;
because hoursesArray is the Arraylis of Housedocumentcharges Object
if(hoursesArray.indexOf("0
the is because the indexOf call equals("045") for each element in ur ArrayList and if true returns the index of this elment if no matches return -1
ASKER
Acctually the arrayList consists of Housedocumentcharges objects which has member vairables like chargeId, paymentAmt, desc etc.
suppose if in the desc member variable of HouseDocumentCharges object contains text like "045"
then what will the indexOf function returns (1 or -1)?
acctually i want scenario like if chargeId member variable of HouseDocumentCharges object only contains 045 then it should return true else false;
suppose if in the desc member variable of HouseDocumentCharges object contains text like "045"
then what will the indexOf function returns (1 or -1)?
acctually i want scenario like if chargeId member variable of HouseDocumentCharges object only contains 045 then it should return true else false;
>> then what will the indexOf function returns (1 or -1)?
Depending on how you implement your indexOf() function
>> i want scenario like if chargeId member variable of HouseDocumentCharges object only contains 045 then it should return true else false
Then you should check all Housedocumentcharges objects contained in the arrayList one by one if their chargeId equals "045"
Depending on how you implement your indexOf() function
>> i want scenario like if chargeId member variable of HouseDocumentCharges object only contains 045 then it should return true else false
Then you should check all Housedocumentcharges objects contained in the arrayList one by one if their chargeId equals "045"
Thanks for accepting
If your not completely happy with our answers (hence the B-grade I assume) don't hesitate to ask for better ;°)
If your not completely happy with our answers (hence the B-grade I assume) don't hesitate to ask for better ;°)
ASKER
actually ur answers solve my purpose i have to do like this to solve my problem
for(int i=0;i<chargesList.size();i ++)
{
houseDocumentCharges =(HouseDocumentCharges)cha rgesList.g et(i);
if(houseDocumentCharges.ch argeId.equ als("045") )
{
cnt++;
}
}
if(cnt == 0)
{
HouseDocumentCharges houseDocumentCharges1 = new HouseDocumentCharges();
houseDocumentCharges1.char geId="045" ;
houseDocumentCharges1.char geDescript ion="COLLE CT INTERNATIONAL AIR FREIGHT";
houseDocumentCharges1.paym entAmount= 0.00;
chargesList.add(0,houseDoc umentCharg es1);
}
and also
if(hoursesArray.indexOf("0 45") == -1) not working correctly in my senario;
anyway thanks for ur help
for(int i=0;i<chargesList.size();i
{
houseDocumentCharges =(HouseDocumentCharges)cha
if(houseDocumentCharges.ch
{
cnt++;
}
}
if(cnt == 0)
{
HouseDocumentCharges houseDocumentCharges1 = new HouseDocumentCharges();
houseDocumentCharges1.char
houseDocumentCharges1.char
houseDocumentCharges1.paym
chargesList.add(0,houseDoc
}
and also
if(hoursesArray.indexOf("0
anyway thanks for ur help
ASKER
{
if(helper.nextOperation.eq
{
ArrayList hoursesArray = breakBulkHouseModel.getCha
if(hoursesArray.indexOf("0
{
houseDocumentCharges.charg
houseDocumentCharges.charg
chargesList.add(houseDocum
}
}
}
IF I DO LIKE THIS I AM GETTING NULLPOINTER EXCEPTION AT THIS LINE hoursesArray.indexOf("045"