@SuppressWarnings("unchecked") protected <T> T castDouble(Class<T> t, Double z) {
    if (t == Long.class || t == long.class) return (T) new Long(z.longValue());
    if (t == Boolean.class || t == boolean.class) return (T) new Boolean(z == 1);
    if (t == Double.class || t == double.class) return (T) z;
    if (t == Integer.class || t == int.class) return (T) new Integer(z.intValue());
    throw new CastException("Double => " + t);
  }