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

Ian Grigg iang@cypherpunks.ai
Sat, 17 Mar 2001 18:07:16 -0400 (AST)


iang        01/03/17 18:07:16

  Modified:    webfunds/client Transaction.java
  Log:
  added some state & type methods for better separation, clarified contractid
  as better name than contract.

Revision  Changes    Path
1.16      +30 -11    java/webfunds/client/Transaction.java

Index: Transaction.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/Transaction.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Transaction.java	2001/03/15 19:25:46	1.15
+++ Transaction.java	2001/03/17 22:07:16	1.16
@@ -1,5 +1,5 @@
 /*
- * $Id: Transaction.java,v 1.15 2001/03/15 19:25:46 gelderen Exp $
+ * $Id: Transaction.java,v 1.16 2001/03/17 22:07:16 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-2001 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -14,7 +14,7 @@
  * WebFunds' idea of a transaction. Transactions from other payment systems
  * such as SOX are mapped to instances of this class.
  *
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
  */
 public final class Transaction {
 
@@ -40,7 +40,7 @@
     private final int type;
 
 
-    private final ItemId contract;
+    private final ItemId contractid;
     private final AccountInfo source;
     private final AccountInfo target;
     private final long amount;
@@ -50,7 +50,7 @@
 
 
     public Transaction(int type, String transid,
-                       ItemId contract,
+                       ItemId contractid,
                        AccountInfo source, AccountInfo target,
                        long amount,
                        byte[] desc, Date date)
@@ -61,8 +61,8 @@
         if( transid == null )
             throw new IllegalArgumentException("transid: " + transid);
 
-        if( contract == null )
-            throw new IllegalArgumentException("contract: " + contract);
+        if( contractid == null )
+            throw new IllegalArgumentException("contract: " + contractid);
 
         /*
          * XXX: the tight check breaks cancels, revisit this later... -JCvG
@@ -78,7 +78,7 @@
         this.desc = (desc == null) ? null : (byte[])desc.clone();
 
         this.transid = transid;
-        this.contract = contract;
+        this.contractid = contractid;
         this.amount = amount;
         this.date = date;
 
@@ -86,6 +86,7 @@
     }
 
 
+
     public int getType() {
         return type;
     }
@@ -105,7 +106,11 @@
         }
     }
 
+    public boolean isPayment()   { return type == TYPE_PAYMENT; }
+    public boolean isDeposit()   { return type == TYPE_DEPOSIT; }
+
 
+
     public void setStatus(int status) {
         if( status < STATUS_MIN || status > STATUS_MAX )
             throw new IllegalArgumentException("Invalid status: " + status);
@@ -146,13 +151,26 @@
         }
     }
 
+    public boolean isPending()   { return status == STATUS_PENDING; }
+    public boolean isPendingCan(){ return status == STATUS_PENDING_CANCEL; }
+    public boolean isPendingFail(){return status == STATUS_PENDING_FAILURE; }
+    public boolean isComplete()  { return status == STATUS_COMPLETED_OK; }
+    public boolean isCancelled() { return status == STATUS_COMPLETED_CANCELLED;}
+    public boolean isFailed()    { return status == STATUS_COMPLETED_FAILURE; }
+
+    /* composite states */
+    public boolean isAnyPending()
+                   { return isPending() || isPendingCan() || isPendingFail(); }
+    public boolean isAllComplete()
+                   { return isComplete() || isCancelled() || isFailed(); }
+
 
     public String getTransId() {
         return transid;
     }
 
-    public ItemId getContract() {
-        return contract;
+    public ItemId getContractId() {
+        return contractid;
     }
 
     public AccountInfo getSource() {
@@ -182,10 +200,11 @@
 
     public String toString() {
         return  "Transaction: " +
-                "\nType = " + getTypeAsString() +
+                "\nType = " + getTypeAsString() + " (" + type + ")" +
                 "\nId = " + transid +
                 "\nSource = " + source +
                 "\namount = " + amount +
-                "\nstatus = " + getStatusAsString();
+                "\nitem = " + contractid.fp() +
+                "\nstatus = " + getStatusAsString() + " (" + status + ")";
     }
 }