public (static) swap() method vs. redundant (non-static) private ones...

Posted by Helper Method on Stack Overflow See other posts from Stack Overflow or by Helper Method
Published on 2010-05-03T10:27:32Z Indexed on 2010/05/03 10:28 UTC
Read the original article Hit count: 166

Filed under:
|
|

I'm revisiting data structures and algorithms to refresh my knowledge and from time to time I stumble across this problem:

Often, several data structures do need to swap some elements on the underlying array. So I implement the swap() method in ADT1, ADT2 as a private non-static method. The good thing is, being a private method I don't need to check on the parameters, the bad thing is redundancy. But if I put the swap() method in a helper class as a public static method, I need to check the indices every time for validity, making the swap call very unefficient when many swaps are done.

So what should I do? Neglect the performance degragation, or write small but redundant code?

© Stack Overflow or respective owner

Related posts about java

Related posts about data-structures