import java.util.GregorianCalendar; /* * Pehr Hovey * MAT259 Project 1 Winter 2009 * * Graph Checkout duration, collection code and time in 2D * * Transaction.java - represent one library transaction. * Store only fields needed for this visualization * * Based on course code from Angus * */ public class Transaction { String itemNumber; //Unique identifier String ckodate; String ckotime; String ckidate; String ckitime; String collcode; String itemtype; String title; long ckoduration; //this field is calculated from check-in, check-out date/time long ckitimestamp; //Plot-related info that will be mutated as data is sorted, etc float x,x_b,y; //x_b is different x for when buttons are shown float x_equal, x_b_equal; float duration_height_lin; //height of duration rect in log and linear scale float duration_height_log; String label; //what is the x-label for the current view? boolean on_boundary; //if sorting twice, does this trans appear on a boundary between chunks? public Transaction(){ x=0; x_b = 0; x_equal = 0; x_b_equal = 0; y=0; duration_height_log=0; duration_height_lin=0; on_boundary=false; } public Transaction(Transaction t){ //make a copy. Do it the long way to try to get a deep copy x_equal = t.x_equal; x_b_equal = t.x_b_equal; x_b = t.x_b; x = t.x; y = t.y; duration_height_lin = t.duration_height_lin; duration_height_log = t.duration_height_log; on_boundary = t.on_boundary; itemNumber = t.itemNumber; ckodate = t.ckodate; ckotime = t.ckotime; ckidate = t.ckidate; ckitime = t.ckitime; collcode = t.collcode; itemtype = t.itemtype; title = t.title; ckoduration = t.ckoduration; ckitimestamp = t.ckitimestamp; label = t.label; } public String toString() { String str = ""; //str += "\"" + title + "\" checked out at " + ckotime + " on " + ckodate + " then checked in at " + ckitime + " on " + ckidate; str+=itemNumber+" "+ckodate+" "+ckotime+" "+ckidate+" "+ckitime+" "+collcode+" "+itemtype+" "+title+" cko_duration: "+ckoduration; return str; } public void calculateDuration(){ //calc checkout duration and store in this obj //GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) java.util.GregorianCalendar checkin = TransactionUtils.getGCFromString(ckidate, ckitime); java.util.GregorianCalendar checkout = TransactionUtils.getGCFromString(ckodate, ckotime); ckoduration = TransactionUtils.getTimeDifferenceInMillis(checkout, checkin); } public void calculateTimeStamp(){ //this makes it easier to sort by check in time java.util.GregorianCalendar checkin = TransactionUtils.getGCFromString(ckidate, ckitime); ckitimestamp = checkin.getTimeInMillis(); } }