[Webfunds-commits] java/webfunds/client Transaction.java
Jeroen C. van Gelderen
gelderen@cypherpunks.ai
Tue, 6 Mar 2001 20:07:44 -0400 (AST)
gelderen 01/03/06 20:07:44
Modified: webfunds/client Transaction.java
Log:
General cleanup:
- make class final;
- privatise private methods that had package visibility;
- Rename enums so that they look like enums;
- enforce some important invariants, more to come.
Revision Changes Path
1.12 +67 -66 java/webfunds/client/Transaction.java
Index: Transaction.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Transaction.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Transaction.java 2000/07/16 19:37:28 1.11
+++ Transaction.java 2001/03/07 00:07:43 1.12
@@ -1,7 +1,7 @@
/*
- * $Id: Transaction.java,v 1.11 2000/07/16 19:37:28 iang Exp $
+ * $Id: Transaction.java,v 1.12 2001/03/07 00:07:43 gelderen Exp $
*
- * Copyright (c) Systemics Ltd 1995-1999 on behalf of
+ * Copyright (c) Systemics Ltd 1995-2001 on behalf of
* the WebFunds Development Team. All Rights Reserved.
*/
package webfunds.client;
@@ -11,38 +11,50 @@
/**
- * Be very careful with this class - it is serialised :(
- * It needs to change over to the Encodable.
+ * @version $Revision: 1.12 $
*/
-public class Transaction
-{
+public final class Transaction {
- public static final int PENDING = 0;
- public static final int PENDING_CANCEL = 1;
- public static final int PENDING_FAILURE = 2;
- public static final int COMPLETED_OK = 3;
- public static final int COMPLETED_CANCELLED = 4;
- public static final int COMPLETED_FAILURE = 5;
-
- public static final int PAYMENT = 0;
- public static final int DEPOSIT = 1;
-
- ItemId contract;
- AccountInfo source;
- AccountInfo target;
- long amount;
- byte[] desc;
- Date date;
- int status;
- String transid;
- int type;
+ public static final int
+ STATUS_MIN = 0,
+ STATUS_PENDING = 0,
+ STATUS_PENDING_CANCEL = 1,
+ STATUS_PENDING_FAILURE = 2,
+ STATUS_COMPLETED_OK = 3,
+ STATUS_COMPLETED_CANCELLED = 4,
+ STATUS_COMPLETED_FAILURE = 5,
+ STATUS_MAX = 5;
+
+ private int status;
+
+
+ public static final int
+ TYPE_MIN = 0,
+ TYPE_PAYMENT = 0,
+ TYPE_DEPOSIT = 1,
+ TYPE_MAX = 1;
+
+ private final int type;
+
+
+ private ItemId contract;
+ private AccountInfo source;
+ private AccountInfo target;
+ private long amount;
+ private byte[] desc;
+ private Date date;
+ private String transid;
+
public Transaction(int type, String transid,
ItemId contract,
AccountInfo source, AccountInfo target,
long amount,
byte[] desc, Date date)
{
+ if( type < TYPE_MIN || type > TYPE_MAX )
+ throw new IllegalArgumentException("Invalid type: " + type);
+
this.type = type;
this.transid = transid;
this.contract = contract;
@@ -51,22 +63,21 @@
this.amount = amount;
this.desc = desc;
this.date = date;
- this.status = PENDING;
+ this.status = STATUS_PENDING;
}
- public int getType()
- {
+
+ public int getType() {
return type;
}
- public String getStringType()
- {
- switch(type)
- {
- case PAYMENT:
+
+ public String getTypeAsString() {
+ switch(type) {
+ case TYPE_PAYMENT:
return "Payment";
//not reached
- case DEPOSIT:
+ case TYPE_DEPOSIT:
return "Deposit";
//not reached
default:
@@ -75,38 +86,39 @@
}
}
- public void setStatus(int status)
- {
+ public void setStatus(int status) {
+ if( status < STATUS_MIN || status > STATUS_MAX )
+ throw new IllegalArgumentException("Invalid status: " + status);
+
this.status = status;
}
- public int getStatus()
- {
+ public int getStatus() {
return status;
}
/* see ReceiptTableModel for test of CANCEL */
- public String getStringStatus()
+ public String getStatusAsString()
{
switch(status)
{
- case PENDING:
+ case STATUS_PENDING:
return "PENDING";
// not reached
- case PENDING_CANCEL:
+ case STATUS_PENDING_CANCEL:
return "PENDING CANCEL";
// not reached
- case PENDING_FAILURE:
+ case STATUS_PENDING_FAILURE:
return "PENDING FAILURE";
// not reached
- case COMPLETED_OK:
+ case STATUS_COMPLETED_OK:
return "COMPLETED";
// not reached
- case COMPLETED_CANCELLED:
+ case STATUS_COMPLETED_CANCELLED:
return "CANCELLED";
// not reached
- case COMPLETED_FAILURE:
+ case STATUS_COMPLETED_FAILURE:
return "FAILED";
// not reached
default:
@@ -115,53 +127,42 @@
}
}
-
- public String getTransId()
- {
+ public String getTransId() {
return transid;
}
- public ItemId getContract()
- {
+ public ItemId getContract() {
return contract;
}
- public AccountInfo getSource()
- {
+ public AccountInfo getSource() {
return (source == null ? new AccountInfo() : source);
}
- public AccountInfo getTarget()
- {
+ public AccountInfo getTarget() {
return (target == null ? new AccountInfo() : target);
}
- public long getAmount()
- {
+ public long getAmount() {
return amount;
}
- public Date getDate()
- {
+ public Date getDate() {
return date;
}
- public byte[] getDesc()
- {
+ public byte[] getDesc() {
return desc;
}
- public String toString()
- {
+ public String toString() {
return "Transaction: " +
- "\nType = " + getStringType() +
+ "\nType = " + getTypeAsString() +
"\nId = " + transid +
"\nSource = " + source +
"\namount = " + amount +
- "\nstatus = " + getStringStatus();
+ "\nstatus = " + getStatusAsString();
}
-
-
}