diff --git a/buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java b/buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java new file mode 100644 index 0000000..7ecca87 --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java @@ -0,0 +1,44 @@ +package com.plannaplan.models; + +import com.plannaplan.entities.Assignment; + +public class MatchData { + private Assignment assignmentOne; + private Assignment assignmentTwo; + + public MatchData(Assignment assignmentOne, Assignment assignmentTwo) { + this.assignmentOne = assignmentOne; + this.assignmentTwo = assignmentTwo; + } + + public Assignment getAssignmentTwo() { + return assignmentTwo; + } + + public Assignment getAssignmentOne() { + return assignmentOne; + } + + @Override + public boolean equals(Object o) { + + // If the object is compared with itself then return true + if (o == this) { + return true; + } + + /* + * Check if o is an instance of Complex or not "null instanceof [type]" also + * returns false + */ + if (!(o instanceof MatchData)) { + return false; + } + + // typecast o to Complex so that we can compare data members + MatchData c = (MatchData) o; + + // Compare the data members and return accordingly + return (this.assignmentOne.equals(c.getAssignmentOne()) && this.assignmentTwo.equals(c.getAssignmentTwo())) || (this.assignmentOne.equals(c.getAssignmentTwo()) && this.assignmentTwo.equals(c.getAssignmentOne())); + } +} diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java b/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java index 3c423b8..af43b97 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java @@ -6,6 +6,7 @@ import java.util.Optional; import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Exchange; import com.plannaplan.entities.Groups; +import com.plannaplan.models.MatchData; import com.plannaplan.repositories.ExchangeRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -14,50 +15,56 @@ import org.springframework.stereotype.Service; @Service public class ExchangeService { - @Autowired - private ExchangeRepository repo; + @Autowired + private ExchangeRepository repo; - /** - * @param exchange Instance to save in database - * @return Exchange Instance contains database id - */ - public Exchange save(Exchange exchange) { - return this.repo.save(exchange); - } + /** + * @param exchange Instance to save in database + * @return Exchange Instance contains database id + */ + public Exchange save(Exchange exchange) { + return this.repo.save(exchange); + } - /** - * @param id Id of exchange in database - * @return Optional Exchange if found - */ - public Optional getById(Long id) { - return this.repo.findById(id); - } + /** + * @param id Id of exchange in database + * @return Optional Exchange if found + */ + public Optional getById(Long id) { + return this.repo.findById(id); + } - /** - * @param id Id of user - * @return List of exchanges that belong to user - */ - public List getByUserId(Long id) { - return this.repo.getByUserId(id); - } + /** + * @param id Id of user + * @return List of exchanges that belong to user + */ + public List getByUserId(Long id) { + return this.repo.getByUserId(id); + } - /** - * @param entity Exchange entity which we would like to delete - */ - public void deleteExchange(Exchange entity) { - this.repo.delete(entity); - } + /** + * @param entity Exchange entity which we would like to delete + */ + public void deleteExchange(Exchange entity) { + this.repo.delete(entity); + } - /** - * @param assignment Assignment to trade for - * @param group Desired group - * @return Optional with Exchange if exist - */ - public Optional checkForExchange(Assignment assignment, Groups group) { - return this.repo.checkForExchange(assignment, group); - } + /** + * @param assignment Assignment to trade for + * @param group Desired group + * @return Optional with Exchange if exist + */ + public Optional checkForExchange(Assignment assignment, Groups group) { + return this.repo.checkForExchange(assignment, group); + } - public void performExchange() { + public void performExchange() { - } + } + +// public void getMatches(){ +// final List matches = this.repo.getMatches().stream().map(m -> { +// return (MatchData) m; +// }); +// } }