Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:38:08+00:00 2026-06-12T05:38:08+00:00

i am working on a large application which has differnt conditions(ifs) and different methods

  • 0

i am working on a large application which has differnt conditions(ifs) and different methods associated with it.Please suggest a way to optimize below mentioned code(reduce as much of nested ifs as possible).I would like the code to able incorporate any other specific condition with ease.(I use property files to fetch conditions)
.

 public getParameter(String parameter)
    {
      if(parameter=specific condition1
        ||parameter=specific condition2)
      {
      do this
      }
      if(parameter=specific condition3)
      {
       do something else
      }
      if(parameter=specific condition4)
      {
       do something else
      }
      if(parameter=general condition)
      {
       do something else
      }
      else  {
       do something else
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:38:09+00:00Added an answer on June 12, 2026 at 5:38 am

    Say you have a property file with

    do1=val1,val2,val3
    do2=val5,val6,val7
    

    (it seems you have a fixed set of actions)

    You may load it with

        HashMap<String, HashSet<String>> rules = new HashMap<String, HashSet<String>>();
        for(String key : properties.stringPropertyNames()) {
            HashSet<String> set = new HashSet<String>();
            set.addAll(Arrays.asList(properties.getProperty(key).split(",")));
            rules.put(key, set);
        }
    

    Now you have a map linking action names (“do1”, etc.) to sets of possible values (“val1”, etc.).

    You may execute the rules with

        if (rules.get("do1").contains(parameter)) do1();
        if (rules.get("do2").contains(parameter)) do2();
    

    (I let you add the necessary checks to avoid null pointer exceptions for example)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an application which has large amount of data in a
I'm working on an Spring application which has a large number of beans -
I am working on an application which has a large array containing lines of
I'm currently working on my first deployment of a large server side application which
I am working on Alarm application in which I want to set Large Sound
I'm currently working on a large and old C++ application that has had many
I'm working on a large legacy application using stateless session beans that has recently
I am currently working on one android application which has C2DM implementation and I
I am working on a very large application that has multiple processes running simultaneously;
I've noticed that the native C++ application I'm working on has quite a large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.