/** @deprecated use {@link ConversionUtils#convert(Object, Class)} */ @Deprecated public static <T> T convert(final Object value, final Class<T> type) { return ConversionUtils.convert(value, type); }
/** @deprecated use {@link ConversionUtils#convert(Object, Class)} */ @Deprecated public static <T> T convert(final Object value, final Class<T> type) { return ConversionUtils.convert(value, type); }
/** * Converts the given object to a {@link Number} of the specified type, or * null if the types are incompatible. */ public static Number toNumber(final Object value, final Class<?> type) { final Object num = ConversionUtils.convert(value, type); return num == null ? null : Types.cast(num, Number.class); }
/** * Converts the given object to a {@link Number} of the specified type, or * null if the types are incompatible. */ public static Number toNumber(final Object value, final Class<?> type) { final Object num = ConversionUtils.convert(value, type); return num == null ? null : Types.cast(num, Number.class); }
private <D> D tValue(final String value, final Class<D> type) { if (value == null || value.isEmpty()) return null; final Class<D> saneType = Types.box(type); return ConversionUtils.convert(value, saneType); }
private <D> D tValue(final String value, final Class<D> type) { if (value == null || value.isEmpty()) return null; final Class<D> saneType = Types.box(type); return ConversionUtils.convert(value, saneType); }
/** * Sets the given field's value of the specified object instance. * * @throws IllegalArgumentException if the value cannot be set. */ // FIXME: Move to ConvertService and deprecate this signature. public static void setValue(final Field field, final Object instance, final Object value) { try { field.setAccessible(true); final Object compatibleValue; if (value == null || field.getType().isInstance(value)) { // the given value is compatible with the field compatibleValue = value; } else { // the given value needs to be converted to a compatible type final Type fieldType = Types.fieldType(field, instance.getClass()); @SuppressWarnings("deprecation") final Object convertedValue = ConversionUtils.convert(value, fieldType); compatibleValue = convertedValue; } field.set(instance, compatibleValue); } catch (final IllegalAccessException e) { throw new IllegalArgumentException("No access to field: " + field.getName(), e); } }
/** * Sets the given field's value of the specified object instance. * * @throws IllegalArgumentException if the value cannot be set. */ // FIXME: Move to ConvertService and deprecate this signature. public static void setValue(final Field field, final Object instance, final Object value) { try { field.setAccessible(true); final Object compatibleValue; if (value == null || field.getType().isInstance(value)) { // the given value is compatible with the field compatibleValue = value; } else { // the given value needs to be converted to a compatible type final Type fieldType = Types.fieldType(field, instance.getClass()); @SuppressWarnings("deprecation") final Object convertedValue = ConversionUtils.convert(value, fieldType); compatibleValue = convertedValue; } field.set(instance, compatibleValue); } catch (final IllegalAccessException e) { throw new IllegalArgumentException("No access to field: " + field.getName(), e); } }
/** * Returns the persisted value of a ModuleItem. Returns null if nothing has * been persisted. It is the API user's responsibility to check the return * value for null. */ @Override @Deprecated public T loadValue() { // if there is nothing to load from persistence return nothing if (!isPersisted()) return null; final String sValue; final String persistKey = getPersistKey(); if (persistKey == null || persistKey.isEmpty()) { final Class<?> prefClass = getDelegateClass(); final String prefKey = getName(); sValue = Prefs.get(prefClass, prefKey); } else sValue = Prefs.get(persistKey); // if persisted value has never been set before return null if (sValue == null) return null; return ConversionUtils.convert(sValue, getType()); }
/** * Returns the persisted value of a ModuleItem. Returns null if nothing has * been persisted. It is the API user's responsibility to check the return * value for null. */ @Override @Deprecated public T loadValue() { // if there is nothing to load from persistence return nothing if (!isPersisted()) return null; final String sValue; final String persistKey = getPersistKey(); if (persistKey == null || persistKey.isEmpty()) { final Class<?> prefClass = getDelegateClass(); final String prefKey = getName(); sValue = Prefs.get(prefClass, prefKey); } else sValue = Prefs.get(persistKey); // if persisted value has never been set before return null if (sValue == null) return null; return ConversionUtils.convert(sValue, getType()); }