• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help for refactoring this code

 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CheckStyle is giving Cyclomatic Complexity value 11 for following method, while the maximum allowed is 10.

Is there any scope for Refactoring?


 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need default in this case?
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic