finished Date.java s compareTo() and modifyed Order.java s compare to method to use its date
This commit is contained in:
@@ -74,22 +74,52 @@ public class Date implements Comparable<Date>{
|
|||||||
return this.mHour +":"+ this.mMinute +":"+ this.mSecond +" "+ this.mMonth +"-"+ this.mDay +"-"+ this.mYear;
|
return this.mHour +":"+ this.mMinute +":"+ this.mSecond +" "+ this.mMonth +"-"+ this.mDay +"-"+ this.mYear;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the total value of month + day + year + hour + minute + second
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public long total(){
|
|
||||||
return this.mDay + this.mHour + this.mMinute + this.mMonth + this.mSecond + this.mYear;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Date date) {
|
public int compareTo(Date date) {
|
||||||
long thisTotal = this.total();
|
if(this.mYear != date.getYear())
|
||||||
long thatTotal = date.total();
|
return this.mYear > date.getYear() ? 1 : -1;
|
||||||
if(thisTotal < thatTotal)
|
else
|
||||||
return -1; //before
|
if(this.mMonth != date.getMonth())
|
||||||
if(thisTotal > thatTotal)
|
return this.mMonth > date.getMonth() ? 1 : -1;
|
||||||
return 1; //after
|
else
|
||||||
return 0;//equal
|
if(this.mDay != date.getDay())
|
||||||
|
return this.mDay > date.getDay() ? 1 : -1;
|
||||||
|
else
|
||||||
|
if(this.mHour != date.getHour())
|
||||||
|
return this.mHour > date.getHour() ? 1 : -1;
|
||||||
|
else
|
||||||
|
if(this.mMinute != date.getMinute())
|
||||||
|
return this.mMinute > date.getMinute() ? 1 : -1;
|
||||||
|
else
|
||||||
|
if(this.mSecond != date.getSecond())
|
||||||
|
return this.mSecond > date.getSecond() ? 1 : -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getSecond() {
|
||||||
|
return this.mSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMinute() {
|
||||||
|
return this.mMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getHour() {
|
||||||
|
return this.mHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDay() {
|
||||||
|
return this.mDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMonth() {
|
||||||
|
return this.mMonth;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getYear() {
|
||||||
|
return this.mYear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,8 +93,8 @@ public class Order implements Comparable<Order>{
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Order o) {
|
public int compareTo(Order o) {
|
||||||
return this.mItemName.compareTo(o.getItemName());
|
// return this.mItemName.compareTo(o.getItemName());
|
||||||
// return this.mOrderCreationDate.compareTo(o.getOrderCreationDate());
|
return this.mOrderCreationDate.compareTo(o.getOrderCreationDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user