@Test(expected = IllegalArgumentException.class) public void testWithMultipleParameters() { AcceptableLanguage.valueOf("en-US; q=0.7; a=b"); }
public static AcceptableLanguage valueOf(String value) { if (WILDCARD.equals(value)) { return new AcceptableLanguage(WILDCARD, null, 1d); } else { String[] parts = value.split(";\\s*"); if (parts.length > 2) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String tag = parts[0].trim(); if (!isValid(tag)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String primaryTag = tag; String subTag = null; int subIndex = tag.indexOf('-'); if (subIndex != -1) { primaryTag = tag.substring(0, subIndex); subTag = tag.substring(subIndex + 1, tag.length()); } double q = 1d; if (parts.length > 1) { String parameter = parts[1].trim(); int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); if (!"q".equals(attribute)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } q = Double.valueOf(parameter.substring(eqIndex + 1, parameter.length())); checkQuality(q); } } return new AcceptableLanguage(primaryTag, subTag, q); } }
AcceptableLanguage { public static AcceptableLanguage valueOf(String value) { if (WILDCARD.equals(value)) { return new AcceptableLanguage(WILDCARD, null, 1d); } else { String[] parts = value.split(";\\s*"); if (parts.length > 2) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String tag = parts[0].trim(); if (!isValid(tag)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String primaryTag = tag; String subTag = null; int subIndex = tag.indexOf('-'); if (subIndex != -1) { primaryTag = tag.substring(0, subIndex); subTag = tag.substring(subIndex + 1, tag.length()); } double q = 1d; if (parts.length > 1) { String parameter = parts[1].trim(); int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); if (!"q".equals(attribute)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } q = Double.valueOf(parameter.substring(eqIndex + 1, parameter.length())); checkQuality(q); } } return new AcceptableLanguage(primaryTag, subTag, q); } } }
AcceptableLanguage { public static AcceptableLanguage valueOf(String value) { if (WILDCARD.equals(value)) { return new AcceptableLanguage(WILDCARD, null, 1d); } else { String[] parts = value.split(";\\s*"); if (parts.length > 2) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String tag = parts[0].trim(); if (!isValid(tag)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String primaryTag = tag; String subTag = null; int subIndex = tag.indexOf('-'); if (subIndex != -1) { primaryTag = tag.substring(0, subIndex); subTag = tag.substring(subIndex + 1, tag.length()); } double q = 1d; if (parts.length > 1) { String parameter = parts[1].trim(); int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); if (!"q".equals(attribute)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } q = Double.valueOf(parameter.substring(eqIndex + 1, parameter.length())); checkQuality(q); } } return new AcceptableLanguage(primaryTag, subTag, q); } } private  AcceptableLanguage(String primaryTag, String subTags, double quality); }
AcceptableLanguage { public static AcceptableLanguage valueOf(String value) { if (WILDCARD.equals(value)) { return new AcceptableLanguage(WILDCARD, null, 1d); } else { String[] parts = value.split(";\\s*"); if (parts.length > 2) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String tag = parts[0].trim(); if (!isValid(tag)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String primaryTag = tag; String subTag = null; int subIndex = tag.indexOf('-'); if (subIndex != -1) { primaryTag = tag.substring(0, subIndex); subTag = tag.substring(subIndex + 1, tag.length()); } double q = 1d; if (parts.length > 1) { String parameter = parts[1].trim(); int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); if (!"q".equals(attribute)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } q = Double.valueOf(parameter.substring(eqIndex + 1, parameter.length())); checkQuality(q); } } return new AcceptableLanguage(primaryTag, subTag, q); } } private  AcceptableLanguage(String primaryTag, String subTags, double quality); String getPrimaryTag(); String getSubTags(); double getQuality(); Locale asLocale(); boolean includes(Locale tag); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static List<AcceptableLanguage> valuesOf(String values); static AcceptableLanguage valueOf(String value); static Locale bestCandidate(List<AcceptableLanguage> ranges, Collection<Locale> candidates); static boolean accepts(List<AcceptableLanguage> ranges, Locale candidate); }
AcceptableLanguage { public static AcceptableLanguage valueOf(String value) { if (WILDCARD.equals(value)) { return new AcceptableLanguage(WILDCARD, null, 1d); } else { String[] parts = value.split(";\\s*"); if (parts.length > 2) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String tag = parts[0].trim(); if (!isValid(tag)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } String primaryTag = tag; String subTag = null; int subIndex = tag.indexOf('-'); if (subIndex != -1) { primaryTag = tag.substring(0, subIndex); subTag = tag.substring(subIndex + 1, tag.length()); } double q = 1d; if (parts.length > 1) { String parameter = parts[1].trim(); int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); if (!"q".equals(attribute)) { throw new IllegalArgumentException("'" + value + "' is not a valid language tag"); } q = Double.valueOf(parameter.substring(eqIndex + 1, parameter.length())); checkQuality(q); } } return new AcceptableLanguage(primaryTag, subTag, q); } } private  AcceptableLanguage(String primaryTag, String subTags, double quality); String getPrimaryTag(); String getSubTags(); double getQuality(); Locale asLocale(); boolean includes(Locale tag); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static List<AcceptableLanguage> valuesOf(String values); static AcceptableLanguage valueOf(String value); static Locale bestCandidate(List<AcceptableLanguage> ranges, Collection<Locale> candidates); static boolean accepts(List<AcceptableLanguage> ranges, Locale candidate); static final AcceptableLanguage ANY; }