Module dev.hydraulic.types
Package dev.hydraulic.types.mimetyped
Class MimeTypedString<M extends MimeType>
java.lang.Object
dev.hydraulic.types.mimetyped.MimeTypedString<M>
- Type Parameters:
M- A marker type that isn't represented or stored at runtime. It exists only for source documentation, type inference, reflection and languages that have extension functions. So, feel free to use a wildcard type here, you won't lose anything except some type safety.
- All Implemented Interfaces:
MimeTyped<String,,M> Serializable,CharSequence,Comparable<MimeTypedString<M>>
public final class MimeTypedString<M extends MimeType>
extends Object
implements CharSequence, Serializable, Comparable<MimeTypedString<M>>, MimeTyped<String,M>
A value-based type that combines a string with an associated MIME type. The class implements
CharSequence by delegation, thus
can be treated as if it were the underlying string in some cases. Two instances are compared using MIME_TYPE_THEN_CONTENT.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Comparator<MimeTypedString<?>>A comparator that sorts first by mime type, and then by content. -
Constructor Summary
ConstructorsConstructorDescriptionMimeTypedString(String content, String mimeType) Constructs an immutable mime-typed string. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) @NotNull IntStreamchars()@NotNull IntStreamintcompareTo(@NotNull MimeTypedString o) content()The wrapped content.static MimeTypedString<MimeType.text.csv>text/csvbooleaninthashCode()static MimeTypedString<MimeType.text.html>text/htmlstatic MimeTypedString<MimeType.text.json>application/jsonintlength()text/markdownmimeType()The MIME type.static MimeTypedString<MimeType.text.plain>text/plain@NotNull CharSequencesubSequence(int start, int end) static MimeTypedString<MimeType.text>Returns the text astext/subtype.toString()Returnscontent.application/xmlMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
isEmpty
-
Field Details
-
MIME_TYPE_THEN_CONTENT
A comparator that sorts first by mime type, and then by content.
-
-
Constructor Details
-
MimeTypedString
Constructs an immutable mime-typed string.- Parameters:
content- The wrapped string.mimeType- A MIME type.
-
-
Method Details
-
text
Returns the text astext/subtype. -
plain
text/plain -
xml
application/xml -
json
application/json -
html
text/html -
csv
text/csv -
markdown
text/markdown -
content
The wrapped content. -
mimeType
The MIME type. -
equals
-
hashCode
public int hashCode() -
toString
Returnscontent.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
chars
- Specified by:
charsin interfaceCharSequence
-
codePoints
- Specified by:
codePointsin interfaceCharSequence
-
compareTo
- Specified by:
compareToin interfaceComparable<M extends MimeType>
-