File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
I agree. Here's the link:
subject: Need help for refactoring this code
It's not a secret anymore!