IdCounter.java 803 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package classes;
  2. import com.google.gson.annotations.Expose;
  3. /**
  4. * Static counter
  5. * ID-Counter for all Cps Objects.
  6. *
  7. * @author Gruppe14
  8. */
  9. public class IdCounter {
  10. @Expose
  11. private static int counter = 1;
  12. /**
  13. * Return the next ID and increment the ID counter by 1.
  14. * @return the next ID
  15. */
  16. public static synchronized int nextId() {
  17. return counter++;
  18. }
  19. /**
  20. * Return the Counter.
  21. *
  22. * @return the counter
  23. */
  24. public static int getCounter() {
  25. return counter;
  26. }
  27. /**
  28. * Set the Counter.
  29. *
  30. * @param counter
  31. * the counter to set
  32. */
  33. public static void setCounter(int counter) {
  34. IdCounter.counter = counter;
  35. }
  36. /**
  37. * Reset the Counter.
  38. */
  39. public static void resetCounter() {
  40. counter = 1;
  41. }
  42. }