P
Paul Tomblin
I have these objects that I want to put into a hash, and then be able to
pull them out based on either of two criteria, both Strings. So what I've
done is to make a Key class that has both of the Strings in it, and the
"equals" method on the Key class will return true if one String is
non-null and equals the one in the other Key, or if the other String is
non-null and equals the one in the other Key.
Is that sufficient, or should I make the Key implement Comparable or
something?
/**
* Key allows the object in the cache to be searched for by UUID *or*
* by fileName.
*/
private class Key
{
String fileName;
String UUID;
public boolean equals(Object obj)
{
if (obj instanceof Key)
{
Key otherKey = (Key)obj;
if (UUID != null && otherKey.UUID != null)
{
return UUID.equals(otherKey.UUID);
}
if (fileName != null && otherKey.fileName != null)
{
return fileName.equals(otherKey.fileName);
}
}
return false;
}
}
pull them out based on either of two criteria, both Strings. So what I've
done is to make a Key class that has both of the Strings in it, and the
"equals" method on the Key class will return true if one String is
non-null and equals the one in the other Key, or if the other String is
non-null and equals the one in the other Key.
Is that sufficient, or should I make the Key implement Comparable or
something?
/**
* Key allows the object in the cache to be searched for by UUID *or*
* by fileName.
*/
private class Key
{
String fileName;
String UUID;
public boolean equals(Object obj)
{
if (obj instanceof Key)
{
Key otherKey = (Key)obj;
if (UUID != null && otherKey.UUID != null)
{
return UUID.equals(otherKey.UUID);
}
if (fileName != null && otherKey.fileName != null)
{
return fileName.equals(otherKey.fileName);
}
}
return false;
}
}