[Webfunds-commits] java/webfunds/client Transaction.java

Jeroen C. van Gelderen gelderen@cypherpunks.ai
Tue, 6 Mar 2001 23:10:40 -0400 (AST)


gelderen    01/03/06 23:10:40

  Modified:    webfunds/client Transaction.java
  Log:
  - add more sanity checks;
  - mark all immutable instance variables final.

Revision  Changes    Path
1.13      +34 -19    java/webfunds/client/Transaction.java

Index: Transaction.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Transaction.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Transaction.java	2001/03/07 00:07:43	1.12
+++ Transaction.java	2001/03/07 03:10:39	1.13
@@ -1,5 +1,5 @@
 /*
- * $Id: Transaction.java,v 1.12 2001/03/07 00:07:43 gelderen Exp $
+ * $Id: Transaction.java,v 1.13 2001/03/07 03:10:39 gelderen Exp $
  *
  * Copyright (c) Systemics Ltd 1995-2001 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -11,7 +11,7 @@
 
 
 /**
- * @version $Revision: 1.12 $
+ * @version $Revision: 1.13 $
  */
 public final class Transaction {
 
@@ -37,13 +37,13 @@
     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;
+    private final ItemId contract;
+    private final AccountInfo source;
+    private final AccountInfo target;
+    private final long amount;
+    private final byte[] desc;
+    private final Date date;
+    private final String transid;
 
 
     public Transaction(int type, String transid,
@@ -53,16 +53,31 @@
                        byte[] desc, Date date)
     {
         if( type < TYPE_MIN || type > TYPE_MAX )
-            throw new IllegalArgumentException("Invalid type: " + type);
+            throw new IllegalArgumentException("type: " + type);
 
+        if( transid == null )
+            throw new IllegalArgumentException("transid: " + transid);
+
+        if( contract == null )
+            throw new IllegalArgumentException("contract: " + contract);
+
+        if( desc == null )
+            throw new IllegalArgumentException("desc: " + desc);
+
+        if( date == null )
+            throw new IllegalArgumentException("date: " + date);
+
         this.type = type;
+
+        this.source = (source == null ? new AccountInfo() : source);
+        this.target = (target == null ? new AccountInfo() : target);
+
         this.transid = transid;
         this.contract = contract;
-        this.source = source;
-        this.target = target;
         this.amount = amount;
-        this.desc = desc;
+        this.desc = (byte[])desc.clone();
         this.date = date;
+
         this.status = STATUS_PENDING;
     }
 
@@ -86,6 +101,7 @@
         }
     }
 
+
     public void setStatus(int status) {
         if( status < STATUS_MIN || status > STATUS_MAX )
             throw new IllegalArgumentException("Invalid status: " + status);
@@ -93,16 +109,15 @@
         this.status = status;
     }
 
+
     public int getStatus() {
         return status;
     }
 
     /* see ReceiptTableModel for test of CANCEL */
 
-    public String getStatusAsString()
-    {
-        switch(status)
-        {
+    public String getStatusAsString() {
+        switch(status) {
             case STATUS_PENDING:
                 return "PENDING";
                 // not reached
@@ -137,11 +152,11 @@
     }
 
     public AccountInfo getSource() {
-        return (source == null ? new AccountInfo() : source);
+        return this.source;
     }
 
     public AccountInfo getTarget() {
-        return (target == null ? new AccountInfo() : target);
+        return this.target;
     }
 
     public long getAmount() {