-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: [Java] 列挙型を定数の集合にしてnon exhaustiveに (#955)
#941 の続き。また列挙型の網羅性についての議論は以下。 #950 (comment)
- Loading branch information
Showing
8 changed files
with
159 additions
and
48 deletions.
There are no files selected for viewing
21 changes: 17 additions & 4 deletions
21
.../voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/AccelerationMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
package jp.hiroshiba.voicevoxcore; | ||
|
||
/** ハードウェアアクセラレーションモード。 */ | ||
public enum AccelerationMode { | ||
public class AccelerationMode { | ||
/** 実行環境に合わせて自動的に選択する。 */ | ||
AUTO, | ||
public static final AccelerationMode AUTO = new AccelerationMode("AUTO"); | ||
|
||
/** CPUに設定する。 */ | ||
CPU, | ||
public static final AccelerationMode CPU = new AccelerationMode("CPU"); | ||
|
||
/** GPUに設定する。 */ | ||
GPU, | ||
public static final AccelerationMode GPU = new AccelerationMode("GPU"); | ||
|
||
private final String identifier; | ||
|
||
private AccelerationMode(String identifier) { | ||
this.identifier = identifier; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return identifier; | ||
} | ||
} |
70 changes: 55 additions & 15 deletions
70
crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/StyleType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,67 @@ | ||
package jp.hiroshiba.voicevoxcore; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
import java.lang.reflect.Type; | ||
|
||
/** スタイル(style)に対応するモデルの種類。 */ | ||
public enum StyleType { | ||
public class StyleType { | ||
/** 音声合成クエリの作成と音声合成が可能。 */ | ||
@SerializedName("talk") | ||
@Expose | ||
TALK, | ||
public static final StyleType TALK = new StyleType("talk"); | ||
|
||
/** 歌唱音声合成用のクエリの作成が可能。 */ | ||
@SerializedName("singing_teacher") | ||
@Expose | ||
SINGING_TEACHER, | ||
public static final StyleType SINGING_TEACHER = new StyleType("singing_teacher"); | ||
|
||
/** 歌唱音声合成が可能。 */ | ||
@SerializedName("frame_decode") | ||
@Expose | ||
FRAME_DECODE, | ||
public static final StyleType FRAME_DECODE = new StyleType("frame_decode"); | ||
|
||
/** 歌唱音声合成用のクエリの作成と歌唱音声合成が可能。 */ | ||
@SerializedName("sing") | ||
@Expose | ||
SING, | ||
public static final StyleType SING = new StyleType("sing"); | ||
|
||
public static final class Serializer implements JsonSerializer<StyleType> { | ||
@Override | ||
public JsonElement serialize(StyleType src, Type typeOfSrc, JsonSerializationContext context) { | ||
return new JsonPrimitive(src.toString()); | ||
} | ||
} | ||
|
||
public static final class Deserializer implements JsonDeserializer<StyleType> { | ||
@Override | ||
public StyleType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | ||
throws JsonParseException { | ||
String value = json.getAsString(); | ||
switch (value) { | ||
case "talk": | ||
return TALK; | ||
case "singing_teacher": | ||
return SINGING_TEACHER; | ||
case "frame_decode": | ||
return FRAME_DECODE; | ||
case "sing": | ||
return SING; | ||
default: | ||
throw new JsonParseException( | ||
String.format( | ||
"Invalid variant: `%s`, expected one of " | ||
+ "`talk`, `singing_teacher`, `frame_decode`, `sing`", | ||
value)); | ||
} | ||
} | ||
} | ||
|
||
private final String identifier; | ||
|
||
private StyleType(String identifier) { | ||
this.identifier = identifier; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return identifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters