Results 1 to 6 of 6
Thread: Replacing Else If
- 12-28-2009, 04:54 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
Replacing Else If
I am looking for a way to replace ELSE if condition. for example I have:
if (this.test.equals("A")) {
this.test= "B";
this.service = "B2";
return true;
}
else if (this.test.equals("B")) {
this.carrierServiceLevel = "C";
this.service = "C2";
return true;
}
Just like above we have like 10 else if.. all of that is in sequence. So if A fails, than B, else C, else D,, etc.
How can I replace this else if using some different way. I want to store this a, b c, values in DB so in future I can easily change the value in DB than hardcoding in Java..
Please let me know how can I replace this else if...
Thanks
- 12-28-2009, 05:24 PM #2
You can code your static values as enumerations (enums) and use the switch statement if you want ;-)
"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 12-28-2009, 09:11 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
I dont want static values, i want it to be dynamic, I want to store it in db and then remove the else if logic..
- 12-28-2009, 09:18 PM #4
Can you provide some example scenario?
If I get you right, then you can store in your db a value of the classname and then load it via the classloader. But it all depends. For me a more precise description of your problem would be great."There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
- 12-28-2009, 10:06 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
Currently, what we do is,...
Default value selected is A, then application runs some logic, if it return "FAILURE", we want user to select next value B, again if it returns "FAILURE" , select C,
Currently we are doing this by
if(this.test.equals("A"){
this.test = "B"
return true;
}
else if(this.test.equals("B"){
this.test = "C"
return true;
}
we do this from A-F... we are using this else if to check what user has selected based on that we assign this.test to next value....
Now their is a change in values.. all the values will be for example.. instead of A it will AA, B it will be BB..
so what we decided is to store this value AA, BB , in Database, assing some sequence like AA is 1, BB is 2,, then read this table, and assign this.test to whatever the next value should be , by replacing if else and hardcoded values in that....
i hope it makes sense...
- 12-28-2009, 11:06 PM #6
Hm, maybe you can write a value class that defines a succesfunction.
And provide a method to check whether the value is valid.
The calling method would look like thisJava Code:public class Value { // provide logic for the value, like the real value and additional information public Value getSuccessor() { Value currentValue = this; // determine the next value given the "this" val (via DB?) ... } }
does this help?Java Code:// if failure if (!doTestValue(test.currentValue)) { test.currentValue = currentValue.getSuccessor(); } return true;"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
Similar Threads
-
Replacing char in string help
By jimmy-lin in forum New To JavaReplies: 3Last Post: 10-12-2009, 06:01 AM -
Replacing Vowels in a word.
By mklprasad in forum Advanced JavaReplies: 1Last Post: 10-05-2009, 12:31 PM -
Help Replacing String
By 7oclock in forum New To JavaReplies: 5Last Post: 02-14-2009, 07:31 AM -
replacing characters???
By manda147 in forum New To JavaReplies: 2Last Post: 11-29-2008, 08:19 AM -
Replacing at an index
By bugger in forum New To JavaReplies: 2Last Post: 01-29-2008, 06:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks