WIP: verder uitbreiden model

This commit is contained in:
Wanja Krah
2025-05-22 18:42:39 +02:00
parent aa6f50e3c8
commit e617bc09c1
22 changed files with 366 additions and 38 deletions

View File

@@ -18,6 +18,19 @@
<groupId>com.google.ortools</groupId>
<artifactId>ortools-java</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,17 +0,0 @@
package nl.agilecc.agiledancers;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}

View File

@@ -0,0 +1,30 @@
package nl.agilecc.agiledancers.model;
import lombok.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@Getter
@Setter
@EqualsAndHashCode
@ToString
@NoArgsConstructor
public abstract class AbstractEntity {
private Long id;
protected <T> void addNullSafe(Set<T> set, T t) {
emptyIfNull(set).add(t);
}
private <T> Set<T> emptyIfNull(Set<T> set) {
return set == null ?
new HashSet<>() :
set;
}
protected <T> Set<T> unmodifiableNullSafe(Set<T> set) {
return set == null ? Collections.emptySet() : Collections.unmodifiableSet(set);
}
}

View File

@@ -1,6 +1,12 @@
package nl.agilecc.agiledancers.model;
public class Coach {
private Long id;
private String name;
import lombok.*;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@ToString(onlyExplicitlyIncluded = true)
public class Coach extends AbstractEntity {
@ToString.Include
private final String name;
}

View File

@@ -1,17 +1,46 @@
package nl.agilecc.agiledancers.model;
import lombok.*;
import nl.agilecc.agiledancers.model.specifications.DanceGroupStyle;
import nl.agilecc.agiledancers.model.specifications.DanceGroupType;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class DanceGroup {
private Long id;
private String category;
private DanceGroupType type;
private int startAge;
private int endAge;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@ToString(onlyExplicitlyIncluded = true)
public class DanceGroup extends AbstractEntity {
@ToString.Include
private final String category;
@ToString.Include
private final DanceGroupType type;
@ToString.Include
private final int startAge;
@ToString.Include
private final int endAge;
@ToString.Include
private Set<Dancer> dancers;
@ToString.Include
private Set<DanceGroupStyle> styles;
@ToString.Include
private Coach coach;
public Set<Dancer> getDancers() {
return super.unmodifiableNullSafe(dancers);
}
public void addDancer(Dancer dancer) {
super.addNullSafe(dancers, dancer);
}
public Set<DanceGroupStyle> getStyles() {
return super.unmodifiableNullSafe(styles);
}
public void addStyle(DanceGroupStyle style) {
super.addNullSafe(styles, style);
}
}

View File

@@ -0,0 +1,50 @@
package nl.agilecc.agiledancers.model;
import lombok.*;
import java.util.Collections;
import java.util.Set;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@ToString(onlyExplicitlyIncluded = true)
public class DanceSchool extends AbstractEntity {
private final String name;
private final Set<Dancer> dancers;
private final Set<DanceGroup> danceGroups;
private final Set<Show> shows;
private final Set<Coach> coaches;
public Set<Dancer> getDancers() {
return super.unmodifiableNullSafe(dancers);
}
public Set<DanceGroup> getDanceGroups() {
return super.unmodifiableNullSafe(danceGroups);
}
public Set<Show> getShows() {
return super.unmodifiableNullSafe(shows);
}
public Set<Coach> getCoaches() {
return super.unmodifiableNullSafe(coaches);
}
public void addDancer(Dancer dancer) {
super.addNullSafe(dancers, dancer);
}
public void addDanceGroup(DanceGroup danceGroup) {
super.addNullSafe(danceGroups, danceGroup);
}
public void addShow(Show show) {
super.addNullSafe(shows, show);
}
public void addCoach(Coach coach) {
super.addNullSafe(coaches, coach);
}
}

View File

@@ -1,7 +1,21 @@
package nl.agilecc.agiledancers.model;
public class Dancer {
private Long id;
private String name;
private int age;
import lombok.*;
import java.time.LocalDate;
import java.time.Period;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@ToString(onlyExplicitlyIncluded = true)
public class Dancer extends AbstractEntity {
@ToString.Include
private final String name;
@ToString.Include
private LocalDate birthDate;
public int age() {
return Period.between(birthDate, LocalDate.now()).getYears();
}
}

View File

@@ -1,12 +1,17 @@
package nl.agilecc.agiledancers.model;
import lombok.*;
import nl.agilecc.agiledancers.model.specifications.DayPartType;
import java.util.List;
public class DayPart {
private Long id;
private DayPartType type;
private List<DanceGroup> danceGroups;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@ToString(onlyExplicitlyIncluded = true)
public class DayPart extends AbstractEntity {
@ToString.Include
private final DayPartType type;
@ToString.Include
private final List<DanceGroup> danceGroups;
}

View File

@@ -1,8 +1,14 @@
package nl.agilecc.agiledancers.model;
import lombok.*;
import java.util.List;
public class Show {
private Long id;
private List<DayPart> dayParts;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@ToString(onlyExplicitlyIncluded = true)
public class Show extends AbstractEntity {
@ToString.Include
private final List<DayPart> dayParts;
}

View File

@@ -0,0 +1,27 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.AbstractEntity;
import java.util.*;
public abstract class AbstractRepository<T extends AbstractEntity> {
private long sequence = 0L;
protected Map<Long, T> entities = new LinkedHashMap<>();
public T add(T entity) {
if (entity.getId() == null) {
entity.setId(sequence++);
}
entities.put(entity.getId(), entity);
return entity;
}
public List<T> findAll() {
return List.copyOf(entities.values());
}
public T findById(long id) {
return entities.get(id);
}
}

View File

@@ -0,0 +1,7 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.Coach;
public class CoachRepository extends AbstractRepository<Coach> {
}

View File

@@ -0,0 +1,6 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.DanceGroup;
public class DanceGroupRepository extends AbstractRepository<DanceGroup> {
}

View File

@@ -0,0 +1,6 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.DanceSchool;
public class DanceSchoolRepository extends AbstractRepository<DanceSchool> {
}

View File

@@ -0,0 +1,6 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.Dancer;
public class DancerRepository extends AbstractRepository<Dancer> {
}

View File

@@ -0,0 +1,6 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.DayPart;
public class DayPartRepository extends AbstractRepository<DayPart> {
}

View File

@@ -0,0 +1,6 @@
package nl.agilecc.agiledancers.repository;
import nl.agilecc.agiledancers.model.Show;
public class ShowRepository extends AbstractRepository<Show> {
}

View File

@@ -0,0 +1,12 @@
package nl.agilecc.agiledancers.service;
import nl.agilecc.agiledancers.model.Coach;
import nl.agilecc.agiledancers.repository.CoachRepository;
public class CoachService {
private CoachRepository coachRepository = new CoachRepository();
public Coach addCoach(String name, Coach coach) {
return coachRepository.add(Coach.builder().name(name).build());
}
}

View File

@@ -0,0 +1,27 @@
package nl.agilecc.agiledancers.service;
import nl.agilecc.agiledancers.model.Coach;
import nl.agilecc.agiledancers.model.DanceGroup;
import nl.agilecc.agiledancers.model.Dancer;
import nl.agilecc.agiledancers.model.specifications.DanceGroupStyle;
import nl.agilecc.agiledancers.model.specifications.DanceGroupType;
import nl.agilecc.agiledancers.repository.DanceGroupRepository;
import java.util.Set;
public class DanceGroupService {
private final DanceGroupRepository danceGroupRepository = new DanceGroupRepository();
public DanceGroup add(String category, DanceGroupType type, int startAge, int endAge, Set<Dancer> dancers, Set<DanceGroupStyle> styles, Coach coach) {
DanceGroup danceGroup = DanceGroup.builder()
.category(category)
.type(type)
.startAge(startAge)
.endAge(endAge)
.dancers(dancers)
.styles(styles)
.coach(coach).build();
return danceGroupRepository.add(danceGroup);
}
}

View File

@@ -0,0 +1,29 @@
package nl.agilecc.agiledancers.service;
import nl.agilecc.agiledancers.model.*;
import nl.agilecc.agiledancers.repository.DanceSchoolRepository;
public class DanceSchoolService {
private final DanceSchoolRepository danceSchoolRepository = new DanceSchoolRepository();
public DanceSchool add(String name) {
DanceSchool danceSchool = DanceSchool.builder().name(name).build();
return danceSchoolRepository.add(danceSchool);
}
public void addDancer(Long danceSchoolId, Dancer dancer) {
danceSchoolRepository.findById(danceSchoolId).addDancer(dancer);
}
public void addDanceGroup(Long danceSchoolId, DanceGroup danceGroup) {
danceSchoolRepository.findById(danceSchoolId).addDanceGroup(danceGroup);
}
public void addCoach(Long danceSchoolId, Coach coach) {
danceSchoolRepository.findById(danceSchoolId).addCoach(coach);
}
public void addShow(Long danceSchoolId, Show show) {
danceSchoolRepository.findById(danceSchoolId).addShow(show);
}
}

View File

@@ -0,0 +1,15 @@
package nl.agilecc.agiledancers.service;
import nl.agilecc.agiledancers.model.Dancer;
import nl.agilecc.agiledancers.repository.DancerRepository;
import java.time.LocalDate;
public class DancerService {
private final DancerRepository dancerRepository = new DancerRepository();
public Dancer addDancer(String name, LocalDate birthDate) {
Dancer dancer = Dancer.builder().name(name).birthDate(birthDate).build();
return dancerRepository.add(dancer);
}
}

View File

@@ -0,0 +1,26 @@
package sit;
import net.datafaker.Faker;
import nl.agilecc.agiledancers.model.DanceSchool;
import nl.agilecc.agiledancers.service.DanceSchoolService;
import org.junit.jupiter.api.Test;
class DanceSchoolSit {
Faker faker = new Faker();
int numberOfDanceGroups = 42;
int aantalDansersTm5 = 10;
int aantalDansers6tm10 = 30;
int aantalDansers11tot14 = 70;
int aantalDansers14tm17 = 140;
int aantalDansers18Plus = 100;
private DanceSchoolService danceSchoolService = new DanceSchoolService();
@Test
void testDanceSchoolModel() {
DanceSchool danceSchool = danceSchoolService.add("24 Dance Studio");
}
}

19
pom.xml
View File

@@ -26,6 +26,10 @@
<ortools-java.version>9.12.4544</ortools-java.version>
<lombok.version>1.18.38</lombok.version>
<!-- test dependencies -->
<datafaker.version>2.4.3</datafaker.version>
<junit-jupiter.version>5.12.2</junit-jupiter.version>
</properties>
<!-- dependencies that can be included by child-project - without stating the version -->
@@ -36,6 +40,21 @@
<artifactId>ortools-java</artifactId>
<version>${ortools-java.version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<version>${datafaker.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>