• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

how to throw message in this senario

in the arraylist i have chargeid's and their corresponding billamount;

045--0
162--999
225--900

for above case some charges has billamount then  i dont want to throw message;

 if any chargeid's doesn't have billamount at that time only i want to throw message at client side;
0
chaitu chaitu
Asked:
chaitu chaitu
  • 3
  • 3
1 Solution
 
TimYatesCommented:
>>  i dont want to throw message;

What do you mean "throw message"?

You talking about exceptions?
0
 
chaitu chaituAuthor Commented:
yesss
0
 
koppchaCommented:
It would better to use HashMap with chargeId's as key and billamount as values so that in your case you can just check if that particular chargeId key exist..if it doesn't then throw the message if it exists get the values of the key if the value is zero then also throw the message.
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chaitu chaituAuthor Commented:
i didnt get u;my charge's stored  in arraylist of Housedocumentcharges object
0
 
koppchaCommented:
Ok then iterate throw each element and take each object oy type Housedocumentcharges .In the object you might be having some getter methods to get the charge and billamount if billamount is zero for that particular object then throw the message

public boolean check() throws OwnException{
Iterator HousedocumentchargesIterator = yourArrayList.Iterator();
while(HousedocumentchargesIterator.hasNext()){
Housedocumentcharges  housedocumentcharges= (Housedocumentcharges )usedocumentchargesIterator.next()
if(housedocumentcharges.getBillamount==0){
throw new OwnException;
}
}
return true
}
0
 
chaitu chaituAuthor Commented:
if i have 10 chargeid's and one chargeid will have bill amount at that i dont want to throw a message;

if all the 10 chargeid's have no billamount's at that time only i want throw the exception
0
 
koppchaCommented:
This should do what you want just keep a flag check

public boolean check() throws OwnException{
Iterator HousedocumentchargesIterator = yourArrayList.Iterator();
int  passed = 1;
while(HousedocumentchargesIterator.hasNext()){
Housedocumentcharges  housedocumentcharges= (Housedocumentcharges )usedocumentchargesIterator.next()
if(housedocumentcharges.getBillamount !=0){
passed = 0;
break;
}
}
if (passed==0){
throw new OwnException;
}

return true
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now