1 2 Previous Next 19 Replies Latest reply: Dec 13, 2012 3:18 AM by TPD-Opitz Go to original post RSS
      • 15. Re: how to optimize this code + is design proper
        TPD-Opitz
        Vicky wrote:
        Thanks TPD
        But a full fleged code might have been better to understand.
        Shortly I was blamed for posting code, but that was in another thread...
        So here is what I mean:
        public class Links{
             public static final Filter<Links> UNFILTERED= new Filter<Links>() {
                 public boolean accept(Links aLink) { return true;}
             };
             private Filter<Links> currentFilter = UNFILTERED;
             private String nodeName;
             private List<Links> children;
        
             public void setFilter( Filter<Links> newFilter){
                        assert(null!=newFilter);
                  this.currentFilter=newFilter;
             }
        
             public List<Links> getChildren(){
                        List<Links> filteredLinks = new ArrayList<>();
                  for (Links currentLink : children) {
                     if(this.currentFilter.accept(currentLink) {
                                currentLink.setFilter(this.currentFilter);
                                filteredLinks.add(currentLink);
                     }
                  }
                  return filteredLinks;
             }
        // more methods ...
        }
        I for myself also like my setter methods to return this
         public Links setFilter( Filter<Links> newFilter){
                        assert(null!=newFilter);
                  this.currentFilter=newFilter;
                        return this;
             }
        so I can write
        filteredLinks.add(currentLink.setFilter(this.currentFilter)); 
        You may be concerned about creating to many instances of <tt>ArrayList</tt> but they live for a verry short time and the GC is optimized for handling of short living objects. Also generally you should avoid returning a reference to a mutable member by any chance because this turnes the member into a global variable, which is not a good idea.

        bye
        TPD
        • 16. Re: how to optimize this code + is design proper
          814889
          Thanks TPD


          May be i am asking to much but i wont be able to understand until i am able to run the code , the code was insufficient to run so if you dont mind can you post full code which i can run i will fill data myself.
          • 17. Re: how to optimize this code + is design proper
            814889
            still some doubts left
            • 18. Re: how to optimize this code + is design proper
              TPD-Opitz
              hello Vicky,

              I'm willing to explain concepts even by posting code, but you should be able to use basic computer handlig concepts like copy and paste and basic programming concepts like how to call a method and how to pass parameters already.
              I will not do that part for you.

              But if you post what you made from the input given here I may take time to comment that...

              bye
              TPD
              • 19. Re: how to optimize this code + is design proper
                TPD-Opitz
                Vicky wrote:
                still some doubts left
                which are?

                bye
                TPD
                1 2 Previous Next