One of the long-tenured developers, Douglas at Patrick's company left, which meant Patrick was called upon to pick up that share of the work. The code left behind by Douglas the departing developer was, well… code.

For example, this block of Java:

private String[] getDomainId(Collection<ParticularCaseEntity> particularCase) {
       
    // Get all domainId
    Collection<String> ids = new ArrayList<String>();
    for (ParticularCaseEntity case : particularCase) {
        ids.add(case.getDomainId());
    }

    Set<String> domainIdsWithoutRepeat = new HashSet<String>();
    domainIdsWithoutRepeat.addAll(ids);

    Collection<String> domainIds = new ArrayList<String>();
    for (String domainId : domainIdsWithoutRepeat) {
        domainIds.add(domainId);
    }
    return domainIds.toArray(new String[0]);       
}

The purpose of this code is to get a set of "domain IDs"- a set, specifically, because we want them without duplicates. And this code takes the long way around to do it.

First, it returns a String[]- but logically, what it should return is a set. Maybe it's meant to comply with an external interface, but it's a private method- so I actually think this developer just didn't understand collection types at all.

And I have more evidence for that, which is the rest of this code.

We iterate across our ParticularCaseEntitys, and add each one to an array list. Then we create a hash set, and add all of those to a hash set. Then we create another array list, and add each entry in the set to the array list. Then we convert that array list into an array so we can return it.

At most, we really only needed the HashSet. But this gives us a nice tour of all the wrong data structures to use for this problem, which is helpful.

Speaking of helpful, it didn't take long for Patrick's employer to realize that having Patrick doing his job, and also picking up the work that Douglas used to do was bad. So they opened a new position, at a higher pay grade, hoping to induce a more senior developer to step in. And wouldn't you know, after 6 months, they found a perfect candidate, who had just finished a short six month stint at one of their competitors: Douglas!

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!