1 package org.neuclear.ledger.prevalent;
2
3 import org.neuclear.ledger.PostedHeldTransaction;
4 import org.neuclear.ledger.TransactionItem;
5
6 import java.io.Serializable;
7 import java.util.List;
8 import java.util.ArrayList;
9 import java.util.Date;
10 import java.util.Iterator;
11
12 /***
13 * Created by IntelliJ IDEA.
14 * User: pelleb
15 * Date: Mar 20, 2004
16 * Time: 5:49:35 PM
17 * To change this template use File | Settings | File Templates.
18 */
19 public class AccountHeld implements Serializable {
20 private List holds= new ArrayList(1);
21 private HoldTable holdtable;
22 private String id;
23
24 public AccountHeld(HoldTable holdtable, String id) {
25 this.holdtable = holdtable;
26 this.id = id;
27 }
28 public void add(final PostedHeldTransaction tran){
29 holds.add(tran);
30 }
31
32 double getBalance(){
33 final Date current=new Date();
34 Iterator iter=holds.iterator();
35 double balance=0;
36 PostedHeldTransaction expired=null;
37 while (iter.hasNext()) {
38 PostedHeldTransaction transaction = (PostedHeldTransaction) iter.next();
39 if (transaction.getExpiryTime().after(current)){
40 Iterator items=transaction.getItems();
41 while (items.hasNext()) {
42 TransactionItem item = (TransactionItem) items.next();
43 if(item.getBook().equals(id)&&item.getAmount()<0)
44 balance+=item.getAmount();
45 }
46 } else {
47 expired=transaction;
48 }
49 }
50 if (expired!=null)
51 holdtable.expire(expired);
52 return balance;
53 }
54 void expire(final PostedHeldTransaction dead){
55 for (int i = 0; i < holds.size(); i++) {
56 PostedHeldTransaction transaction = (PostedHeldTransaction) holds.get(i);
57 if (transaction.getId().equals(dead.getId())){
58 holds.remove(i);
59 return;
60 }
61
62 }
63 holds.remove(dead);
64 }
65 int getHoldCount(){
66 return holds.size();
67 }
68 }
This page was automatically generated by Maven