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

contains method still not validating properly? any problem my bean class

contains method still not validating properly

in the chargelist i have charges 162,620;

chargelist contains other than 620 i.e 162 chargeid exists in the list why it is not entering into if loop;


   if(chargesList!=null && chargesList.size()>0)
            {
    if (!chargesList.contains( new HouseDocumentCharges("620")) )
    {
                        userInputModel = new UserInputModel(vndrList,"vendorIdLabel", ValidationConstants.MULTI_VENDOR_VALIDATION_NAME,4);//changed validation code from 3 to 4
                        validationModel.addUserInput("Vendor(s)",userInputModel);
    }


 any problem my bean class

public class HouseDocumentCharges implements Serializable,Cloneable
{

      public String            costIncurredAt;
      
      public String            chargeId;
      public String            chargeDescription;
      

       public HouseDocumentCharges(String chargeId) {
       this.chargeId = chargeId;
   }

  public boolean equals(Object obj) {
       return chargeId.equals( ((HouseDocumentCharges)obj).chargeId );
   }
   public int hashCode() {
       return chargeId.hashCode();
   }

}
    }
0
chaitu chaitu
Asked:
chaitu chaitu
  • 3
  • 2
1 Solution
 
objectsCommented:
because it contains an element with chargeid=620
0
 
chaitu chaituAuthor Commented:
but chargeList also contains 162 chargeid naa...
0
 
chaitu chaituAuthor Commented:
then what is the solution.......................
0
 
objectsCommented:
>     if (!chargesList.contains( new HouseDocumentCharges("620")) )

your if conditions is "if list does not contain '620'", which is false as it does contain "620"

> then what is the solution.......................

Depends on what condition you want it to be true
0
 
objectsCommented:
fpr example if you want it to return true if it contains 620 or 621 then use:

    if (chargesList.contains( new HouseDocumentCharges("620")) ||
        chargesList.contains( new HouseDocumentCharges("621"))  )
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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