Buisness logic docs updated
This commit is contained in:
@ -3,64 +3,92 @@ 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;
|
||||
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
|
||||
/**
|
||||
* create MatchData
|
||||
*
|
||||
* @param exchangeOne first Exchange of found match
|
||||
* @param exchangeTwo second Exchange of found match
|
||||
*/
|
||||
if (!(o instanceof MatchData)) {
|
||||
return false;
|
||||
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
|
||||
this.exchangeOne = exchangeOne;
|
||||
this.exchangeTwo = exchangeTwo;
|
||||
}
|
||||
|
||||
// typecast o to Complex so that we can compare data members
|
||||
MatchData c = (MatchData) o;
|
||||
/**
|
||||
* @return first Exchange
|
||||
*/
|
||||
public Exchange getExchangeOne() {
|
||||
return this.exchangeOne;
|
||||
}
|
||||
|
||||
// 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()));
|
||||
}
|
||||
/**
|
||||
* @return second Exchange
|
||||
*/
|
||||
public Exchange getExchangeTwo() {
|
||||
return this.exchangeTwo;
|
||||
}
|
||||
|
||||
public int compare(MatchData m1) {
|
||||
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
||||
}
|
||||
/**
|
||||
* @return second Exchange's owned assignmetn
|
||||
*/
|
||||
public Assignment getAssignmentTwo() {
|
||||
return this.exchangeTwo.getOwnedAssignment();
|
||||
}
|
||||
|
||||
public long getExchangesMsValue(){
|
||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||
}
|
||||
/**
|
||||
* @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 <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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sum of both exchanges java.sql.Timestanp::getTime"
|
||||
*/
|
||||
public long getExchangesMsValue() {
|
||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user