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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:16:46+00:00 2026-06-12T17:16:46+00:00

I am wondering how to reduce the Cyclomatic Complexity of the following code and

  • 0

I am wondering how to reduce the Cyclomatic Complexity of the following code and if this is even something that I should be worried about.

Please refer to the method ValuePojo.getSomething()
(Please don’t worry about the variable naming, this has been re-written for clarity in this question)

public class ValuePojo
{
    private ValueTypeEnum type;

    private BigDecimal    value1;

    private BigDecimal    value2;

    private BigDecimal    value3;

    public ValuePojo()
    {
        super();
    }

    /**
     * This method reports as "HIGH Cyclomatic Complexity"
     * 
     * @return
     */
    public BigDecimal getSomething()
    {
        if (this.type == null)
        {
            return null;
        }

        switch (this.type)
        {
            case TYPE_A:
            case TYPE_B:
            case TYPE_C:
            case TYPE_D:
                return this.value1;

            case TYPE_E:
            case TYPE_F:
            case TYPE_G:
            case TYPE_H:
                return this.value2;

            case TYPE_I:
            case TYPE_J:
                return this.value3;
        }

        return null;
    }
}
  • 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-12T17:16:48+00:00Added an answer on June 12, 2026 at 5:16 pm

    The Cyclomatic Complexity is determined by the number of branches of execution in your code. if - else blocks, switch statements – all increase the Cyclomatic complexity of your code and also increase the number of test cases you would need to ensure appropriate code coverage.

    To reduce complexity in your code, I would suggest you remove the case statements that do not have a defined behavior and replace it with a default behavior in your switch statement.

    Here is another question on Stack Overflows that addresses this issue.

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

Sidebar

Related Questions

just wondering if there is a way to reduce the amount of code needed
I'm trying to reduce the code duplication that exists throughout my asp.net web forms.
Possible Duplicate: When should I make explicit use of the this pointer? I'm wondering
I'm just wondering how i could make this code more efficient. I feel like
Using this code to take a string and convert it to binary: bin(reduce(lambda x,
Working with MySQL lately, from PHP, I am wondering about this: What is the
I was wondering about the differences between Grep and Filter : Filter : Reduce
Wondering what the best / good way of doing this would be in jQuery.
Wondering if any of you can help me: I've made a signup modal that
Wondering if someone could please explain the difference between these two queries and advise

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.