MIMEType { public boolean includes(MIMEType mimeType) { boolean includes = mimeType == null || equalsWithoutParameters(ALL) || equalsWithoutParameters(mimeType); if (!includes) { includes = getPrimaryType().equals(mimeType.getPrimaryType()) && (getSubType().equals(mimeType.getSubType()) || "*".equals(getSubType())); } return includes; } MIMEType(String primaryType, String subType); private  MIMEType(String primaryType, String subType, Map<String, String> parameters); MIMEType addParameter(String name, String value); String getSubType(); String getPrimaryType(); String getCharset(); @Override int hashCode(); @Override boolean equals(final Object object); boolean equalsWithoutParameters(final Object o); @Deprecated boolean equals(final Object o, final boolean includeParameters); boolean includes(MIMEType mimeType); boolean includes(String mimeType); String getParameter(String name); List<Parameter> getParameters(); @Override String toString(); static MIMEType valueOf(final String MIMEType); static MIMEType valueOf(final String primaryType, final String subType); static boolean includes(String mimeType1, String mimeType2); static final MIMEType ALL; static final MIMEType APPLICATION_OCTET_STREAM; }
@Test public void testIncludes() { MIMEType type = MIMEType.valueOf("image/*"); MIMEType jpegType = MIMEType.valueOf("image/jpeg"); assertTrue("Image type did not include jpeg type", type.includes(jpegType)); type = MIMEType.ALL; assertTrue("All type did not include jpeg type", type.includes(jpegType)); type = MIMEType.valueOf("image", "jpeg"); assertTrue("Same type was not the same as jpeg type", type.includes(jpegType)); assertTrue("type type did not include null type", type.includes((MIMEType)null)); }