Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Refactor Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Refactor Question" Watch "Refactor Question" New topic
Author

Refactor Question

Cata Alex
Greenhorn

Joined: Nov 03, 2012
Posts: 1
Hi!
Can anyone help me redesign this part of code or give me some tips? I want it to work the same but to be much easier to read.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Welcome to the Ranch

How do you ensure that method is called only once? Are you recording when it is called? Are you throwing an Exception if it is called twice?
Why are you not using the clone() method of the array passed? Why not add the array elements to a List, ignoring nulls?
You ought to declare those loop variables in the loop header.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Cata Alex wrote:Can anyone help me redesign this part of code or give me some tips? I want it to work the same but to be much easier to read.

Well the best piece of advice I can give you is to use Lists (java.util.List) instead of arrays. You're writing a lot of code to do things (eg, replace null requirements by empty requirements) that is done automatically by a List class (eg, ArrayList).

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Refactor Question
 
Similar Threads
How to configure Bonecp in java project without breaking connection when more than connection
Doubt about StringTokenizer !!
I take null point exception
why am i getting this error?
String find and replace