/** * Creates a list of {@link AcceptType} objects based on given input string. * @param acceptTypes accept types, comma-separated, as specified for the HTTP header <code>Accept</code> * @return a list of <code>AcceptType</code> objects * @throws IllegalArgumentException if input string is not parseable */ public static List<AcceptType> create(final String acceptTypes) { if (acceptTypes == null) { throw new IllegalArgumentException("Type parameter MUST NOT be null."); } List<AcceptType> result = new ArrayList<AcceptType>(); List<IllegalArgumentException> exceptionList = new ArrayList<IllegalArgumentException>(); String[] values = acceptTypes.split(","); for (String value : values) { try { result.add(new AcceptType(value.trim())); } catch (IllegalArgumentException e) { exceptionList.add(e); } } if (!exceptionList.isEmpty() || result.isEmpty()) { throw exceptionList.get(0); } sort(result); return result; }
/** * Creates a list of {@link AcceptType} objects based on given input string. * @param acceptTypes accept types, comma-separated, as specified for the HTTP header <code>Accept</code> * @return a list of <code>AcceptType</code> objects * @throws IllegalArgumentException if input string is not parseable */ public static List<AcceptType> create(final String acceptTypes) { if (acceptTypes == null) { throw new IllegalArgumentException("Type parameter MUST NOT be null."); } List<AcceptType> result = new ArrayList<AcceptType>(); List<IllegalArgumentException> exceptionList = new ArrayList<IllegalArgumentException>(); String[] values = acceptTypes.split(","); for (String value : values) { try { result.add(new AcceptType(value.trim())); } catch (IllegalArgumentException e) { exceptionList.add(e); } } if (!exceptionList.isEmpty() || result.isEmpty()) { throw exceptionList.get(0); } sort(result); return result; }
/** * Creates a list of {@link AcceptType} objects based on given content type. * @param contentType the content type * @return an immutable one-element list of <code>AcceptType</code> objects that matches only the given content type */ public static List<AcceptType> fromContentType(final ContentType contentType) { return Collections.singletonList(new AcceptType( contentType.getType(), contentType.getSubtype(), contentType.getParameters(), 1F)); }
/** * Creates a list of {@link AcceptType} objects based on given content type. * @param contentType the content type * @return an immutable one-element list of <code>AcceptType</code> objects that matches only the given content type */ public static List<AcceptType> fromContentType(final ContentType contentType) { return Collections.singletonList(new AcceptType( contentType.getType(), contentType.getSubtype(), contentType.getParameters(), 1F)); }