Skip to content

Commit 5809904

Browse files
committed
Add annotations to MediaFormat
1 parent 53dfd87 commit 5809904

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
import javax.annotation.Nonnull;
26+
import javax.annotation.Nullable;
2627
import java.util.Arrays;
2728
import java.util.List;
2829
import java.util.function.Function;
@@ -66,11 +67,15 @@ public enum MediaFormat {
6667
// @formatter:on
6768

6869
public final int id;
70+
@Nonnull
6971
public final String name;
72+
@Nonnull
7073
public final String suffix;
74+
@Nonnull
7175
public final String mimeType;
7276

73-
MediaFormat(final int id, final String name, final String suffix, final String mimeType) {
77+
MediaFormat(final int id, @Nonnull final String name,
78+
@Nonnull final String suffix, @Nonnull final String mimeType) {
7479
this.id = id;
7580
this.name = name;
7681
this.suffix = suffix;
@@ -94,6 +99,7 @@ private static <T> T getById(final int id,
9499
* @return the friendly name of the MediaFormat associated with this ids,
95100
* or an empty String if none match it.
96101
*/
102+
@Nonnull
97103
public static String getNameById(final int id) {
98104
return getById(id, MediaFormat::getName, "");
99105
}
@@ -105,6 +111,7 @@ public static String getNameById(final int id) {
105111
* @return the file extension of the MediaFormat associated with this ids,
106112
* or an empty String if none match it.
107113
*/
114+
@Nonnull
108115
public static String getSuffixById(final int id) {
109116
return getById(id, MediaFormat::getSuffix, "");
110117
}
@@ -116,16 +123,20 @@ public static String getSuffixById(final int id) {
116123
* @return the MIME type of the MediaFormat associated with this ids,
117124
* or an empty String if none match it.
118125
*/
126+
@Nullable
119127
public static String getMimeById(final int id) {
120128
return getById(id, MediaFormat::getMimeType, null);
121129
}
122130

123131
/**
124-
* Return the MediaFormat with the supplied mime type
132+
* Return the first {@link MediaFormat} with the supplied mime type.
133+
* There might be more formats which have the same mime type.
134+
* To retrieve those, use {@link #getAllFromMimeType(String)}.
125135
*
126136
* @return MediaFormat associated with this mime type,
127137
* or null if none match it.
128138
*/
139+
@Nullable
129140
public static MediaFormat getFromMimeType(final String mimeType) {
130141
return Arrays.stream(MediaFormat.values())
131142
.filter(mediaFormat -> mediaFormat.mimeType.equals(mimeType))
@@ -152,10 +163,16 @@ public static List<MediaFormat> getAllFromMimeType(final String mimeType) {
152163
* @param id the id
153164
* @return the id of the media format or null.
154165
*/
166+
@Nullable
155167
public static MediaFormat getFormatById(final int id) {
156168
return getById(id, mediaFormat -> mediaFormat, null);
157169
}
158170

171+
/**
172+
* Get the first media format that has the given suffix/file extension.
173+
* @return the matching {@link MediaFormat} or {@code null} if no associated format is found
174+
*/
175+
@Nullable
159176
public static MediaFormat getFromSuffix(final String suffix) {
160177
return Arrays.stream(MediaFormat.values())
161178
.filter(mediaFormat -> mediaFormat.suffix.equals(suffix))
@@ -168,6 +185,7 @@ public static MediaFormat getFromSuffix(final String suffix) {
168185
*
169186
* @return the name of the format
170187
*/
188+
@Nonnull
171189
public String getName() {
172190
return name;
173191
}
@@ -177,6 +195,7 @@ public String getName() {
177195
*
178196
* @return the filename extension
179197
*/
198+
@Nonnull
180199
public String getSuffix() {
181200
return suffix;
182201
}
@@ -186,6 +205,7 @@ public String getSuffix() {
186205
*
187206
* @return the mime type
188207
*/
208+
@Nonnull
189209
public String getMimeType() {
190210
return mimeType;
191211
}

0 commit comments

Comments
 (0)