improve the if statement

improve the If statement to a switch
This commit is contained in:
Trobax 2022-11-23 18:15:37 +01:00
parent e04bd79518
commit b05de45437
2 changed files with 13 additions and 14 deletions

View File

@ -57,8 +57,8 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>8</source> <source>18</source>
<target>8</target> <target>18</target>
<compilerArgs>--enable-preview</compilerArgs> <compilerArgs>--enable-preview</compilerArgs>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -4,20 +4,19 @@ public class StorageItem {
protected Item item; protected Item item;
public static StorageItem createItem(Item item) { public static StorageItem createItem(Item item) {
if (item.name.equals(AgeddBrie.NAME)) { switch (item.name) {
case AgeddBrie.NAME:
return new AgeddBrie(item); return new AgeddBrie(item);
} case BackstagePasses.NAME:
if (item.name.equals(BackstagePasses.NAME)) {
return new BackstagePasses(item); return new BackstagePasses(item);
} case Sulfuras.NAME:
if (item.name.equals(Sulfuras.NAME)) {
return new Sulfuras(item); return new Sulfuras(item);
} case Conjured.NAME:
if (item.name.equals(Conjured.NAME)) {
return new Conjured(item); return new Conjured(item);
} case default:
return new StorageItem(item); return new StorageItem(item);
} }
}
public StorageItem(Item item) { public StorageItem(Item item) {
this.item = item; this.item = item;