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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:46:33+00:00 2026-06-05T07:46:33+00:00

My Question is- I have two string variables site_inclusion and site_exclusion . If site_inclusion

  • 0

My Question is-

I have two string variables site_inclusion and site_exclusion. If site_inclusion has a value, then I don’t care what values site_exclusion contains. That is to say that site_inclusion overrides site_exclusion. If, however, site_inclusion is null and site_exclusion has a value, then I want to examine site_exclusion.

To be more precise:

  1. If site_inclusion and site_exclusion are both null then set useTheSynthesizer as true;
  2. If site_inclusion is not null and it matches with the regexPattern then set useTheSynthesizer as true. And I don’t care what values are there in site_exclusion.
  3. If site_inclusion is null and site_exclusion is not null and site_exclusion does not match the regexPattern then set useTheSynthesizer to true.

I wrote the below code but somehow I think, I am repeating some stuff here in the if/else loop. Any code improvements will be appreciated that fulfill my conditions.

String site_inclusion = metadata.getSiteInclusion();
String site_exclusion = metadata.getSiteExclusion();

// fix for redundant data per site issue
if(site_inclusion != null && site_inclusion.matches(regexPattern)) {
    useTheSynthesizer = true;
} else if(site_exclusion != null && !(site_exclusion.matches(regexPattern))) {
    useTheSynthesizer = true;
} else if(site_inclusion == null && site_exclusion == null ) {
    useTheSynthesizer = true;
}
  • 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-05T07:46:34+00:00Added an answer on June 5, 2026 at 7:46 am
    1. You don’t really need the last null test.
    2. I (personally) find it poor style to do an if(test == true) flag = true statement. You can simply say flag = test.

    My recommendation would be:

    if(site_inclusion != null)
    {
        useTheSynthesizer = site_inclusion.matches(regexPattern);
    }
    else if(site_exclusion != null)
    {
        useTheSynthesizer = ! site_exclusion.matches(regexPattern);
    }
    else
    {
        useTheSynthesizer = true;
    }
    

    You could also do it in a oneliner:

    useTheSynthesizer = site_inclusion != null ? site_inclusion.matches(regexPattern) : (site_exclusion != null ? ! site_exclusion.matches(regexPattern) : true);
    

    But I find that sort of obnoxious to read.

    (Note, I made the assumption that useTheSynthesizer was otherwise false. This isn’t explicit in your code or explanation, but I think this assumption was safe.)

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

Sidebar

Related Questions

I have a domain model that contains member variables for two languages, something like
Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew
I have a question: I have two MSSQL tables, items and states, that are
A quick technical question- I have two queries that output some of the same
I have a class Message that has a std::string as a data member, defined
If I have two static variables in different compilation units, then their initialization order
I have a text file... HELLO GOODBYE FAREWELL .. and two string variables, requested
I have a text file that contains date, and two time-strings separated by spaces
really a simple question , I have two Variables one_hour_ago and current_time, I need
I have a Sport base class that has a couple variables. I also have

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.