public static boolean bool(Object value) { return Cls.convert(value, Boolean.class); }
public static Date date(Object value) { return Cls.convert(value, Date.class); }
public static String str(Object value) { return Cls.convert(value, String.class); }
@SuppressWarnings("unchecked") private <T> T withDefault(Object value, T defaultValue) { if (value != null) { return (T) (defaultValue != null ? Cls.convert(value, Cls.of(defaultValue)) : value); } else { return defaultValue; } }
public static boolean bool(Object value) { return U.or(convert(value, Boolean.class), false); }
@Override protected T retrieve() { return Cls.convert(src.getOrNull(), type); }
public static <T> T getPropValueOfType(Object obj, String property, Class<T> returnType, T defaultValue) { Object id = getPropValue(obj, property, null); return id != null ? Cls.convert(id, returnType) : defaultValue; }
@Override public String id() { return Cls.convert(Beany.getIdIfExists(value), String.class); }
@Override public Object getParamValue(Req req) { Object value = type.isPrimitive() ? req.header(name) : req.header(name, null); return Cls.convert(value, type); }
@Override public Object getParamValue(Req req) { Object value = required || type.isPrimitive() ? req.data(name) : req.data(name, null); return Cls.convert(value, type); }
@Override public synchronized boolean is(String key) { makeSureIsInitialized(); Object value = get(key); try { return Boolean.TRUE.equals(Cls.convert(value, Boolean.class)); } catch (Exception e) { return false; } }
@Override @SuppressWarnings("unchecked") public <K> K or(K alternative) { U.notNull(alternative, "alternative"); T value = getOrNull(); return value != null ? (K) Cls.convert(value, alternative.getClass()) : alternative; }
@Override public Object getParamValue(Req req) { Object value = type.isPrimitive() ? req.cookie(name) : req.cookie(name, null); return Cls.convert(value, type); }
protected int pageNumber() { Integer pageNum = Cls.convert(req().params().get(param), Integer.class); int value = U.or(pageNum, initial, min, 1); if (min != null) { value = Math.max(min, value); } if (max != null) { value = Math.min(max, value); } return value; }
private <T> T provideSessionValue(Object target, Class<T> type, String name, Mapper<String, Object> session) { U.notNull(session, "session"); Object value = Lmbd.eval(session, name); return value != null ? Cls.convert(value, type) : null; }
private <T> T provideBindValue(Object target, Class<T> type, String name, Mapper<String, Object> bindings) { U.notNull(bindings, "bindings"); Object value = Lmbd.eval(bindings, name); return value != null ? Cls.convert(value, type) : null; }
@Override public void doSet(T value) { if (!readOnly) { T oldValue = get(); if (oldValue != null) { item.set(property, Cls.convert(value, oldValue.getClass())); } else { item.set(property, value); } } }
public static ReqRespHandler read(final Class<?> entityType) { return (ReqRespHandler) (req, resp) -> { Object id = Cls.convert(req.param("id"), idType(entityType)); return JPA.get(entityType, id); }; }
public static ReqRespHandler delete(final Class<?> entityType) { return (ReqRespHandler) (req, resp) -> { Object id = Cls.convert(req.param("id"), idType(entityType)); JPA.delete(entityType, id); return OK; }; }
public static ReqRespHandler update(final Class<?> entityType) { return (ReqRespHandler) (req, resp) -> { Object id = Cls.convert(req.param("id"), idType(entityType)); JPA.get(entityType, id); // make sure it exists JPA.merge(req.data(entityType)); // FIXME improve the merge return OK; }; }