SlowerBuffer

Programming and Technology Related Stuff

You Want a Hash in That Vector?

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    /**
     * 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:

1
2
3
4
5
6
7
8
    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 when and why these things are even used and hopefully update the documentation, which is clearly lacking, as well as wrong (return type is clearly not ‘String’). Better yet, maybe I can just remove these hideous things altogether!

Comments