IdCounter.java 683 B

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