@UseDataProvider("forTestParsingAcceptLanguageHeader") @Test public void testParsingAcceptLanguageHeader(String acceptLanguageHeader, String language, String country, float qValue) { AcceptLanguageHeaderDelegate headerDelegate = new AcceptLanguageHeaderDelegate(); AcceptLanguage acceptLanguage = headerDelegate.fromString(acceptLanguageHeader); assertEquals(language, acceptLanguage.getPrimaryTag()); assertEquals(country, acceptLanguage.getSubTag()); assertEquals(qValue, acceptLanguage.getQvalue(), 0.0F); }
@Override public AcceptLanguage fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } try { header = HeaderHelper.removeWhitespaces(header); String tag; Map<String, String> params = null; int p = scan(header, QUALITY_SEPARATOR); if (charAtIs(header, p, QUALITY_SEPARATOR)) { tag = header.substring(0, p); params = new HeaderParameterParser().parse(header); } else { tag = header; } String lang; String country = null; p = scan(header, SUB_TAG_SEPARATOR); if (charAtIs(header, p, SUB_TAG_SEPARATOR)) { lang = tag.substring(0, p); country = tag.substring(p + 1); } else { lang = tag; } if (params == null || params.get(QVALUE) == null) { return new AcceptLanguage(new Language(new Locale(lang, nullToEmpty(country)))); } return new AcceptLanguage(new Locale(lang, nullToEmpty(country)), parseQualityValue(params.get(QVALUE))); } catch (ParseException e) { throw new IllegalArgumentException("Accept language header malformed"); } }
AcceptLanguageHeaderDelegate implements RuntimeDelegate.HeaderDelegate<AcceptLanguage> { @Override public AcceptLanguage fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } try { header = HeaderHelper.removeWhitespaces(header); String tag; Map<String, String> params = null; int p = scan(header, QUALITY_SEPARATOR); if (charAtIs(header, p, QUALITY_SEPARATOR)) { tag = header.substring(0, p); params = new HeaderParameterParser().parse(header); } else { tag = header; } String lang; String country = null; p = scan(header, SUB_TAG_SEPARATOR); if (charAtIs(header, p, SUB_TAG_SEPARATOR)) { lang = tag.substring(0, p); country = tag.substring(p + 1); } else { lang = tag; } if (params == null || params.get(QVALUE) == null) { return new AcceptLanguage(new Language(new Locale(lang, nullToEmpty(country)))); } return new AcceptLanguage(new Locale(lang, nullToEmpty(country)), parseQualityValue(params.get(QVALUE))); } catch (ParseException e) { throw new IllegalArgumentException("Accept language header malformed"); } } }
AcceptLanguageHeaderDelegate implements RuntimeDelegate.HeaderDelegate<AcceptLanguage> { @Override public AcceptLanguage fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } try { header = HeaderHelper.removeWhitespaces(header); String tag; Map<String, String> params = null; int p = scan(header, QUALITY_SEPARATOR); if (charAtIs(header, p, QUALITY_SEPARATOR)) { tag = header.substring(0, p); params = new HeaderParameterParser().parse(header); } else { tag = header; } String lang; String country = null; p = scan(header, SUB_TAG_SEPARATOR); if (charAtIs(header, p, SUB_TAG_SEPARATOR)) { lang = tag.substring(0, p); country = tag.substring(p + 1); } else { lang = tag; } if (params == null || params.get(QVALUE) == null) { return new AcceptLanguage(new Language(new Locale(lang, nullToEmpty(country)))); } return new AcceptLanguage(new Locale(lang, nullToEmpty(country)), parseQualityValue(params.get(QVALUE))); } catch (ParseException e) { throw new IllegalArgumentException("Accept language header malformed"); } }  }
AcceptLanguageHeaderDelegate implements RuntimeDelegate.HeaderDelegate<AcceptLanguage> { @Override public AcceptLanguage fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } try { header = HeaderHelper.removeWhitespaces(header); String tag; Map<String, String> params = null; int p = scan(header, QUALITY_SEPARATOR); if (charAtIs(header, p, QUALITY_SEPARATOR)) { tag = header.substring(0, p); params = new HeaderParameterParser().parse(header); } else { tag = header; } String lang; String country = null; p = scan(header, SUB_TAG_SEPARATOR); if (charAtIs(header, p, SUB_TAG_SEPARATOR)) { lang = tag.substring(0, p); country = tag.substring(p + 1); } else { lang = tag; } if (params == null || params.get(QVALUE) == null) { return new AcceptLanguage(new Language(new Locale(lang, nullToEmpty(country)))); } return new AcceptLanguage(new Locale(lang, nullToEmpty(country)), parseQualityValue(params.get(QVALUE))); } catch (ParseException e) { throw new IllegalArgumentException("Accept language header malformed"); } }  @Override AcceptLanguage fromString(String header); @Override String toString(AcceptLanguage language); }
AcceptLanguageHeaderDelegate implements RuntimeDelegate.HeaderDelegate<AcceptLanguage> { @Override public AcceptLanguage fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } try { header = HeaderHelper.removeWhitespaces(header); String tag; Map<String, String> params = null; int p = scan(header, QUALITY_SEPARATOR); if (charAtIs(header, p, QUALITY_SEPARATOR)) { tag = header.substring(0, p); params = new HeaderParameterParser().parse(header); } else { tag = header; } String lang; String country = null; p = scan(header, SUB_TAG_SEPARATOR); if (charAtIs(header, p, SUB_TAG_SEPARATOR)) { lang = tag.substring(0, p); country = tag.substring(p + 1); } else { lang = tag; } if (params == null || params.get(QVALUE) == null) { return new AcceptLanguage(new Language(new Locale(lang, nullToEmpty(country)))); } return new AcceptLanguage(new Locale(lang, nullToEmpty(country)), parseQualityValue(params.get(QVALUE))); } catch (ParseException e) { throw new IllegalArgumentException("Accept language header malformed"); } }  @Override AcceptLanguage fromString(String header); @Override String toString(AcceptLanguage language);  }