• (nodebb)

    [pre]private static boolean existsFirstPost(ArrayList<Integer> postFolder, Integer postId) { for (Integer post : postFolder) { if (post.equals(postId)) return true; } return false; } [/pre]

  • (nodebb)

    The developer had family issues - daddy wasn't around.

  • (nodebb)

    Paul writes: "I guess the last developer didn't know that every implementation of a java.util.Collection has a method called contains. At least they knew how to do a for-each.".

    Yeah, of course he didn't know, because clearly no collections library ever has methods like C++'s std::map<...>::find(...).

    Or maybe that's the problem. He looked for a method called find, but couldn't ... er ... find ... it.

  • Industrial Automation Engineer (unregistered)

    this some implementation of a hierarchical(?) structure, which determines if an element is contained in an (arbitrary) object called father-folder?

  • (nodebb)

    A static method for this, and a list of fathers, not children, really reeks of whatever design they have being utterly harebrained.

    I'd almost like to see the whole tree-handling code, even though I know I'd lose IQ points by having seen it.

  • (nodebb)

    Perhaps it's a graph rather than a tree, which would explain why a node can have several fathers.

  • Ex-Java dev (unregistered)

    I'm guessing it's a list of all parents going up the tree, so it's just a single path up the tree, rather than the full tree. The integers would be IDs. Why? From where? I can't answer that.

    Answers, much like the code writer's father, left for milk a long time ago.

  • (nodebb)

    As a father of 2, I sometimes wonder if I'm who I think I am. Maybe I could use this function in my life? Or maybe this is a test for the old song "I'm My Own Grandpa"?

  • (nodebb)

    Never trust the framework! Always reimplement basic functions like that, it's the only way to trust your code!

    NIH rocks.

    PS: such a short method obviously is perfect and doesn't need unit tests. It's so simple, there's no way it could fail. Unit tests are for weaklings who write bugs anyway.

  • my name (unregistered)

    errm, to the best of my knowledge there's no Java builtin for trees, either you use TreeItem (from JavaFx, watch out for memory leaks) or make your own tree data structure, perhaps there is some library around, don't know, long speech cut short, use a parent member in your data structure

  • SG (unregistered) in reply to my name

    You're correct — Java has collection classes backed by B-tree structures (TreeMap, TreeSet), but there's no general-purpose implementation hierarchical data structure... probably because such things tend to be more specialised use cases where an out-of-the-box option probably won't make anybody happy.

  • (nodebb)

    the code clearly implies some sort of tree structure

    Facts not in evidence. I don't see any evidence from that code of any kind of tree structure.

  • Steve (not that one) (unregistered)

    "existsFather(ArrayList<Integer> fatherFolder, Integer fatherId)"? Sexist pig.

  • (nodebb)

    C# is now killing Java development

Leave a comment on “Contains Bad Choices”

Log In or post as a guest

Replying to comment #:

« Return to Article