backend/buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java
2021-01-15 16:24:29 +01:00

96 lines
2.2 KiB
Java
Executable File

package com.plannaplan.models;
import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Exchange;
/**
* Match of users Exchange's to be performed
*/
public class MatchData {
private Exchange exchangeOne;
private Exchange exchangeTwo;
/**
* create MatchData
*
* @param exchangeOne first Exchange of found match
* @param exchangeTwo second Exchange of found match
*/
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
this.exchangeOne = exchangeOne;
this.exchangeTwo = exchangeTwo;
}
/**
* @return first Exchange
*/
public Exchange getExchangeOne() {
return this.exchangeOne;
}
/**
* @return second Exchange
*/
public Exchange getExchangeTwo() {
return this.exchangeTwo;
}
/**
* @return second Exchange's owned assignmetn
*/
public Assignment getAssignmentTwo() {
return this.exchangeTwo.getOwnedAssignment();
}
/**
* @return first Exchange's owned assignmetn
*/
public Assignment getAssignmentOne() {
return this.exchangeOne.getOwnedAssignment();
}
@Override
public int hashCode() {
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof MatchData)) {
return false;
}
MatchData c = (MatchData) o;
return (this.getAssignmentOne().equals(c.getAssignmentOne())
&& this.getAssignmentTwo().equals(c.getAssignmentTwo()))
|| (this.getAssignmentOne().equals(c.getAssignmentTwo())
&& this.getAssignmentTwo().equals(c.getAssignmentOne()));
}
/**
* comparator for MatchData. It compare it by sum of both exchange's times. For
* example MatchData with Exchanges 11:00 and 12:00 will be less than with
* Exchanges 12:00 and 12:00
*
* @param m1 MatchData instance to compare to
* @return int less than 0 if m1 is "less than", 0 if it's equal and more than 0
* otherwise
*/
public int compare(MatchData m1) {
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
}
/**
* @return sum of both exchanges java.sql.Timestanp::getTime"
*/
public long getExchangesMsValue() {
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
}
}