package classes; import com.google.gson.annotations.Expose; /** * Static counter * ID-Counter for all Cps Objects. * * @author Gruppe14 */ public class IdCounter { @Expose private static int counterObjects = 1; @Expose private static int counterElements = 1; public enum CounterType { Object, Element } /** * Return the next ID and increment the ID counter by 1. * @return the next ID */ public static synchronized int nextId(CounterType type) { switch(type){ case Element: return counterObjects++; case Object: default: return counterElements++; } } /** * Return the Counter. * * @return the counter */ public static int actualId(CounterType type) { switch(type){ case Element: return counterObjects; case Object: default: return counterElements; } } /** * Set the Counter. * * @param counter * the counter to set */ public static void setCounter(int counter, CounterType type) { switch(type){ case Element: counterElements = counter; case Object: default: counterObjects = counter; } } /** * Reset the Counter. */ public static void resetObjectCounter(CounterType type) { switch(type){ case Element: counterObjects = 1; case Object: default: counterElements = 1; } } }