@Test public void testValueOf$badQuality$greaterThanOne() throws Exception { CharsetPreference sut = CharsetPreference.valueOf("unicode-1-1;q=1.8"); assertThat(sut,nullValue()); }
public static CharsetPreference valueOf(final String str) { final String[] parts = str.split(";"); if(parts.length<=2) { final String charsetName =parts[0].trim(); if("*".equals(charsetName) || TOKEN_MATCHER.matchesAllOf(charsetName)) { int weight=MAX_WEIGHT; if(parts.length==2) { final String weightValue=parts[1].trim(); final Matcher matcher = QUALITY_PATTERN.matcher(weightValue); if(!matcher.matches()) { return null; } if(weightValue.charAt(2)=='0') { weight=Integer.parseInt(Strings.padEnd(weightValue.substring(4),3,'0')); } } return new CharsetPreference(charsetName,weight); } } return null; }
CharsetPreference implements Comparable<CharsetPreference> { public static CharsetPreference valueOf(final String str) { final String[] parts = str.split(";"); if(parts.length<=2) { final String charsetName =parts[0].trim(); if("*".equals(charsetName) || TOKEN_MATCHER.matchesAllOf(charsetName)) { int weight=MAX_WEIGHT; if(parts.length==2) { final String weightValue=parts[1].trim(); final Matcher matcher = QUALITY_PATTERN.matcher(weightValue); if(!matcher.matches()) { return null; } if(weightValue.charAt(2)=='0') { weight=Integer.parseInt(Strings.padEnd(weightValue.substring(4),3,'0')); } } return new CharsetPreference(charsetName,weight); } } return null; } }
CharsetPreference implements Comparable<CharsetPreference> { public static CharsetPreference valueOf(final String str) { final String[] parts = str.split(";"); if(parts.length<=2) { final String charsetName =parts[0].trim(); if("*".equals(charsetName) || TOKEN_MATCHER.matchesAllOf(charsetName)) { int weight=MAX_WEIGHT; if(parts.length==2) { final String weightValue=parts[1].trim(); final Matcher matcher = QUALITY_PATTERN.matcher(weightValue); if(!matcher.matches()) { return null; } if(weightValue.charAt(2)=='0') { weight=Integer.parseInt(Strings.padEnd(weightValue.substring(4),3,'0')); } } return new CharsetPreference(charsetName,weight); } } return null; } CharsetPreference(final String charset, final int weight); }
CharsetPreference implements Comparable<CharsetPreference> { public static CharsetPreference valueOf(final String str) { final String[] parts = str.split(";"); if(parts.length<=2) { final String charsetName =parts[0].trim(); if("*".equals(charsetName) || TOKEN_MATCHER.matchesAllOf(charsetName)) { int weight=MAX_WEIGHT; if(parts.length==2) { final String weightValue=parts[1].trim(); final Matcher matcher = QUALITY_PATTERN.matcher(weightValue); if(!matcher.matches()) { return null; } if(weightValue.charAt(2)=='0') { weight=Integer.parseInt(Strings.padEnd(weightValue.substring(4),3,'0')); } } return new CharsetPreference(charsetName,weight); } } return null; } CharsetPreference(final String charset, final int weight); String charset(); double weight(); boolean isWildcard(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); @Override int compareTo(final CharsetPreference o); static CharsetPreference valueOf(final String str); static CharsetPreference wildcard(); static CharsetPreference wildcard(final double weight); static CharsetPreference create(final Charset charset); static CharsetPreference create(final Charset charset, final double weight); }
CharsetPreference implements Comparable<CharsetPreference> { public static CharsetPreference valueOf(final String str) { final String[] parts = str.split(";"); if(parts.length<=2) { final String charsetName =parts[0].trim(); if("*".equals(charsetName) || TOKEN_MATCHER.matchesAllOf(charsetName)) { int weight=MAX_WEIGHT; if(parts.length==2) { final String weightValue=parts[1].trim(); final Matcher matcher = QUALITY_PATTERN.matcher(weightValue); if(!matcher.matches()) { return null; } if(weightValue.charAt(2)=='0') { weight=Integer.parseInt(Strings.padEnd(weightValue.substring(4),3,'0')); } } return new CharsetPreference(charsetName,weight); } } return null; } CharsetPreference(final String charset, final int weight); String charset(); double weight(); boolean isWildcard(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); @Override int compareTo(final CharsetPreference o); static CharsetPreference valueOf(final String str); static CharsetPreference wildcard(); static CharsetPreference wildcard(final double weight); static CharsetPreference create(final Charset charset); static CharsetPreference create(final Charset charset, final double weight);  }