/** * Converts a string value(s) to a Set of the target type. You may optionally specify * a string pattern to assist in the type conversion. * * @param classOfT * @param pattern optional pattern for interpreting the underlying request * string value. (used for date & time conversions) * @return a set of the values */ public <T> Set<T> toSet(Class<T> classOfT, String pattern) { return (Set<T>) toCollection(HashSet.class, classOfT, pattern); }
public <T> List<T> toList(Class<T> classOfT, String pattern) { return toCollection(ArrayList.class, classOfT, pattern); }
} else { Class<? extends Collection> collectionClass = (Class<? extends Collection>) fieldClass; value = getParameters().get(parameterName).toCollection(collectionClass, genericClass, pattern);
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Param annotation = parameter.getAnnotation(Param.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = routeContext.getParameter(name); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Header annotation = parameter.getAnnotation(Header.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = new ParameterValue(routeContext.getRequest().getLocale(), routeContext.getHeader(name)); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }
@Override public Object extract(Context context) { ParameterValue pv = new ParameterValue(context.getHeader(name)); if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override public Object extract(Context context) { ParameterValue pv = new ParameterValue(context.getHeader(name)); if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override public Object extract(Context context) { ParameterValue pv = context.getParameter(name); if (suffixes != null) { // automatically strip the suffix, if we can String value = pv.toString(); if (value != null) { String ext = Files.getFileExtension(value); if (!Strings.isNullOrEmpty(ext) && suffixes.contains(ext.toLowerCase())) { pv = new ParameterValue(Files.getNameWithoutExtension(value)); } } } if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override public Object extract(Context context) { ParameterValue pv = context.getParameter(name); if (suffixes != null) { // automatically strip the suffix, if we can String value = pv.toString(); if (value != null) { String ext = Files.getFileExtension(value); if (!Strings.isNullOrEmpty(ext) && suffixes.contains(ext.toLowerCase())) { pv = new ParameterValue(Files.getNameWithoutExtension(value)); } } } if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Param annotation = parameter.getAnnotation(Param.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = routeContext.getParameter(name); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Header annotation = parameter.getAnnotation(Header.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = new ParameterValue(routeContext.getRequest().getLocale(), routeContext.getHeader(name)); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }