1 4 package com.nightlabs.ipanema.accounting; 5 6 import com.nightlabs.ipanema.trade.LegalEntity; 7 import com.nightlabs.ipanema.transfer.Anchor; 8 import com.nightlabs.ipanema.transfer.Transfer; 9 10 21 public class Account extends Anchor 22 { 23 26 public static final String PARTNER_ACCOUNT_TYPE_VENDOR = "Vendor"; 27 30 public static final String PARTNER_ACCOUNT_TYPE_CUSTOMER = "Customer"; 31 32 33 private LegalEntity owner; 34 private Currency currency; 35 private long balance = 0; 36 private boolean statistical; 38 39 protected Account() { } 40 41 public Account(String organisationID, String anchorID, Currency currency, boolean statistical) { 42 super(organisationID, anchorID); 43 44 if (currency == null) 45 throw new NullPointerException ("currency must not be null!"); 46 47 this.currency = currency; 48 } 49 65 public long getBalance() 66 { 67 return balance; 68 } 69 72 public Currency getCurrency() 73 { 74 return currency; 75 } 76 83 public boolean isStatistical() 84 { 85 return statistical; 86 } 87 88 93 protected void internalBookTransfer(Transfer transfer) 94 { 95 if (transfer == null) 96 throw new NullPointerException ("transfer must not be null!"); 97 98 if (!(transfer instanceof MoneyTransfer)) 99 throw new ClassCastException ("Account cannot book another Transfer (\""+transfer.getPrimaryKey()+"\" with type "+transfer.getClass().getName()+") than MoneyTransfer!"); 100 101 MoneyTransfer mt = (MoneyTransfer) transfer; 102 103 if (!mt.getCurrency().getCurrencyID().equals(this.getCurrency().getCurrencyID())) 104 throw new IllegalArgumentException ("Attempt to book MoneyTransfer with different currency than currency of this Account!"); 105 106 boolean isDebit = mt.getFrom().getPrimaryKey().equals(this.getPrimaryKey()); 107 108 if (isDebit) 109 this.balance -= mt.getAmount(); 110 else 111 this.balance += mt.getAmount(); 112 } 113 114 public LegalEntity getOwner() { 115 return owner; 116 } 117 118 public void setOwner(LegalEntity owner) { 119 this.owner = owner; 120 } 121 } 122 | Popular Tags |