Skip to content

Commit

Permalink
Add missing hiatus, web novel, and mixed media enums (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute authored Jun 6, 2022
1 parent 485876c commit 0f66642
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kttdevelopment</groupId>
<artifactId>mal4j</artifactId>
<version>2.7.5-SNAPSHOT</version>
<version>2.8.0</version>

<profiles>
<profile>
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/kttdevelopment/mal4j/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Used for logging operating.
*/
abstract class Logging {
public abstract class Logging {

// dedicated logger

Expand All @@ -43,8 +43,11 @@ public final String format(final LogRecord record){
}});
}

static Logger getLogger(){
return logger;
public static Logger getLogger(){
if(!new Exception().getStackTrace()[1].toString().startsWith("com.kttdevelopment.mal4j."))
throw new SecurityException("Logging not allowed for this class");
else
return logger;
}

// debug
Expand All @@ -57,7 +60,7 @@ static void setDebug(final boolean debug){

// debug logging

private static final transient HashSet<String> secrets = new HashSet<>();
private static final HashSet<String> secrets = new HashSet<>();

static void addMask(final String secret){
if(secret != null)
Expand All @@ -73,10 +76,10 @@ static void debug(){
if(debug)
System.out.println();
}

static void debug(final String message){
if(message == null) return;

if(debug){
String buffer = message;
for(final String secret : secrets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@

package com.kttdevelopment.mal4j.anime.property;

import com.kttdevelopment.mal4j.Logging;
import com.kttdevelopment.mal4j.property.MediaItem;

/**
* Represents an Anime's airing status.
*
* @see MediaItem#getStatus()
* @since 1.0.0
* @version 1.0.0
* @version 2.8.0
* @author Katsute
*/
public enum AnimeAirStatus {

Unknown ("unknown"),

Airing ("currently_airing"),
NotYetAired ("not_yet_aired"),
Finished ("finished_airing");
Expand Down Expand Up @@ -64,7 +67,9 @@ public static AnimeAirStatus asEnum(final String string){
for(final AnimeAirStatus value : values())
if(value.field.equalsIgnoreCase(string))
return value;
return null;
if(string != null)
Logging.getLogger().warning(String.format("Unrecognized Anime air status '%s', please report this to the maintainers of Mal4J", string));
return Unknown;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,38 @@

package com.kttdevelopment.mal4j.anime.property;

import com.kttdevelopment.mal4j.Logging;
import com.kttdevelopment.mal4j.anime.AnimePreview;

/**
* Represents the source material for an Anime.
*
* @see AnimePreview#getSource()
* @since 1.0.0
* @version 1.0.0
* @version 2.8.0
* @author Katsute
*/
@SuppressWarnings("SpellCheckingInspection")
public enum AnimeSource {

Unknown ("unknown"),

Other ("other"),
Original ("original"),
Manga ("manga"),
FourKomaManga ("4_koma_manga"),
/**
* @deprecated use {@link #WebManga}
*/
@Deprecated
Web_Manga ("web_manga"),
Digital_Manga ("digital_manga"),
WebManga ("web_manga"),
/**
* @deprecated use {@link #DigitalManga}
*/
@Deprecated
Digital_Manga ("digital_manga"),
DigitalManga ("digital_manga"),
Novel ("novel"),
LightNovel ("light_novel"),
VisualNovel ("visual_nodel"),
Expand All @@ -45,7 +58,10 @@ public enum AnimeSource {
Book ("book"),
PictureBook ("picture_book"),
Radio ("radio"),
Music ("music");
Music ("music"),

MixedMedia ("mixed_media"),
WebNovel ("web_novel");

private final String field;

Expand Down Expand Up @@ -75,9 +91,11 @@ public final String field(){
*/
public static AnimeSource asEnum(final String string){
for(final AnimeSource value : values())
if(value.field.equalsIgnoreCase(string))
if(!value.name().contains("_") && value.field.equalsIgnoreCase(string))
return value;
return null;
if(string != null)
Logging.getLogger().warning(String.format("Unrecognized Anime source '%s', please report this to the maintainers of Mal4J", string));
return Unknown;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@

package com.kttdevelopment.mal4j.anime.property;

import com.kttdevelopment.mal4j.Logging;
import com.kttdevelopment.mal4j.anime.AnimePreview;

/**
* Represents the type of media that the Anime is.
*
* @see AnimePreview#getType()
* @since 1.0.0
* @version 1.0.0
* @version 2.8.0
* @author Katsute
*/
public enum AnimeType {

Unknown ("unknown"),
TV ("tv"),
OVA ("ova"),
Movie ("movie"),
Special ("special"),
ONA ("ona"),
Music ("music");
Unknown ("unknown"),

TV ("tv"),
OVA ("ova"),
Movie ("movie"),
Special ("special"),
ONA ("ona"),
Music ("music"),

MixedMedia ("mixed_media");

private final String field;

Expand Down Expand Up @@ -68,7 +72,9 @@ public static AnimeType asEnum(final String string){
for(final AnimeType value : values())
if(value.field.equalsIgnoreCase(string))
return value;
return null;
if(string != null)
Logging.getLogger().warning(String.format("Unrecognized Anime type '%s', please report this to the maintainers of Mal4J", string));
return Unknown;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@

package com.kttdevelopment.mal4j.manga.property;

import com.kttdevelopment.mal4j.Logging;
import com.kttdevelopment.mal4j.property.MediaItem;

/**
* Represents a Manga's publishing status.
*
* @see MediaItem#getStatus()
* @since 1.0.0
* @version 1.0.0
* @version 2.8.0
* @author Katsute
*/
public enum MangaPublishStatus {

Unknown ("unknown"),

Publishing ("currently_publishing"),
NotYetPublished ("not_yet_published"),
Finished ("finished");
Finished ("finished"),

OnHiatus ("on_hiatus");

private final String field;

Expand Down Expand Up @@ -64,7 +69,9 @@ public static MangaPublishStatus asEnum(final String string){
for(final MangaPublishStatus value : values())
if(value.field.equalsIgnoreCase(string))
return value;
return null;
if(string != null)
Logging.getLogger().warning(String.format("Unrecognized Manga publish status '%s', please report this to the maintainers of Mal4J", string));
return Unknown;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@

package com.kttdevelopment.mal4j.manga.property;

import com.kttdevelopment.mal4j.Logging;

/**
* Represents the type of medium a Manga is.
*
* @see com.kttdevelopment.mal4j.manga.MangaPreview#getType()
* @since 1.0.0
* @version 1.1.0
* @version 2.8.0
* @author Katsute
*/
@SuppressWarnings("SpellCheckingInspection")
public enum MangaType {

Unknown ("unknown"),

Manga ("manga"),
/**
* @deprecated use {@link #LightNovel}
Expand Down Expand Up @@ -73,7 +76,9 @@ public static MangaType asEnum(final String string){
for(final MangaType value : values())
if(value.field.equalsIgnoreCase(string))
return value;
return null;
if(string != null)
Logging.getLogger().warning(String.format("Unrecognized Manga type '%s', please report this to the maintainers of Mal4J", string));
return Unknown;
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/kttdevelopment/mal4j/AnimeTests/TestAnime.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.kttdevelopment.mal4j.*;
import com.kttdevelopment.mal4j.anime.Anime;
import com.kttdevelopment.mal4j.anime.property.AnimeSource;
import com.kttdevelopment.mal4j.anime.property.AnimeType;
import com.kttdevelopment.mal4j.manga.RelatedManga;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -154,4 +156,12 @@ final void testRelatedManga(){
assertNotNull(relatedManga.getRelationTypeFormat());
}

@Test
final void testEnum(){
assertEquals(AnimeSource.WebNovel, mal.getAnime(37208).getSource());
assertEquals(AnimeSource.MixedMedia, mal.getAnime(34474).getSource());
assertEquals(AnimeSource.Unknown, AnimeSource.asEnum("?"));
assertEquals(AnimeType.Unknown, AnimeType.asEnum("?"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kttdevelopment.mal4j.MyAnimeList;
import com.kttdevelopment.mal4j.TestProvider;
import com.kttdevelopment.mal4j.anime.AnimePreview;
import com.kttdevelopment.mal4j.anime.property.AnimeType;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -51,7 +52,7 @@ final void testFields(){
.withLimit(1)
.withNoFields()
.search();
assertNull(search.get(0).getType());
assertEquals(AnimeType.Unknown, search.get(0).getType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.kttdevelopment.mal4j.*;
import com.kttdevelopment.mal4j.anime.RelatedAnime;
import com.kttdevelopment.mal4j.manga.Manga;
import com.kttdevelopment.mal4j.manga.property.MangaPublishStatus;
import com.kttdevelopment.mal4j.manga.property.MangaType;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -136,4 +138,11 @@ final void testRelatedAnime(){
assertNotNull(relatedAnime.getRelationTypeFormat());
}

@Test
final void testEnum(){
assertEquals(MangaPublishStatus.OnHiatus, mal.getManga(2).getStatus());
assertEquals(MangaPublishStatus.Unknown, MangaPublishStatus.asEnum("?"));
assertEquals(MangaType.Unknown, MangaType.asEnum("?"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kttdevelopment.mal4j.MyAnimeList;
import com.kttdevelopment.mal4j.TestProvider;
import com.kttdevelopment.mal4j.manga.MangaPreview;
import com.kttdevelopment.mal4j.manga.property.MangaType;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -51,7 +52,7 @@ final void testFields(){
.withLimit(1)
.withNoFields()
.search();
assertNull(search.get(0).getType());
assertEquals(MangaType.Unknown, search.get(0).getType());
}

@Test
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/kttdevelopment/mal4j/TestLogging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kttdevelopment.mal4j;

import org.junit.jupiter.api.Test;

final class TestLogging {

@Test
final void testLog(){
Logging.getLogger();
}

}

0 comments on commit 0f66642

Please sign in to comment.