[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

how to do validation part in java , i have 5 fields i need verify validation for all these 5 fields

Hi here i have total 5 fields,all these are not mandatory fields
From UI end i am selecting these values clicking on submit button.
i can select any of the field and inserting into DB,once the value inserted in DB,It should not accept the value again.
The below are the fields:
1.state
2.pid
3.kst
4.DM
5.ped

now from the application i am selecting the state value and clicking submit button
here i am checking the condition

if(state!=null and pid==null and kst==null and DM==null and ped==nul){
	 if{
	//here i am checking these values are already there in DB or not
	//if values are not there in DB then i am inserting these values into respective table.
	}
}else if(...)
{
}

Open in new window

like this i need to check all the scenarios
i have  total 5 fields
here i am seeing total 16 scenarios how can i check all the possible scenarios
i can use else if conditions upto all 16 scenarios but is there any logic to use all the scenarios in short form
0
srikotesh
Asked:
srikotesh
  • 6
  • 4
  • 3
  • +1
1 Solution
 
CEHJCommented:
here i am seeing total 16 scenarios how can i check all the possible scenarios
Why do you need to?

Please also post the table definition
0
 
zzynxSoftware engineerCommented:
It seems to me that whatever the combination is you can do the same check:
check if a record having the given values for state, pid, kst, DM and ped is already in the table.
Or do I understand this wrong?
0
 
srikoteshAuthor Commented:
i am  doing the same but i need to keep more else if blocks

For this i did one alternative

if(condition 1 || condition2 || condition3 || condition 4){	
	//here i am checking db validation as well (conditon1 ||conditon2 ||condition3 ||condition4)
}else if( condition5 || condition6 || condition 7 || condition 8){	
	//here i am checking db validation as well (conditon4 ||conditon5 ||condition6 ||condition7 ||condition 8)
}

Open in new window


by using or condition i cut down many else if blocks
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
With that pseudo-code, it's very difficult to tell whether that's valid or even necessary. Generally what are these conditions?
0
 
zzynxSoftware engineerCommented:
Indeed some more specifics would help a lot. The more specific you are the better we can help you.
eg. in your code

if(state!=null and pid==null and kst==null and DM==null and ped==nul){
	 if{
	//here i am checking these values are already there in DB or not
	//if values are not there in DB then i am inserting these values into respective table.
	}
}

Open in new window


what does "checking these values are already in DB or not" mean.
Do you check if "a record with state = the given state and the 4 other fields = null" exists or what?
0
 
srikoteshAuthor Commented:
in the earlier post i have gave the scenario
let suppose condition1 means
if((state!=null and pid==null and kst==null and DM==null and ped==nul)||(state!=null and pid!=null and kst==null and DM==null and ped==null){
            //if(condition1)or (condition2)
            let suppose from ui screen i entered only state and rest of the fields are null
            at that time condition1 vl satisfy and it vl go inside
            and one more scenario ivl give the value like state and pid that second condition vl satisfy
0
 
zzynxSoftware engineerCommented:
I understand very well that if you enter only state in the UI that the condition1 is true.
And that if you enter state and pid then the condition2 is true. (after all, I can read java code ;-)
And I understand that you don't want to write 16 if statements to cover all possible scenarios.
But to know if you can group some of the 16 conditions together, I try to understand what is inside those if statements
If I don't know that, I can't help. Sorry.
In other words: please explain as detailed as possible what this does:
>>      //here i am checking these values are already there in DB or not
>>      //if values are not there in DB then i am inserting these values into respective table.


Also, you still didn't answer CEHJ's question:
>> Please also post the table definition

Kind advise:
If you want us to help you, please answer our questions, or tell us why you (think) that's an irrelevant question.
But don't just neglect them or experts will do the same with your question.
0
 
srikoteshAuthor Commented:
Hi CEHJ,

These all 5 fields not in the same table
it is the combination of 3 tables
i am using the query and with these 3 table and fecthing the values

it is not possible for me to provide complete table information
0
 
srikoteshAuthor Commented:
i completed this task by placing or(||).
0
 
CEHJCommented:
You'd have probably simplified the code (and readability) by using EnumSet
0
 
srikoteshAuthor Commented:
HI CEHJ,
could u plz explore how to use Enumset
0
 
CEHJCommented:
It's difficult to tell you exactly, since you've not been providing enough information, but the basic idea is that you'd create a Set mirroring which fields have been filled in and then compare that Set for equality with others that you're interested in, e.g.

EnumSet<FieldOpts> stateAndPid = EnumSet<FieldOpts>.of(FieldOpts.Pid, FieldOpts.State);
if(enteredSet.equals(stateAndPid)) {
  // Do state and pid entered
}

Open in new window

0
 
srikoteshAuthor Commented:
Thanks :) i will try to implement this
0
 
GaryCommented:
I've requested that this question be closed as follows:

Accepted answer: 500 points for CEHJ's comment #a40285344

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Independent Software Vendors: 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!

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