From 1cb2c145d1dd6addf16119c84f3209c71183a2c2 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Tue, 11 May 2021 21:00:33 +0200 Subject: [PATCH] feat: added integer conversion to StoneType enum --- .../gamelibrary/entities/StoneType.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java index c2cecca..909f4f0 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java @@ -1,11 +1,36 @@ package uulm.teamname.marvelous.gamelibrary.entities; +import java.util.HashMap; +import java.util.Map; + /** Specifies the type of an {@link InfinityStone}. */ public enum StoneType { - SpaceStone, - MindStone, - RealityStone, - PowerStone, - TimeStone, - SoulStone + SpaceStone(0), + MindStone(1), + RealityStone(2), + PowerStone(3), + TimeStone(4), + SoulStone(5); + + private final int id; + private final static HashMap map; + + private StoneType(int id) { + this.id = id; + } + + static { + map = new HashMap<>(); + for (StoneType stoneType : StoneType.values()) { + map.put(stoneType.id, stoneType); + } + } + + public static StoneType valueOf (int stoneType) { + return map.get(stoneType); + } + + public int getID() { + return id; + } }