• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Refactor Question

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic