I changed all of Dates field variables (except mYear) from int to byte to save memory.
updated comments
This commit is contained in:
@@ -12,11 +12,11 @@ package com.TwentyCodes.java.OrderProcessor;
|
|||||||
*/
|
*/
|
||||||
public class Date implements Comparable<Date>{
|
public class Date implements Comparable<Date>{
|
||||||
|
|
||||||
private int mHour;
|
private byte mHour;
|
||||||
private int mMinute;
|
private byte mMinute;
|
||||||
private int mSecond;
|
private byte mSecond;
|
||||||
private int mMonth;
|
private byte mMonth;
|
||||||
private int mDay;
|
private byte mDay;
|
||||||
private int mYear;
|
private int mYear;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,14 +32,14 @@ public class Date implements Comparable<Date>{
|
|||||||
String[] time = parts[1].split(":");
|
String[] time = parts[1].split(":");
|
||||||
try {
|
try {
|
||||||
this.mYear = Integer.parseInt(removeFirstChar(date[0]));
|
this.mYear = Integer.parseInt(removeFirstChar(date[0]));
|
||||||
this.mDay = Integer.parseInt(date[2]);
|
this.mDay = Byte.parseByte(date[2]);
|
||||||
this.mMonth = Integer.parseInt(date[1]);
|
this.mMonth = Byte.parseByte(date[1]);
|
||||||
this.mHour = Integer.parseInt(time[0]);
|
this.mHour = Byte.parseByte(time[0]);
|
||||||
this.mMinute = Integer.parseInt(time[1]);
|
this.mMinute = Byte.parseByte(time[1]);
|
||||||
this.mSecond = Integer.parseInt(removeLastChar(time[2]));
|
this.mSecond = Byte.parseByte(removeLastChar(time[2]));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new InvalidDateFormatException();
|
throw new InvalidDateFormatException(newDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,26 +99,56 @@ public class Date implements Comparable<Date>{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSecond() {
|
/**
|
||||||
|
* getter for second
|
||||||
|
* @return seconds
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private byte getSecond() {
|
||||||
return this.mSecond;
|
return this.mSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMinute() {
|
/**
|
||||||
|
* getter for minutes
|
||||||
|
* @return minutes
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private byte getMinute() {
|
||||||
return this.mMinute;
|
return this.mMinute;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getHour() {
|
/**
|
||||||
|
* getter for hours
|
||||||
|
* @return hours
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private byte getHour() {
|
||||||
return this.mHour;
|
return this.mHour;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getDay() {
|
/**
|
||||||
|
* getter for day
|
||||||
|
* @return day
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private byte getDay() {
|
||||||
return this.mDay;
|
return this.mDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMonth() {
|
/**
|
||||||
|
* getter for month
|
||||||
|
* @return month
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private byte getMonth() {
|
||||||
return this.mMonth;
|
return this.mMonth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for year
|
||||||
|
* @return year
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
private int getYear() {
|
private int getYear() {
|
||||||
return this.mYear;
|
return this.mYear;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,18 +82,17 @@ public class Order implements Comparable<Order>{
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return this.mGoogleOrderNumber +","+ this.mOrderCreationDate.toString() +","+ this.mItemName +","+ this.mOrderAmount +","+ this.mAmountCharged +","+ this.mFinancialStatus +","+ this.mFulfillmentStatus +","+ this.mCustomerName +","+ this.mCustomerEmail;
|
return this.mGoogleOrderNumber +", "+ this.mOrderCreationDate.toString() +", "+ this.mItemName +", "+ this.mOrderAmount +", "+ this.mAmountCharged +", "+ this.mFinancialStatus +", "+ this.mFulfillmentStatus +", "+ this.mCustomerName +", "+ this.mCustomerEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares orders by item name
|
* Compares orders by orders creation date
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Order o) {
|
public int compareTo(Order o) {
|
||||||
// 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