// Path: repay/src/main/java/com/repay/android/model/Debt.java
// public class Debt implements Comparable<Debt>, Serializable {
// 	
// 	private Date date;
// 	private BigDecimal amount;
// 	private String repayID, description;
// 	private int debtID;
// 	
// 	public Debt(int debtID, String repayID, Date date, BigDecimal amount, String description) {
// 		super();
// 		this.date = date;
// 		this.debtID = debtID;
// 		this.amount = amount;
// 		this.repayID = repayID;
// 		this.description = description;
// 	}
// 	
// 	public Date getDate() {
// 		return date;
// 	}
// 
// 	public void setDate(Date date) {
// 		this.date = date;
// 	}
// 
// 	public BigDecimal getAmount() {
// 		return amount;
// 	}
// 
// 	public void setAmount(BigDecimal amount) {
// 		this.amount = amount;
// 	}
// 
// 	public String getRepayID() {
// 		return repayID;
// 	}
// 
// 	public void setRepayID(String repayID) {
// 		this.repayID = repayID;
// 	}
// 
// 	public String getDescription() {
// 		return description;
// 	}
// 
// 	public void setDescription(String description) {
// 		this.description = description;
// 	}
// 	
// 	public int getDebtID(){
// 		return debtID;
// 	}
// 	
// 	@Override
// 	public int compareTo(Debt another) {
// 		return another.getDate().compareTo(date);
// 	}
// }
// 
// Path: repay/src/main/java/com/repay/android/model/Friend.java
// public class Friend implements Comparable<Friend>, Serializable {
// 	
// 	public static final String REPAYID = "repayID";
// 	public static final String LOOKUPURI = "lookupUri";
// 	public static final String NAME = "name";
// 	public static final String AMOUNT = "amount";
// 
// 	private String name, repayID;
// 	private BigDecimal debt;
// 	private String lookupURI;
// 	
// 	public Friend(String repayID, String lookupURI, String name, BigDecimal debt) {
// 		super();
// 		this.lookupURI = lookupURI;
// 		this.name = name;
// 		this.repayID = repayID;
// 		this.debt = debt;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getRepayID() {
// 		return repayID;
// 	}
// 
// 	public String getLookupURI() {
// 		return lookupURI;
// 	}
// 
// 	public BigDecimal getDebt() {
// 		return debt;
// 	}
// 
// 	public void setDebt(BigDecimal debt) {
// 		this.debt = debt;
// 	}
// 
// 	@Override
// 	public int compareTo(Friend another) {
// 		return another.getDebt().compareTo(debt);
// 	}
// 
// 	@Override
// 	public boolean equals(Object o) {
// 		return (o.getClass() == Friend.class && ((Friend) o).getRepayID().equals(repayID));
// 	}
// }


import java.math.BigDecimal;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import com.repay.android.model.Debt;
import com.repay.android.model.Friend;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.util.Log;
		super(context, DB_NAME, null, DB_VERSION);
	}

	/**
	 * Generate an ID for entering into the database as a primary key
	 * @return String representation of the Repay ID
	 */
	public static String generateRepayID() {
		long rand = new SecureRandom().nextLong();
		return String.valueOf(rand);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create Friends table
		db.execSQL(String.format("CREATE TABLE %s (%s TEXT PRIMARY KEY, %s TEXT, %s TEXT, %s TEXT)",
				Names.F_TABLENAME, Names.F_REPAYID, Names.F_LOOKUPURI, Names.F_NAME, Names.F_DEBT));

		// Create Debts table
		db.execSQL(String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT NOT NULL, "
						+ "%s TEXT, %s TEXT, %s TEXT, FOREIGN KEY(%s) REFERENCES %s(%s))", Names.D_TABLENAME,
				Names.D_DEBTID, Names.D_REPAYID, Names.D_DATE, Names.D_AMOUNT,
				Names.D_DESCRIPTION, Names.D_REPAYID, Names.F_TABLENAME, Names.F_REPAYID));
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion==1 && newVersion==2){
			// Change to include a debtID
			try{
// Path: repay/src/main/java/com/repay/android/model/Debt.java
// public class Debt implements Comparable<Debt>, Serializable {
// 	
// 	private Date date;
// 	private BigDecimal amount;
// 	private String repayID, description;
// 	private int debtID;
// 	
// 	public Debt(int debtID, String repayID, Date date, BigDecimal amount, String description) {
// 		super();
// 		this.date = date;
// 		this.debtID = debtID;
// 		this.amount = amount;
// 		this.repayID = repayID;
// 		this.description = description;
// 	}
// 	
// 	public Date getDate() {
// 		return date;
// 	}
// 
// 	public void setDate(Date date) {
// 		this.date = date;
// 	}
// 
// 	public BigDecimal getAmount() {
// 		return amount;
// 	}
// 
// 	public void setAmount(BigDecimal amount) {
// 		this.amount = amount;
// 	}
// 
// 	public String getRepayID() {
// 		return repayID;
// 	}
// 
// 	public void setRepayID(String repayID) {
// 		this.repayID = repayID;
// 	}
// 
// 	public String getDescription() {
// 		return description;
// 	}
// 
// 	public void setDescription(String description) {
// 		this.description = description;
// 	}
// 	
// 	public int getDebtID(){
// 		return debtID;
// 	}
// 	
// 	@Override
// 	public int compareTo(Debt another) {
// 		return another.getDate().compareTo(date);
// 	}
// }
// 
// Path: repay/src/main/java/com/repay/android/model/Friend.java
// public class Friend implements Comparable<Friend>, Serializable {
// 	
// 	public static final String REPAYID = "repayID";
// 	public static final String LOOKUPURI = "lookupUri";
// 	public static final String NAME = "name";
// 	public static final String AMOUNT = "amount";
// 
// 	private String name, repayID;
// 	private BigDecimal debt;
// 	private String lookupURI;
// 	
// 	public Friend(String repayID, String lookupURI, String name, BigDecimal debt) {
// 		super();
// 		this.lookupURI = lookupURI;
// 		this.name = name;
// 		this.repayID = repayID;
// 		this.debt = debt;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getRepayID() {
// 		return repayID;
// 	}
// 
// 	public String getLookupURI() {
// 		return lookupURI;
// 	}
// 
// 	public BigDecimal getDebt() {
// 		return debt;
// 	}
// 
// 	public void setDebt(BigDecimal debt) {
// 		this.debt = debt;
// 	}
// 
// 	@Override
// 	public int compareTo(Friend another) {
// 		return another.getDebt().compareTo(debt);
// 	}
// 
// 	@Override
// 	public boolean equals(Object o) {
// 		return (o.getClass() == Friend.class && ((Friend) o).getRepayID().equals(repayID));
// 	}
// }


// Path: repay/src/main/java/com/repay/android/database/DatabaseHandler.java
import java.math.BigDecimal;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import com.repay.android.model.Debt;
import com.repay.android.model.Friend;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.util.Log;

		super(context, DB_NAME, null, DB_VERSION);
	}

	/**
	 * Generate an ID for entering into the database as a primary key
	 * @return String representation of the Repay ID
	 */
	public static String generateRepayID() {
		long rand = new SecureRandom().nextLong();
		return String.valueOf(rand);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create Friends table
		db.execSQL(String.format("CREATE TABLE %s (%s TEXT PRIMARY KEY, %s TEXT, %s TEXT, %s TEXT)",
				Names.F_TABLENAME, Names.F_REPAYID, Names.F_LOOKUPURI, Names.F_NAME, Names.F_DEBT));

		// Create Debts table
		db.execSQL(String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT NOT NULL, "
						+ "%s TEXT, %s TEXT, %s TEXT, FOREIGN KEY(%s) REFERENCES %s(%s))", Names.D_TABLENAME,
				Names.D_DEBTID, Names.D_REPAYID, Names.D_DATE, Names.D_AMOUNT,
				Names.D_DESCRIPTION, Names.D_REPAYID, Names.F_TABLENAME, Names.F_REPAYID));
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion==1 && newVersion==2){
			// Change to include a debtID
			try{
				ArrayList<Debt> debts = new ArrayList<Debt>();