/** * Attempts to lookup a defined top-level type using the given type name. * Note, per RFC-6838 4.2, top-level type and subtype names are case-insensitive. * * @param typeName * the name to lookup a Type instance by. * * @return The top-level Type instance identified by the given type name, if one is not found, then a new Type * instance is created with the given name. */ public static Type of(final String typeName) { // return a top-level type instance if givenType's name matches, else create a new type final Type type = lowercaseNameToTypeValuesMap.get(typeName.toLowerCase()); return type != null ? type : new Type(typeName); // allow non-registered top-level types. }
@Test public void test_type_parser_does_parse_unknown_type () throws ParserFailure { Optional<Type> oResult = MimeTypeParser.typeParser.tryParse("unknown"); assertThat(oResult.isPresent()).isTrue(); assertThat(oResult.get()).isNotSameAs(Type.of("unknown")); assertThat(oResult.get().getName()).isEqualTo("unknown"); }
Type givenType = Type.of(toplLevelTypeString); Facet givenFacet = Facet.forRegistrationTreeName(facetString).orElse(Facet.STANDARD); Optional<String> givenSuffix = (suffixString == null || suffixString.isEmpty()) ? Optional.empty() : Optional.of(suffixString);
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final MimeType mimeType = (MimeType) o; if (!getType().equals(mimeType.getType())) return false; //noinspection SimplifiableIfStatement if (!getSubType().equals(mimeType.getSubType())) return false; return getParameters().equals(mimeType.getParameters()); }
@Override public String toString() { if (toStringCache == null) { toStringCache = type.getName() + "/" + subType.getFacet().getRegistrationTreeName().map(tree -> tree + ".").orElse("") + subType.getName() + subType.getSuffix().map(suffix -> "+" + suffix).orElse("") + parameters.entrySet().stream().map(entry -> ";" + entry.getKey() + "=" + entry.getValue()) .collect(Collectors.joining()); } return toStringCache; } }
@Override public int hashCode() { return type.hashCode(); }
@Override public String toString() { return type.getName(); } }
private MediaRangeType mrType(String typeString) { if (MediaRange.WILDCARD_TYPE.toString().equals(typeString)) return MediaRange.WILDCARD_TYPE; return new MimeMediaRangeType(MimeType.Type.of(typeString)); }
@Override public int hashCode() { int result = getType().hashCode(); result = 67867979 * result + getSubType().hashCode(); result = 67867979 * result + getParameters().hashCode(); return result; }
@Test public void equals_returns_true_for_same_instance() { // given MimeMediaRangeType instance = new MimeMediaRangeType(MimeType.Type.of("foo")); // expect assertThat(instance.equals(instance)).isTrue(); }
@Override public int hashCode() { return getName().hashCode(); } }