[jbosscache-dev] reworking CacheMarshaller200.marshallObject() to a switch statement?

Galder Zamarreno galder.zamarreno at jboss.com
Fri Feb 2 10:54:38 EST 2007


Looking at CacheMarshaller200.marshallObject, we seem to have quite a big if chain. For BETA2, I was thinking that we could create a static Map<Class, int> containing class names and magic numbers, similar to the work we did for MethodDeclarations.

public static final Map COLLECTIONS = new HashMap();

static
{
  COLLECTIONS.put(ArrayList.class, MAGICNUMBER_ARRAY_LIST);
}

...

int i = COLLECTIONS.get(o.getClass());
switch(i)
{
  Case MAGICNUMBER_ARRAY_LIST: ...
}

Also, the instanceof if statements could be translated into this, specially bearing in mind that when we unmarshall, we create new instances of the class we compared for in the instanceof statement, so we would be back to the problem we had with the customer collections.

Galder Zamarreño
Sr. Software Maintenance Engineer
JBoss, a division of Red Hat






More information about the jbosscache-dev mailing list