backend/buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java

67 lines
1.7 KiB
Java
Raw Normal View History

package com.plannaplan.models;
import com.plannaplan.entities.Assignment;
2021-01-12 14:10:48 +01:00
import com.plannaplan.entities.Exchange;
public class MatchData {
2021-01-12 14:10:48 +01:00
private Exchange exchangeOne;
private Exchange exchangeTwo;
2021-01-12 14:10:48 +01:00
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
this.exchangeOne = exchangeOne;
this.exchangeTwo = exchangeTwo;
}
public Exchange getExchangeOne() {
return this.exchangeOne;
}
public Exchange getExchangeTwo() {
return this.exchangeTwo;
}
public Assignment getAssignmentTwo() {
2021-01-12 14:10:48 +01:00
return this.exchangeTwo.getOwnedAssignment();
}
public Assignment getAssignmentOne() {
2021-01-12 14:10:48 +01:00
return this.exchangeOne.getOwnedAssignment();
}
@Override
public int hashCode() {
2021-01-12 14:10:48 +01:00
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
}
@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
2021-01-12 14:10:48 +01:00
return (this.getAssignmentOne().equals(c.getAssignmentOne()) && this.getAssignmentTwo().equals(c.getAssignmentTwo())) || (this.getAssignmentOne().equals(c.getAssignmentTwo()) && this.getAssignmentTwo().equals(c.getAssignmentOne()));
}
public int compare(MatchData m1) {
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
}
public long getExchangesMsValue(){
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
}
}