Category.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package holeg.ui.view.category;
  2. import holeg.model.AbstractCanvasObject;
  3. import java.util.HashSet;
  4. import java.util.Optional;
  5. import java.util.Set;
  6. /**
  7. * Class "Category" performs the functionality of listing elements into groups. Each Category
  8. * contains an ArrayList of CpsObjects, a name and a HashMap of ObjIdx.
  9. *
  10. * @author Gruppe14
  11. */
  12. public class Category {
  13. // objects: is a ArrayList of all Objects that belongs to the Category
  14. private Set<AbstractCanvasObject> objects = new HashSet<AbstractCanvasObject>();
  15. // name: is a String chosen by the User
  16. private String name;
  17. /**
  18. * Category Constructor.
  19. *
  20. * @param name name of the Category
  21. */
  22. public Category(String name) {
  23. setName(name);
  24. }
  25. /**
  26. * Getter for all CpsObjects.
  27. *
  28. * @return the objects
  29. */
  30. public Set<AbstractCanvasObject> getObjects() {
  31. return objects;
  32. }
  33. /**
  34. * Set a new ArrayList of CpsObjects.
  35. *
  36. * @param objects the objects to set
  37. */
  38. public void setObjects(Set<AbstractCanvasObject> objects) {
  39. this.objects = objects;
  40. }
  41. /**
  42. * Getter the name of the Category.
  43. *
  44. * @return the name
  45. */
  46. public String getName() {
  47. return name;
  48. }
  49. /**
  50. * Set the name of the Category to a new one.
  51. *
  52. * @param name the name to set
  53. */
  54. public void setName(String name) {
  55. this.name = name;
  56. }
  57. public Optional<AbstractCanvasObject> findObjectWithName(String name) {
  58. return objects.stream().filter(obj -> obj.getName().equals(name)).findFirst();
  59. }
  60. public boolean removeObjectsWithName(String name) {
  61. return objects.removeIf(obj -> obj.getName().equals(name));
  62. }
  63. }