This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Alternative to SWITCH statement

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys!

the application that i am currently working on has a new "variable" to be added (so to speak) that requires me to relate it another existing variable, but the problem lies in the fact that the new variable will a different value for every different value of the existing variable and the existing variable has 400+ (!) different values. is there any alternative way to handle this other than create an obscenely long SWITCH statement?

thanks...
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure there are better ways.... could you give a better description on what type of variable you are comparing and what some of the possible values are? There are different methods depending on if your comparing a primitive, a String, or some custom object.
 
Sheriff
Posts: 21774
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kansh TR",

Please read your private messages regarding an important announcement.

Thank you,

Rob
 
Kansh Sahasrabuddhe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Brian Legg wrote:Sure there are better ways.... could you give a better description on what type of variable you are comparing and what some of the possible values are? There are different methods depending on if your comparing a primitive, a String, or some custom object.



hey Brian:

the reference variable is called "branch" which is an int type and the variable "old" has different values for each value of "branch". now the user has implemented a new standard and therefore the application has to be updated with the variable "new" for future use, but at the same time the all the values of "old" have to be transferred to "new" according 400+ different values of "branch" as there is no equation to convert "old" to "new".

old and new are both float type.

thanks
 
Marshal
Posts: 65005
246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like something for a Map. If old1|->new1 and old2|->new2 etc, that suggests a Map<Old, New> might be useful.
I am sure you know about Maps but here is the API link.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Campbell if I understand the problem correctly. Just throw em all in a Map and then pull out the "new" values based on the "old" key.
 
Kansh Sahasrabuddhe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Sounds like something for a Map. If old1|->new1 and old2|->new2 etc, that suggests a Map<Old, New> might be useful.
I am sure you know about Maps but here is the API link.



Brian Legg wrote:I agree with Campbell if I understand the problem correctly. Just throw em all in a Map and then pull out the "new" values based on the "old" key.



i think according to what you suggest, it should be Map<branch, difference> would be helpful, because there is no way to know the new values based on the old one. i only know the difference between old and new based on "branch"

thanks

 
Campbell Ritchie
Marshal
Posts: 65005
246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have some way to work out the "new" values from the "old" values, you might be able to put some sort of algorithm in which makes a Map redundant.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!