2021-01-11 16:56:39 +01:00
|
|
|
package com.plannaplan.models;
|
|
|
|
|
|
|
|
import com.plannaplan.entities.Assignment;
|
2021-01-12 14:10:48 +01:00
|
|
|
import com.plannaplan.entities.Exchange;
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* Match of users Exchange's to be performed
|
|
|
|
*/
|
2021-01-11 16:56:39 +01:00
|
|
|
public class MatchData {
|
2021-01-15 15:54:17 +01:00
|
|
|
private Exchange exchangeOne;
|
|
|
|
private Exchange exchangeTwo;
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2021-01-12 14:10:48 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* @return first Exchange
|
|
|
|
*/
|
|
|
|
public Exchange getExchangeOne() {
|
|
|
|
return this.exchangeOne;
|
|
|
|
}
|
2021-01-12 14:10:48 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* @return second Exchange
|
|
|
|
*/
|
|
|
|
public Exchange getExchangeTwo() {
|
|
|
|
return this.exchangeTwo;
|
|
|
|
}
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* @return second Exchange's owned assignmetn
|
|
|
|
*/
|
|
|
|
public Assignment getAssignmentTwo() {
|
|
|
|
return this.exchangeTwo.getOwnedAssignment();
|
|
|
|
}
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* @return first Exchange's owned assignmetn
|
|
|
|
*/
|
|
|
|
public Assignment getAssignmentOne() {
|
|
|
|
return this.exchangeOne.getOwnedAssignment();
|
|
|
|
}
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
|
|
|
|
}
|
2021-01-12 13:04:57 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
if (o == this) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
if (!(o instanceof MatchData)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
MatchData c = (MatchData) o;
|
2021-01-11 16:56:39 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
return (this.getAssignmentOne().equals(c.getAssignmentOne())
|
|
|
|
&& this.getAssignmentTwo().equals(c.getAssignmentTwo()))
|
|
|
|
|| (this.getAssignmentOne().equals(c.getAssignmentTwo())
|
|
|
|
&& this.getAssignmentTwo().equals(c.getAssignmentOne()));
|
|
|
|
}
|
2021-01-13 12:23:00 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* 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 <0 if m1 is "less than", 0 if it's equal and >0 otherwise
|
|
|
|
*/
|
|
|
|
public int compare(MatchData m1) {
|
|
|
|
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
|
|
|
}
|
2021-01-13 12:23:00 +01:00
|
|
|
|
2021-01-15 15:54:17 +01:00
|
|
|
/**
|
|
|
|
* @return sum of both exchanges java.sql.Timestanp::getTime"
|
|
|
|
*/
|
|
|
|
public long getExchangesMsValue() {
|
|
|
|
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
|
|
|
}
|
2021-01-11 16:56:39 +01:00
|
|
|
}
|