C
cbongior
So, I have a situation where I have a set that has a listing of
"supported" class types (See below). The problem is that, I HAVE to
override the toString() method of the BigInteger in a subclass. Well,
By subclassing BigInteger the .getClass() method changes and thus, will
not lookup in this set.
class Class is final, so I can't override any of the methods (like
hashcode). method getClass() is final, so that's out. I can't use a
HashSet (cannot change the hash for Class) or a TreeSet (Class has no
natural ordering and my own Comparator would require me to devise an
arbitrary numerical value for each element -- the most obvious choice
for the compare being the hashCode -- putting me back to the HashSet
problem)
Current set and my idea below
----------begin current set----------------------
public static final Set SUPPORTED_TYPES = new HashSet();
static {
SUPPORTED_TYPES.add(Integer.TYPE);
SUPPORTED_TYPES.add(Long.TYPE);
SUPPORTED_TYPES.add(Short.TYPE);
SUPPORTED_TYPES.add(Byte.TYPE);
SUPPORTED_TYPES.add(Boolean.TYPE);
SUPPORTED_TYPES.add(Float.TYPE);
SUPPORTED_TYPES.add(Double.TYPE);
SUPPORTED_TYPES.add(Integer.class);
SUPPORTED_TYPES.add(Long.class);
SUPPORTED_TYPES.add(Short.class);
SUPPORTED_TYPES.add(Byte.class);
SUPPORTED_TYPES.add(Boolean.class);
SUPPORTED_TYPES.add(Float.class);
SUPPORTED_TYPES.add(Double.class);
SUPPORTED_TYPES.add(String.class);
SUPPORTED_TYPES.add(BigInteger.class);
SUPPORTED_TYPES.add(BigDecimal.class);
SUPPORTED_TYPES.add(Date.class);
}
----------end current set----------------------
I would like to somehow make use of hashing or binary searching for a
speed up. So, I was thinking of using an existing set and overidding
contains to be:
public boolean contains(Object o) {
boolean contains = false;
if(o != null) {
contains = super.contains(o);
if(contains == false)
contains = super.contains(o.getSuperClass());
}
return contains;
}
Clearly this would be slower, but not by much given the limited class
hierarchy and because the original set only contains 2 (for now)
extendable class types. Any thoughts on the subject?
Christian
http://christian.bongiorno.org/resume.pdf
"supported" class types (See below). The problem is that, I HAVE to
override the toString() method of the BigInteger in a subclass. Well,
By subclassing BigInteger the .getClass() method changes and thus, will
not lookup in this set.
class Class is final, so I can't override any of the methods (like
hashcode). method getClass() is final, so that's out. I can't use a
HashSet (cannot change the hash for Class) or a TreeSet (Class has no
natural ordering and my own Comparator would require me to devise an
arbitrary numerical value for each element -- the most obvious choice
for the compare being the hashCode -- putting me back to the HashSet
problem)
Current set and my idea below
----------begin current set----------------------
public static final Set SUPPORTED_TYPES = new HashSet();
static {
SUPPORTED_TYPES.add(Integer.TYPE);
SUPPORTED_TYPES.add(Long.TYPE);
SUPPORTED_TYPES.add(Short.TYPE);
SUPPORTED_TYPES.add(Byte.TYPE);
SUPPORTED_TYPES.add(Boolean.TYPE);
SUPPORTED_TYPES.add(Float.TYPE);
SUPPORTED_TYPES.add(Double.TYPE);
SUPPORTED_TYPES.add(Integer.class);
SUPPORTED_TYPES.add(Long.class);
SUPPORTED_TYPES.add(Short.class);
SUPPORTED_TYPES.add(Byte.class);
SUPPORTED_TYPES.add(Boolean.class);
SUPPORTED_TYPES.add(Float.class);
SUPPORTED_TYPES.add(Double.class);
SUPPORTED_TYPES.add(String.class);
SUPPORTED_TYPES.add(BigInteger.class);
SUPPORTED_TYPES.add(BigDecimal.class);
SUPPORTED_TYPES.add(Date.class);
}
----------end current set----------------------
I would like to somehow make use of hashing or binary searching for a
speed up. So, I was thinking of using an existing set and overidding
contains to be:
public boolean contains(Object o) {
boolean contains = false;
if(o != null) {
contains = super.contains(o);
if(contains == false)
contains = super.contains(o.getSuperClass());
}
return contains;
}
Clearly this would be slower, but not by much given the limited class
hierarchy and because the original set only contains 2 (for now)
extendable class types. Any thoughts on the subject?
Christian
http://christian.bongiorno.org/resume.pdf