Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2011  |  syntax: Java  |  size: 1.15 KB  |  hits: 119  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. import java.util.ArrayList;
  3.  
  4. public class TransferManager {
  5.         private ArrayList<Transfer> openTransfers;
  6.         private int issuedTransfers;
  7.         private int performedTransfers;
  8.        
  9.         public TransferManager() {
  10.                 openTransfers = new ArrayList<Transfer>();
  11.                 issuedTransfers = 0;
  12.                 performedTransfers = 0;
  13.         }
  14.        
  15.         public void issueTransfer(Account from, Account to, int amount) {
  16.                 openTransfers.add(new Transfer(from, to, amount));
  17.                 issuedTransfers++;
  18.         }
  19.        
  20.         public void performTransfers() {
  21.                 for(Transfer transaction : openTransfers) {
  22.                         transaction.performTransfer();
  23.                         performedTransfers++;
  24.                 }              
  25.                 openTransfers.clear();
  26.         }
  27.        
  28.         @Override
  29.         public String toString() {
  30.                 return "TransferManager (openTransfers: " + openTransfers.size() + "; issuedTransfers: " + issuedTransfers + "; performedTransfers: " + performedTransfers + ")";
  31.         }
  32.        
  33.         private static class Transfer {
  34.                 private Account from, to;
  35.                 private int amount;
  36.                
  37.                 public Transfer(Account from, Account to, int amount) {
  38.                         this.from = from;
  39.                         this.to = to;
  40.                         this.amount = amount;
  41.                 }
  42.                
  43.                 public void performTransfer() {
  44.                         from.transfer(-amount);
  45.                         to.transfer(amount);
  46.                 }
  47.         }
  48. }