lundi 29 juin 2015

Java if condition for empty validations

I'm new to java and i want to do a condition check and return a message

PersonalDetails Request: It holds the value for all the below infos

getID();

getName();

getDesignation();

getHomeAddress();

getOfficeAddress();

getEmailID();

getMobile();

getHomePhone();

getOfficePhone();

i want to check all values for empty then return message.

Like "Your ID,Name, Mobile cannot be empty" if i pass empty values to ID, Name, Mobile

Below is the sample snippet which has to do the check for all PersonalDetails Request

public static String checkValue(PersonalDetails Request) {
    String str="Your ";
    if(request.getID().isEmpty())
    {
         str="ID,";
    }
    if(request.getName().isEmpty())
    {
     str="Name";
    }
if(request.getDesignation().isEmpty())
    {
     str="Designation";
    }
if(request.HomeAddress.isEmpty())
    {
     str="Address";
    }
   str+= "cannot be empty"

    return str;
}

Is this right or any other easy approach will address the issue

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire