@Test public void badEntityTagTest() { String header = "1\""; try { EntityTag.valueOf(header); fail("RuntimeException expected"); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString(header)); } try { EntityTag.valueOf(null); fail("RuntimeException expected"); } catch (RuntimeException e) { assertThat(e.getMessage(), is(equalTo("value"))); } }
public static EntityTag valueOf(String value) { Objects.requireNonNull(value, "value"); boolean isWeak = value.startsWith("W/\"") && value.endsWith("\""); boolean isQuoted = (isWeak || value.startsWith("\"")) && value.endsWith("\""); boolean isAnyMatch = "*".equals(value); if (isQuoted) { value = value.substring(value.indexOf("\"") + 1, value.lastIndexOf("\"")); value = value.replaceAll("\\\\\"", "\""); } if (isAnyMatch) { return EntityTag.ANY_MATCH; } if (isWeak) { return new EntityTag(value, true); } if (!isQuoted) { throw new RuntimeException(String.format( "header value (%s) is not a valid entity tag.", value)); } return new EntityTag(value); }
EntityTag { public static EntityTag valueOf(String value) { Objects.requireNonNull(value, "value"); boolean isWeak = value.startsWith("W/\"") && value.endsWith("\""); boolean isQuoted = (isWeak || value.startsWith("\"")) && value.endsWith("\""); boolean isAnyMatch = "*".equals(value); if (isQuoted) { value = value.substring(value.indexOf("\"") + 1, value.lastIndexOf("\"")); value = value.replaceAll("\\\\\"", "\""); } if (isAnyMatch) { return EntityTag.ANY_MATCH; } if (isWeak) { return new EntityTag(value, true); } if (!isQuoted) { throw new RuntimeException(String.format( "header value (%s) is not a valid entity tag.", value)); } return new EntityTag(value); } }
EntityTag { public static EntityTag valueOf(String value) { Objects.requireNonNull(value, "value"); boolean isWeak = value.startsWith("W/\"") && value.endsWith("\""); boolean isQuoted = (isWeak || value.startsWith("\"")) && value.endsWith("\""); boolean isAnyMatch = "*".equals(value); if (isQuoted) { value = value.substring(value.indexOf("\"") + 1, value.lastIndexOf("\"")); value = value.replaceAll("\\\\\"", "\""); } if (isAnyMatch) { return EntityTag.ANY_MATCH; } if (isWeak) { return new EntityTag(value, true); } if (!isQuoted) { throw new RuntimeException(String.format( "header value (%s) is not a valid entity tag.", value)); } return new EntityTag(value); } EntityTag(final String value);  EntityTag(final String value, final boolean weak); }
EntityTag { public static EntityTag valueOf(String value) { Objects.requireNonNull(value, "value"); boolean isWeak = value.startsWith("W/\"") && value.endsWith("\""); boolean isQuoted = (isWeak || value.startsWith("\"")) && value.endsWith("\""); boolean isAnyMatch = "*".equals(value); if (isQuoted) { value = value.substring(value.indexOf("\"") + 1, value.lastIndexOf("\"")); value = value.replaceAll("\\\\\"", "\""); } if (isAnyMatch) { return EntityTag.ANY_MATCH; } if (isWeak) { return new EntityTag(value, true); } if (!isQuoted) { throw new RuntimeException(String.format( "header value (%s) is not a valid entity tag.", value)); } return new EntityTag(value); } EntityTag(final String value);  EntityTag(final String value, final boolean weak); static EntityTag valueOf(String value); @Override int hashCode(); @Override boolean equals(Object o); String getValue(); boolean isWeak(); @Override String toString(); static void appendQuoted(StringBuilder b, String value); static void appendEscapingQuotes(StringBuilder b, String value); }
EntityTag { public static EntityTag valueOf(String value) { Objects.requireNonNull(value, "value"); boolean isWeak = value.startsWith("W/\"") && value.endsWith("\""); boolean isQuoted = (isWeak || value.startsWith("\"")) && value.endsWith("\""); boolean isAnyMatch = "*".equals(value); if (isQuoted) { value = value.substring(value.indexOf("\"") + 1, value.lastIndexOf("\"")); value = value.replaceAll("\\\\\"", "\""); } if (isAnyMatch) { return EntityTag.ANY_MATCH; } if (isWeak) { return new EntityTag(value, true); } if (!isQuoted) { throw new RuntimeException(String.format( "header value (%s) is not a valid entity tag.", value)); } return new EntityTag(value); } EntityTag(final String value);  EntityTag(final String value, final boolean weak); static EntityTag valueOf(String value); @Override int hashCode(); @Override boolean equals(Object o); String getValue(); boolean isWeak(); @Override String toString(); static void appendQuoted(StringBuilder b, String value); static void appendEscapingQuotes(StringBuilder b, String value); static final EntityTag ANY_MATCH; }