kuujo / vertigo

Flow-based programming for the Vert.x application platform.
Apache License 2.0
155 stars 24 forks source link

Refactor FieldsSelector.select method #4

Closed andredasilvapinto closed 11 years ago

andredasilvapinto commented 11 years ago

For

        hash += value.hashCode();

when value.hashCode() < 0

    int index = Integer.valueOf(hash) % connections.size();

will yield a negative value and trigger a IndexOutOfBoundsException in the following line:

    return connections.subList(index, index+1);

Also, when we have multiple fieldNames we will probably get errors on Integer.valueOf(hash) as the string may not be a valid Integer. This can occur either by overflow (multiple positive hashs concatenated) or invalid numbers (imagine "1000000000" and "-1000000000" hashes).

Finally, if you are going to concatenate Strings on a loop, it's better to use a StringBuilder instead of the += operator. StringBuilder doesn't need to keep creating new String objects every time you append a new String to it.

kuujo commented 11 years ago

Right on all counts. Excellent!

^^ merged ^^

andredasilvapinto commented 11 years ago

Thanks