You Want A Hash In That Vector?

I came across a few methods down in our database code yesterday:

    /**
     * Transforms into a hash of Hashtables
     * @return String   - is a string representation of this object
     */
    public HashMap toHashofHashes() {
    .....

    /**
     * Transforms into a Hash (groupBy) of vectors of Hashtables (rows)
     * The groupBy parameter is the column value to group by.  This group by value will
     * be the key of the top level hash rows are represented as hashes in a vector
     * (representing zero to many rows for a group by value)
     * @return String   - is a string representation of this object
     */
    public HashMap toHashOfVectorsOfHashes(String groupBy) {
    .....

    /**
     * Transforms into a vector of Hashtables
     * @return String   - is a string representation of this object
     */
    public Vector toVectorofHashes() {
    .....

The classes haven’t been touched since 2006 (and even then the change was to logging), and were filled with raw type warnings due to the unparameterized vectors and hashmaps (and a whole slew of other warnings that never got cleaned up in the conversions from Java 4 to 5 to 6 to 7).

I took a crack at cleaning it up and got:

    public HashMap<String,HashMap<String,String>> toHashofHashes() {
    .....

    public HashMap<String,Vector<HashMap<String,String>>> toHashOfVectorsOfHashes(String groupBy) {
    .....

    public Vector<HashMap<String,String>> toVectorofHashes() {
    .....

Not exacltly pretty.

Next step will be to figure out why these things are even used and hopefully refactor the calling code, as I’m not sure helper functions to make a “hash of vectors of hashes” indicates a good design.

Comments