/** * @return Get a float when possible. */ default float floatValue() { return to(float.class); }
/** * @return Get a double when possible. */ default double doubleValue() { return to(double.class); }
/** * @return Get a byte when possible. */ default byte byteValue() { return to(byte.class); }
/** * @return Get a long when possible. */ default long longValue() { return to(long.class); }
/** * @return Get a boolean when possible. */ default boolean booleanValue() { return to(boolean.class); }
/** * @return Get a byte when possible. */ default char charValue() { return to(char.class); }
/** * @return Get an integer when possible. */ default int intValue() { return to(int.class); }
/** * @return Get a short when possible. */ default short shortValue() { return to(short.class); }
/** * @return Get a string when possible. */ @Nonnull default String value() { return to(String.class); }
/** * @param type The enum type. * @param <T> Enum type. * @return Get an enum when possible. */ @Nonnull default <T extends Enum<T>> T toEnum(final Class<T> type) { return to(type); }
/** * Convert a raw value to the given type. * * @param type The type to convert to. * @param <T> Target type. * @return Get a value when possible. */ @Nonnull default <T> T to(final Class<T> type) { return to(TypeLiteral.get(type)); }
/** * Convert a raw value to the given type. This method will temporary set {@link MediaType} before * parsing a value, useful if a form field from a HTTP POST was send as json (or any other data). * * @param type The type to convert to. * @param mtype A media type to hint a parser. * @param <T> Target type. * @return Get a value when possible. */ @Nonnull default <T> T to(final Class<T> type, final MediaType mtype) { return to(TypeLiteral.get(type), mtype); }
/** * Short version of <code>params().to(type)</code>. * * @param type Object type. * @param <T> Value type. * @return Instance of object. */ @Nonnull default <T> T form(final Class<T> type) { return params().to(type); }
/** * Short version of <code>params(xss).to(type)</code>. * * @param type Object type. * @param xss Xss filter to apply. * @param <T> Value type. * @return Instance of object. */ @Nonnull default <T> T params(final Class<T> type, final String... xss) { return params(xss).to(type); }
/** * Short version of <code>params(xss).to(type)</code>. * * @param type Object type. * @param xss Xss filter to apply. * @param <T> Value type. * @return Instance of object. */ @Nonnull default <T> T form(final Class<T> type, final String... xss) { return params(xss).to(type); }
/** * Short version of <code>params().to(type)</code>. * * @param type Object type. * @param <T> Value type. * @return Instance of object. */ @Nonnull default <T> T params(final Class<T> type) { return params().to(type); }
/** * @param type The element type. * @param <T> List type. * @return Get list of values when possible. */ @SuppressWarnings("unchecked") @Nonnull default <T> List<T> toList(final Class<T> type) { return (List<T>) to(TypeLiteral.get(Types.listOf(Primitives.wrap(type)))); }
/** * @param type The element type. * @param <T> Set type. * @return Get sorted set of values when possible. */ @SuppressWarnings("unchecked") @Nonnull default <T extends Comparable<T>> SortedSet<T> toSortedSet(final Class<T> type) { return (SortedSet<T>) to(TypeLiteral.get( Types.newParameterizedType(SortedSet.class, Primitives.wrap(type)))); }
/** * @param type The optional type. * @param <T> Optional type. * @return Get an optional value when possible. */ @SuppressWarnings("unchecked") @Nonnull default <T> Optional<T> toOptional(final Class<T> type) { return (Optional<T>) to(TypeLiteral.get( Types.newParameterizedType(Optional.class, Primitives.wrap(type)))); }
/** * @param type The element type. * @param <T> Set type. * @return Get set of values when possible. */ @SuppressWarnings("unchecked") @Nonnull default <T> Set<T> toSet(final Class<T> type) { return (Set<T>) to(TypeLiteral.get(Types.setOf(Primitives.wrap(type)))); }