This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Need help for refactoring this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Need help for refactoring this code" Watch "Need help for refactoring this code" New topic

Need help for refactoring this code

Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
CheckStyle is giving Cyclomatic Complexity value 11 for following method, while the maximum allowed is 10.

Is there any scope for Refactoring?

My blood is tested +ve for Java.
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
Why do you need default in this case?

-Varun -
(My Blog) - Online Certifications - Webner Solutions
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
Where does the number come from? Do you have to use a number or could you use a name? If so -- you might be able to use reflection instead.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Well, even with the number, you could use reflection:

... getClass().getDeclaredField("data" + check);

It would be even simpler if you could make data an array:

result = checkData(data[check]);

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
subject: Need help for refactoring this code
It's not a secret anymore!