IdCounter.java 736 B

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