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 9104667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:55:14+00:00 2026-06-17T01:55:14+00:00

In my java application I have a huge set of conditions which decides just

  • 0

In my java application I have a huge set of conditions which decides just one action. My question is how to make it look nice (I use NetBeans so I’d prefer solution that will not be broken by its code formatting function). I’d also like to have there as low amount of if/else statements as possible, because I think it will make it faster.

My original code was a mess, so I made an action diagram:complex action diagram full of conditions. Take a copy if you want to play with it. Please keep in mind that the diagram is not perfect as to UML syntax, partly because I made it using google docs.

This is the code:

if (!config.get("checkForSpecials") || event.isNotSpecial()) {
    if (config.get("filterMode").equals("blacklist")) {
        if (!itemFilter.contains(event.getItem().getName())) {
            item.process();
        }
    } else if (config.get("filterMode").equals("whitelist")) {
        if (itemFilter.contains(event.getItem().getName())) {
            item.process();
        }
    } else {
        item.process();
    }
}

There are two things I don’t like about it – the conditions are not too clear (especially when I unfold full method names and config strings), and the fact that the process method call is there three times.

  • 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-17T01:55:16+00:00Added an answer on June 17, 2026 at 1:55 am

    Factoring booleans out and caching return values from method calls can help clarify code.

    In addition, plotting all the outcomes on a logic table can help. I use this tool to help.

    With the linked tool:

    A: config.get("filterMode").equals("blacklist")
    B: config.get("filterMode").equals("whitelist")
    C: filterContainsName (see below)
    

    The tool churns out:

    (!A && !B) || (!A && C) || (A && !C)
    

    Which leads to the code below (with a small tweak that replaces (!A && C) with (B && C)):

    boolean filterContainsName = itemFilter.contains(event.getItem().getName());
    boolean useBlacklist       = config.get("filterMode").equals("blacklist");
    boolean useWhitelist       = config.get("filterMode").equals("whitelist");
    
    if (!config.get("safeMode") || event.isSafe()) {
        if((!useBlackList && !useWhiteList) ||
           ( useWhiteList &&  filterContainsName) ||
           ( useBlackList && !filterContainsName)) {
            item.process();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Java application which sends pointer to function (callback) to some native dll
For our Kunagi Java web application we have a signed kunagi.jar file which contains
I need to write a standalone Java application which will have a embedded HTTP
I would like to create extend a Java Swing application to have a look
I have a huge Java Application with numerous packages. Some of the classes in
We have a huge Java Swing application. Now we want to remove couplings from
I'm using eclipse juno IDE I have Java application which have src folder. within
So i have this huge java application running on a ubuntu server. How i
I have some deployment model question for a Java EE web application. Currently we
In my java web application, I have a single background-worker thread, which requires a

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.