@Test public void copyDoesNotCloneImmutableInstances() throws Exception { ImmutableMediaType original = defaultMediaType().build(); ImmutableMediaType copy = ImmutableMediaType.copyOf(original); assertThat(copy,sameInstance(original)); }
static ImmutableMediaType copyOf(final MediaType other) { ImmutableMediaType result=null; if(other instanceof ImmutableMediaType) { result=(ImmutableMediaType)other; } else if(other!=null) { final String header = other.toHeader(); try { result=fromString(header,MediaRangeSyntax.RFC6838); } catch (InvalidMediaTypeException e) { result=fromString(header,MediaRangeSyntax.RFC7230); } } return result; }
ImmutableMediaType implements MediaType { static ImmutableMediaType copyOf(final MediaType other) { ImmutableMediaType result=null; if(other instanceof ImmutableMediaType) { result=(ImmutableMediaType)other; } else if(other!=null) { final String header = other.toHeader(); try { result=fromString(header,MediaRangeSyntax.RFC6838); } catch (InvalidMediaTypeException e) { result=fromString(header,MediaRangeSyntax.RFC7230); } } return result; } }
ImmutableMediaType implements MediaType { static ImmutableMediaType copyOf(final MediaType other) { ImmutableMediaType result=null; if(other instanceof ImmutableMediaType) { result=(ImmutableMediaType)other; } else if(other!=null) { final String header = other.toHeader(); try { result=fromString(header,MediaRangeSyntax.RFC6838); } catch (InvalidMediaTypeException e) { result=fromString(header,MediaRangeSyntax.RFC7230); } } return result; } ImmutableMediaType(final MediaRangeSyntax syntax, final String type, final String subtype, String suffix, final Map<String, String> parameters); }
ImmutableMediaType implements MediaType { static ImmutableMediaType copyOf(final MediaType other) { ImmutableMediaType result=null; if(other instanceof ImmutableMediaType) { result=(ImmutableMediaType)other; } else if(other!=null) { final String header = other.toHeader(); try { result=fromString(header,MediaRangeSyntax.RFC6838); } catch (InvalidMediaTypeException e) { result=fromString(header,MediaRangeSyntax.RFC7230); } } return result; } ImmutableMediaType(final MediaRangeSyntax syntax, final String type, final String subtype, String suffix, final Map<String, String> parameters); @Override String type(); @Override String subType(); @Override Charset charset(); @Override String suffix(); @Override Map<String,String> parameters(); @Override boolean isWildcard(); @Override String toHeader(); @Override int hashCode(); @Override boolean equals(final Object other); @Override String toString(); }
ImmutableMediaType implements MediaType { static ImmutableMediaType copyOf(final MediaType other) { ImmutableMediaType result=null; if(other instanceof ImmutableMediaType) { result=(ImmutableMediaType)other; } else if(other!=null) { final String header = other.toHeader(); try { result=fromString(header,MediaRangeSyntax.RFC6838); } catch (InvalidMediaTypeException e) { result=fromString(header,MediaRangeSyntax.RFC7230); } } return result; } ImmutableMediaType(final MediaRangeSyntax syntax, final String type, final String subtype, String suffix, final Map<String, String> parameters); @Override String type(); @Override String subType(); @Override Charset charset(); @Override String suffix(); @Override Map<String,String> parameters(); @Override boolean isWildcard(); @Override String toHeader(); @Override int hashCode(); @Override boolean equals(final Object other); @Override String toString();  }