backend/buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java
Filip Izydorczyk 1506270dec Master mergerd
2021-01-13 15:53:29 +01:00

67 lines
1.7 KiB
Java
Executable File

package com.plannaplan.models;
import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Exchange;
public class MatchData {
private Exchange exchangeOne;
private Exchange exchangeTwo;
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() {
return this.exchangeTwo.getOwnedAssignment();
}
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 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.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();
}
}