Exemplo n.º 1
0
  public static boolean getBoolean(String field, Map data, boolean required)
      throws GeneralException {

    Object o = null;

    if (required) {

      o = TypeEncoder.checkTypeAndNotNull(field, data, Boolean.class);

    } else {

      o = data.get(field);

      if (o == null) {

        return false;
      }

      if (!Boolean.class.isAssignableFrom(o.getClass())) {

        throw new GeneralException(
            "Expected type for: "
                + field
                + " to be: "
                + Number.class.getName()
                + ", is: "
                + o.getClass().getName());
      }
    }

    return (Boolean) o;
  }
Exemplo n.º 2
0
  public static Date getDate(String field, Map data, boolean required) throws GeneralException {

    Object o = null;

    if (required) {

      o = TypeEncoder.checkTypeAndNotNull(field, data, Number.class);

    } else {

      o = data.get(field);

      if (o == null) {

        return null;
      }

      if (!Number.class.isAssignableFrom(o.getClass())) {

        throw new GeneralException(
            "Expected type for: "
                + field
                + " to be: "
                + Number.class.getName()
                + ", is: "
                + o.getClass().getName());
      }
    }

    return new Date(((Number) o).longValue());
  }