|
| 1 | +package me.proxer.library.entity.media; |
| 2 | + |
| 3 | +import com.squareup.moshi.Json; |
| 4 | +import lombok.EqualsAndHashCode; |
| 5 | +import lombok.Getter; |
| 6 | +import lombok.Value; |
| 7 | +import me.proxer.library.entity.ProxerDateItem; |
| 8 | +import me.proxer.library.entity.ProxerIdItem; |
| 9 | +import me.proxer.library.enums.Genre; |
| 10 | + |
| 11 | +import javax.annotation.Nullable; |
| 12 | +import java.util.Date; |
| 13 | +import java.util.Set; |
| 14 | + |
| 15 | +/** |
| 16 | + * Entity holding the data of a single calendar entry. |
| 17 | + * |
| 18 | + * @author Ruben Gees |
| 19 | + */ |
| 20 | +@Value |
| 21 | +@EqualsAndHashCode(onParam = @__({@Nullable})) |
| 22 | +public class CalendarEntry implements ProxerIdItem, ProxerDateItem { |
| 23 | + |
| 24 | + /** |
| 25 | + * {@inheritDoc} |
| 26 | + */ |
| 27 | + @Getter(onMethod = @__({@Override})) |
| 28 | + @Json(name = "id") |
| 29 | + private String id; |
| 30 | + |
| 31 | + /** |
| 32 | + * Returns the id of the associated {@link me.proxer.library.entity.info.Entry}. |
| 33 | + */ |
| 34 | + @Json(name = "eid") |
| 35 | + private String entryId; |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns the name. |
| 39 | + */ |
| 40 | + @Json(name = "entryname") |
| 41 | + private String name; |
| 42 | + |
| 43 | + /** |
| 44 | + * Returns the next episode to be aired. |
| 45 | + */ |
| 46 | + @Json(name = "episode") |
| 47 | + private int episode; |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns the title of the next episode to be aired. May be empty. |
| 51 | + */ |
| 52 | + @Json(name = "episodeTitle") |
| 53 | + private String episodeTitle; |
| 54 | + |
| 55 | + /** |
| 56 | + * {@inheritDoc} |
| 57 | + */ |
| 58 | + @Getter(onMethod = @__({@Override})) |
| 59 | + @Json(name = "time") |
| 60 | + private Date date; |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns the timezone of the country, the episode is aired in. |
| 64 | + */ |
| 65 | + @Json(name = "timezone") |
| 66 | + private String timezone; |
| 67 | + |
| 68 | + /** |
| 69 | + * Returns the id of the television channel, transmitting the episode. "0" if not set. |
| 70 | + */ |
| 71 | + @Json(name = "iid") |
| 72 | + private String industryId; |
| 73 | + |
| 74 | + /** |
| 75 | + * Returns the name of the television channel, transmitting the episode. May be null. |
| 76 | + */ |
| 77 | + @Nullable |
| 78 | + @Json(name = "industryname") |
| 79 | + private String industryName; |
| 80 | + |
| 81 | + /** |
| 82 | + * Returns the day of the week, the episode is aired. |
| 83 | + */ |
| 84 | + @Json(name = "weekday") |
| 85 | + private String weekDay; |
| 86 | + |
| 87 | + /** |
| 88 | + * Returns the date (and time), the episode will be uploaded. |
| 89 | + * This is just an estimated value and can be imprecise. |
| 90 | + */ |
| 91 | + @Json(name = "uptime") |
| 92 | + private Date uploadDate; |
| 93 | + |
| 94 | + /** |
| 95 | + * Returns the genres. |
| 96 | + */ |
| 97 | + @Json(name = "genre") |
| 98 | + private Set<Genre> genres; |
| 99 | + |
| 100 | + /** |
| 101 | + * Returns the sum of all ratings. |
| 102 | + */ |
| 103 | + @Json(name = "rate_sum") |
| 104 | + private int ratingSum; |
| 105 | + |
| 106 | + /** |
| 107 | + * Returns the amount of ratings. |
| 108 | + */ |
| 109 | + @Json(name = "rate_count") |
| 110 | + private int ratingAmount; |
| 111 | + |
| 112 | + /** |
| 113 | + * Returns the average of all ratings. |
| 114 | + */ |
| 115 | + public final float getRating() { |
| 116 | + if (ratingAmount <= 0) { |
| 117 | + return 0; |
| 118 | + } else { |
| 119 | + return ratingSum / (float) ratingAmount; |
| 120 | + } |
| 121 | + } |
| 122 | +} |
0 commit comments