finished Date.java s compareTo() and modifyed Order.java s compare to method to use its date

This commit is contained in:
2011-01-05 05:55:23 +00:00
parent d571efd22e
commit a1ee23cd53
2 changed files with 46 additions and 16 deletions

View File

@@ -74,22 +74,52 @@ public class Date implements Comparable<Date>{
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
public int compareTo(Date date) {
long thisTotal = this.total();
long thatTotal = date.total();
if(thisTotal < thatTotal)
return -1; //before
if(thisTotal > thatTotal)
return 1; //after
return 0;//equal
if(this.mYear != date.getYear())
return this.mYear > date.getYear() ? 1 : -1;
else
if(this.mMonth != date.getMonth())
return this.mMonth > date.getMonth() ? 1 : -1;
else
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;
}
}

View File

@@ -93,8 +93,8 @@ public class Order implements Comparable<Order>{
*/
@Override
public int compareTo(Order o) {
return this.mItemName.compareTo(o.getItemName());
// return this.mOrderCreationDate.compareTo(o.getOrderCreationDate());
// return this.mItemName.compareTo(o.getItemName());
return this.mOrderCreationDate.compareTo(o.getOrderCreationDate());
}