IdCounter.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package holeg.ui.model;
  2. /**
  3. * Static counter
  4. * ID-Counter for all Cps Objects.
  5. *
  6. * @author Gruppe14
  7. */
  8. public class IdCounter {
  9. private static int counterObjects = 1;
  10. private static int counterElements = 1;
  11. public enum CounterType {
  12. Object, Element
  13. }
  14. /**
  15. * Return the next ID and increment the ID counter by 1.
  16. * @return the next ID
  17. */
  18. public static synchronized int nextId(CounterType type) {
  19. switch(type){
  20. case Element:
  21. return counterObjects++;
  22. case Object:
  23. default:
  24. return counterElements++;
  25. }
  26. }
  27. /**
  28. * Return the Counter.
  29. *
  30. * @return the counter
  31. */
  32. public static int actualId(CounterType type) {
  33. switch(type){
  34. case Element:
  35. return counterObjects;
  36. case Object:
  37. default:
  38. return counterElements;
  39. }
  40. }
  41. /**
  42. * Set the Counter.
  43. *
  44. * @param counter
  45. * the counter to set
  46. */
  47. public static void setCounter(int counter, CounterType type) {
  48. switch(type){
  49. case Element:
  50. counterElements = counter;
  51. case Object:
  52. default:
  53. counterObjects = counter;
  54. }
  55. }
  56. /**
  57. * Reset the Counter.
  58. */
  59. public static void resetObjectCounter(CounterType type) {
  60. switch(type){
  61. case Element:
  62. counterObjects = 1;
  63. case Object:
  64. default:
  65. counterElements = 1;
  66. }
  67. }
  68. }