Harald said:
Guess yourself which one is faster on the average and then
dismiss performance considerations and first go
for a clean, easy to maintain design when choosing the key
type.
Harald Kirsch
This was my sense. After I poplulate the HashMap in one class, other
classes will need to access its elements. I figure a String will
provide a good, easy to understand abstraction for each element. In my
case I have a set of rules. So I'd make my key something like "X Factor
Rule" or "Y Factor Rule", where "X Factor" and "Y Factor" are
recognizable names from our domain.
How about combining performance and readability by making a "Key" class
that contains static final int fields. Something like this:
class HashKeys
{
HashKeys ( ) { }
protected static final int X_FACTOR_RULE = 1;
protected static final int Y_FACTOR_RULE = 2;
}
Then, for example, I can just use HashKeys.X_FACTOR_RULE as a key value.
Alternatively, I can take the Interger approach.
class HashKeys
{
HashKeys( )
{
this.X_FACTOR_RULE = new Integer(1);
this.Y_FACTOR_RULE = new Integer(2);
}
protected Integer X_FACTOR_RULE;
protected Integer Y_FACTOR_RULE;
}
In that case, I'd make HashKeys a Singleton.
Note that I use protected since the Hash Table will be used only by
classes in the same package as itself. Do either of these approaches
seem reasonable? One better than the other? Other suggestions? I'm
inclined to go with the first approach because it seems less complex,
but I don't know if there's any catch I'm missing.
Thanks again for any recommendations!
Ken