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>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
<source>18</source>
<target>18</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>

View File

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