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 Object checkTypeAndNotNull(String field, Map data, Class expect)
      throws GeneralException {

    Object o = data.get(field);

    if (o == null) {

      throw new GeneralException("Expected a value for: " + field);
    }

    if (expect != null) {

      if (!expect.isAssignableFrom(o.getClass())) {

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

    return o;
  }
Exemplo n.º 3
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());
  }