Commit 01e6fa7a authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Add doc to api.tenor

parent 7c404a40
Pipeline #23308 failed with stages
in 2 minutes and 40 seconds
......@@ -5,11 +5,18 @@ import androidx.annotation.NonNull;
import java.io.Serializable;
import java.util.List;
/**
* Class representing the dimensions of a media provided by Tenor
*/
public class Dimension implements Serializable {
public Integer width;
public Integer height;
/**
* Basic Constructor for create Dimension from List.
* @param rawData : List containing raw media dimensions
*/
public Dimension(@NonNull List<Integer> rawData) {
if (rawData.size() >= 2 && rawData.get(0) != null && rawData.get(1) != null) {
this.width = rawData.get(0);
......@@ -18,16 +25,31 @@ public class Dimension implements Serializable {
throw new IllegalArgumentException();
}
/**
* Basic Constructor for create attribute if all arguments are provided.
* @param width : Integer represent width of media
* @param height : Integer represent height of media
*/
public Dimension(@NonNull Integer width, @NonNull Integer height) {
this.width = width;
this.height = height;
}
/**
* For write dimensions.
* @return toString
*/
@NonNull
@Override
public String toString() {
return String.format("W:%d;H:%d", height, width);
}
/**
* For compare Any Object with this dimensions.
* @param obj : Object for comparison
* @return equals
*/
@Override
public boolean equals(Object obj) {
if (obj != null && obj.getClass() == this.getClass())
......@@ -36,6 +58,10 @@ public class Dimension implements Serializable {
return false;
}
/**
* For identify dimensions.
* @return hashCode
*/
@Override
public int hashCode() {
return width.hashCode() * height.hashCode();
......
......@@ -7,19 +7,36 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Class representing Content filters (such as PEGI)
*/
public class FilterContent implements Serializable {
public String name;
/**
* Basic Constructor for create attribute if all arguments are provided.
* @param name : String represent name of this filter
*/
public FilterContent(@NonNull String name) {
this.name = name;
}
/**
* For write filter content.
* @return toString
*/
@NonNull
@Override
public String toString() {
return name;
}
/**
* For compare Any Object with this filter content.
* @param obj : Object for comparison
* @return equals
*/
@Override
public boolean equals(Object obj) {
if (obj != null && obj.getClass() == this.getClass())
......@@ -28,6 +45,10 @@ public class FilterContent implements Serializable {
return false;
}
/**
* For identify filter content.
* @return hashCode
*/
@Override
public int hashCode() {
return name.hashCode();
......@@ -48,10 +69,21 @@ public class FilterContent implements Serializable {
}
public static FilterContent DEFAULT = OFF;
/**
* For get random content filter from the API.
* @return filterContent
*/
@NonNull
public static FilterContent getRandomFilterContent() {
return getRandomFilterContent(filters);
}
/**
* For get random system from list provided.
* @param filters : List where we’re going to shoot randomly
* @return filterContent
*/
@NonNull
public static FilterContent getRandomFilterContent(@NonNull List<FilterContent> filters) {
return filters.get(new Random().nextInt(filters.size()));
}
......
......@@ -4,28 +4,54 @@ import androidx.annotation.NonNull;
import java.io.Serializable;
/**
* Class representing the data in a GIF for easy backup
*/
public class GIFArtifact implements Serializable {
public String query;
public MediaFilter mediaFilter;
public FilterContent filterContent;
/**
* Default Constructor
*/
public GIFArtifact() {
this(GIFObject.NOT_FOUND);
}
/**
* Constructor with only query of research
* @param query : String represent query of research
*/
public GIFArtifact(@NonNull String query) {
this(query, MediaFilter.DEFAULT);
}
/**
* Constructor with query and mediaFilter of research
* @param query : String represent query of research
* @param mediaFilter : MediaFilter represent mediaFilter used in research
*/
public GIFArtifact(@NonNull String query, @NonNull MediaFilter mediaFilter) {
this(query, mediaFilter, FilterContent.DEFAULT);
}
/**
* Constructor with query and filterContent of research
* @param query : String represent query of research
* @param filterContent : FilterContent represent filterContent used in research
*/
public GIFArtifact(@NonNull String query, @NonNull FilterContent filterContent) {
this(query, MediaFilter.DEFAULT, filterContent);
}
/**
* Constructor with all arguments
* @param query : String represent query of research
* @param mediaFilter : MediaFilter represent mediaFilter used in research
* @param filterContent : FilterContent represent filterContent used in research
*/
public GIFArtifact(@NonNull String query, @NonNull MediaFilter mediaFilter,
@NonNull FilterContent filterContent) {
this.query = query;
......
......@@ -6,19 +6,30 @@ import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
/**
* Class representing the different types of media available within the Tenor API.
*/
public class GIFFormat implements Serializable {
public String name;
public List<MediaFilter> mediaFiltersSupported;
/**
* Default constructor with name of format
* @param name : String represent Name of format
*/
public GIFFormat(@NonNull String name) {
this(name, new ArrayList<>());
}
public GIFFormat(@NonNull String name, @Nullable MediaFilter... mediaFiltersSupported) {
/**
* Constructor with all arguments
* @param name : String represent Name of format
* @param mediaFiltersSupported : Media in which the format is present
*/
public GIFFormat(@NonNull String name, @NonNull MediaFilter... mediaFiltersSupported) {
this.name = name;
this.mediaFiltersSupported = new ArrayList<>();
for (MediaFilter mediaFilterSupported : mediaFiltersSupported)
......@@ -26,20 +37,40 @@ public class GIFFormat implements Serializable {
this.mediaFiltersSupported.add(mediaFilterSupported);
}
/**
* Constructor with all arguments
* @param name : String represent Name of format
* @param mediaFiltersSupported : List of media in which the format is present
*/
public GIFFormat(@NonNull String name, @NonNull List<MediaFilter> mediaFiltersSupported) {
this.name = name;
this.mediaFiltersSupported = mediaFiltersSupported;
}
/**
* Indicate if mediaFilter contain this format
* @param mediaFilter : MediaFilter for verification
* @return media
*/
public boolean isPresentInMediaFilter(MediaFilter mediaFilter) {
return this.mediaFiltersSupported.contains(mediaFilter);
}
/**
* For write format.
* @return toString
*/
@NonNull
@Override
public String toString() {
return name;
}
/**
* For compare Any Object with this format.
* @param obj : Object for comparison
* @return equals
*/
@Override
public boolean equals(Object obj) {
if (obj != null && obj.getClass() == this.getClass())
......@@ -48,6 +79,10 @@ public class GIFFormat implements Serializable {
return false;
}
/**
* For identify format.
* @return hashCode
*/
@Override
public int hashCode() {
return name.hashCode();
......@@ -96,6 +131,13 @@ public class GIFFormat implements Serializable {
allFmt.addAll(WEBM_FORMAT);
ALL_FORMAT = allFmt;
}
/**
* For get specific format if supported.
* @param name : String to represent format to search
* @return format
*/
@Nullable
public static GIFFormat get(String name) {
for(GIFFormat fmt : ALL_FORMAT)
if (fmt.name.toLowerCase().equals(name.toLowerCase()))
......@@ -103,13 +145,30 @@ public class GIFFormat implements Serializable {
return null;
}
/**
* For get random format from the API.
* @return format
*/
@NonNull
public static GIFFormat getRandomGIFFormat() {
return getRandomGIFFormat(ALL_FORMAT);
}
/**
* For get random format from list provided.
* @param fmts : List where we’re going to shoot randomly
* @return formats
*/
@NonNull
public static GIFFormat getRandomGIFFormat(@NonNull List<GIFFormat> fmts) {
return fmts.get(new Random().nextInt(fmts.size()));
}
/**
* For get minimal media filter for get this format for reduce cost of request
* @return mediaFilter
*/
@Nullable
public MediaFilter getMinimalMediaFilter() {
return MediaFilter.getMinimalMediaFilter(this.mediaFiltersSupported);
}
......
package fr.iutnantes.miar.dndgenerator.api.tenor;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Class representing a filter per media within the tenor API.
*/
public class MediaFilter implements Serializable {
public String name;
/**
* Default constructor
* @param name : String represent name of filter
*/
public MediaFilter(@NonNull String name) {
this.name = name;
}
/**
* For write media filter.
* @return toString
*/
@NonNull
@Override
public String toString() {
return name;
}
/**
* For compare Any Object with this media filter.
* @param obj : Object for comparison
* @return equals
*/
@Override
public boolean equals(Object obj) {
if (obj != null && obj.getClass() == this.getClass())
......@@ -28,6 +46,10 @@ public class MediaFilter implements Serializable {
return false;
}
/**
* For identify media filter.
* @return hashCode
*/
@Override
public int hashCode() {
return name.hashCode();
......@@ -50,14 +72,30 @@ public class MediaFilter implements Serializable {
}
public final static List<MediaFilter> filters = MinimalAndLower;
/**
* For get random media filter from the API.
* @return mediaFilter
*/
@NonNull
public static MediaFilter getRandomMediaFilter() {
return getRandomMediaFilter(filters);
}
/**
* For get random media filter from list provided.
* @param filters : List where we’re going to shoot randomly
* @return mediaFilter
*/
@NonNull
public static MediaFilter getRandomMediaFilter(@NonNull List<MediaFilter> filters) {
return filters.get(new Random().nextInt(filters.size()));
}
/**
* For get minimal media filter from list provided for reduce cost of request
* @return mediaFilter
*/
@Nullable
public static MediaFilter getMinimalMediaFilter(@NonNull List<MediaFilter> filters) {
if (filters.size() > 0)
return filters.get(0);
......
......@@ -6,6 +6,9 @@ import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.List;
/**
* Class representing a media provided by the tenor API.
*/
public class MediaObject implements Serializable {
public String preview;
......@@ -14,6 +17,15 @@ public class MediaObject implements Serializable {
public Integer size;
public Float duration;
/**
* Default constructor with Dimension instantiation with arguments.
* @param preview : String represent uri for preview of this media
* @param url : String represent uri for this media
* @param width : Integer represent width of this media
* @param height : Integer represent height of this media
* @param size : Integer represent size of this media
* @param duration : Float represent duration of this media
*/
public MediaObject(@NonNull String preview, @NonNull String url, @Nullable Integer width,
@Nullable Integer height, @Nullable Integer size,
@Nullable Float duration) {
......@@ -27,6 +39,14 @@ public class MediaObject implements Serializable {
this.duration = duration;
}
/**
* Default constructor with Dimension instantiation with argument.
* @param preview : String represent uri for preview of this media
* @param url : String represent uri for this media
* @param rawDims : List of Integer represent data exploited by Dimension instantiation
* @param size : Integer represent size of this media
* @param duration : Float represent duration of this media
*/
public MediaObject(@NonNull String preview, @NonNull String url, @Nullable List<Integer> rawDims,
@Nullable Integer size, @Nullable Float duration) {
this.preview = preview;
......@@ -39,6 +59,14 @@ public class MediaObject implements Serializable {
this.duration = duration;
}
/**
* Default constructor.
* @param preview : String represent uri for preview of this media
* @param url : String represent uri for this media
* @param dims : Dimensions of this media
* @param size : Integer represent size of this media
* @param duration : Float represent duration of this media
*/
public MediaObject(@NonNull String preview, @NonNull String url, @Nullable Dimension dims,
@Nullable Integer size, @Nullable Float duration) {
this.preview = preview;
......@@ -48,11 +76,21 @@ public class MediaObject implements Serializable {
this.duration = duration;
}
/**
* For write media object.
* @return toString
*/
@NonNull
@Override
public String toString() {
return url;
}
/**
* For compare Any Object with this media object.
* @param obj : Object for comparison
* @return equals
*/
@Override
public boolean equals(Object obj) {
if (obj != null && obj.getClass() == this.getClass())
......@@ -61,6 +99,10 @@ public class MediaObject implements Serializable {
return false;
}
/**
* For identify media object.
* @return hashCode
*/
@Override
public int hashCode() {
return url.hashCode() * preview.hashCode() * dims.hashCode();
......
......@@ -5,6 +5,9 @@ import androidx.annotation.Nullable;
import java.io.Serializable;
/**
* Class grouping the different arguments that can be passed in a Tenor search.
*/
public class TenorArgs implements Serializable {
public MediaFilter mediaFilter;
......@@ -12,170 +15,462 @@ public class TenorArgs implements Serializable {
public Integer nb;
public GIFObject exclude;
/**
* Default Constructor;
*/
public TenorArgs() {
this(GIFObject.DEFAULT_SIZE);
}
/**
* Constructor with only media filter
* @param mediaFilter : MediaFilter apply in search
*/
public TenorArgs(@NonNull MediaFilter mediaFilter) {
this(mediaFilter, GIFObject.DEFAULT_SIZE);
}
/**
* Constructor with only gif format
* @param gifFormat : gif format you want to see
*/
public TenorArgs(@NonNull GIFFormat gifFormat) {
this(gifFormat, GIFObject.DEFAULT_SIZE);
}
/**
* Constructor with only filter content
* @param filterContent : filter content apply in search
*/
public TenorArgs(@NonNull FilterContent filterContent) {
this(filterContent, GIFObject.DEFAULT_SIZE);
}
/**
* Constructor with only nb results
* @param nb : nb of result you wish
*/
public TenorArgs(@NonNull Integer nb) {
this(nb, null);
}
/**
* Constructor with only excluded gif
* @param exclude : gif you don’t want to see
*/
public TenorArgs(@Nullable GIFObject exclude) {
this(GIFObject.DEFAULT_SIZE, exclude);
}
/**
* Basic Constructor.
* @param gifFormat : gif format you want to see
* @param filterContent : filter content apply in search
*/
public TenorArgs(@NonNull GIFFormat gifFormat, @NonNull FilterContent filterContent) {
this(gifFormat, filterContent, GIFObject.DEFAULT_SIZE);
}
/**
* Basic Constructor.
* @param mediaFilter : media filter apply in search
* @param filterContent : filter content apply in search
*/
public TenorArgs(@NonNull MediaFilter mediaFilter, @NonNull FilterContent filterContent) {
this(mediaFilter, filterContent, GIFObject.DEFAULT_SIZE);
}
/**
* Basic Constructor.
* @param gifFormat : gif format you want to see
* @param nb : nb of result you wish
*/
public TenorArgs(@NonNull GIFFormat gifFormat, @NonNull Integer nb) {
this(gifFormat, nb, null);
}
/**
* Basic Constructor.
* @param mediaFilter : media filter apply in search
* @param nb : nb of result you wish
*/
public TenorArgs(@NonNull MediaFilter mediaFilter, @NonNull Integer nb) {
this(mediaFilter, nb, null);
}
/**
* Basic Constructor.
* @param gifFormat : gif format you want to see
* @param exclude : gif you don’t want to see
*/
public TenorArgs(@NonNull GIFFormat gifFormat, @Nullable GIFObject exclude) {
this(gifFormat, GIFObject.DEFAULT_SIZE, exclude);
}
/**
* Basic Constructor.
* @param mediaFilter : media filter apply in search
* @param exclude : gif you don’t want to see
*/
public TenorArgs(@NonNull MediaFilter mediaFilter, @Nullable GIFObject exclude) {
this(mediaFilter, GIFObject.DEFAULT_SIZE, exclude);
}
/**
* Basic Constructor.
* @param filterContent : filter content apply in search
* @param nb : nb of result you wish
*/