View Javadoc

1   // %4154424325:hoplugins.transfers.vo%
2   package hoplugins.transfers.vo;
3   
4   import java.util.Iterator;
5   import java.util.List;
6   
7   
8   /***
9    * Value Object representing totals information for a selection of transfers.
10   *
11   * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
12   */
13  public class TransferTotals {
14      //~ Instance fields ----------------------------------------------------------------------------
15  
16      private int number_buy;
17      private int number_sell;
18      private int total_buy_price;
19      private int total_buy_tsi;
20      private int total_sell_price;
21      private int total_sell_tsi;
22  
23      //~ Methods ------------------------------------------------------------------------------------
24  
25      /***
26       * Calculates the totals based on a list of transfers.
27       *
28       * @param transfers List of transfers
29       *
30       * @return TransferTotals object containing totals for the list of transfers.
31       */
32      public static TransferTotals calculateTotals(List transfers) {
33          final TransferTotals totals = new TransferTotals();
34  
35          for (Iterator iter = transfers.iterator(); iter.hasNext();) {
36              final PlayerTransfer transfer = (PlayerTransfer) iter.next();
37  
38              if (transfer.getType() == PlayerTransfer.BUY) {
39                  totals.number_buy++;
40                  totals.total_buy_price += transfer.getPrice();
41                  totals.total_buy_tsi += transfer.getTsi();
42              } else if (transfer.getType() == PlayerTransfer.SELL) {
43                  totals.number_sell++;
44                  totals.total_sell_price += transfer.getPrice();
45                  totals.total_sell_tsi += transfer.getTsi();
46              } else {
47                  totals.number_sell++;
48                  totals.total_sell_price += transfer.getPrice();
49                  totals.total_sell_tsi += transfer.getTsi();
50                  totals.number_buy++;
51                  totals.total_buy_price += transfer.getPrice();
52                  totals.total_buy_tsi += transfer.getTsi();
53              }
54          }
55  
56          return totals;
57      }
58  
59      /***
60       * Gets the number of BUY transfers
61       *
62       * @return Number of BUY transfers
63       */
64      public final int getAmountBuy() {
65          return number_buy;
66      }
67  
68      /***
69       * Gets the number of SELL transfers
70       *
71       * @return Number of SELL transfers
72       */
73      public final int getAmountSell() {
74          return number_sell;
75      }
76  
77      /***
78       * Gets the average price for BUY transfers
79       *
80       * @return Average price
81       */
82      public final double getBuyPriceAvg() {
83          if (number_buy > 0) {
84              return total_buy_price / number_buy;
85          } else {
86              return 0;
87          }
88      }
89  
90      /***
91       * Gets the total price for BUY transfers
92       *
93       * @return Total price
94       */
95      public final int getBuyPriceTotal() {
96          return total_buy_price;
97      }
98  
99      /***
100      * Gets the average TSI value for BUY transfers
101      *
102      * @return Average TSI value
103      */
104     public final double getBuyTsiAvg() {
105         if (number_buy > 0) {
106             return total_buy_tsi / number_buy;
107         } else {
108             return 0;
109         }
110     }
111 
112     /***
113      * Gets the total TSI value for BUY transfers
114      *
115      * @return Total TSI value
116      */
117     public final int getBuyTsiTotal() {
118         return total_buy_tsi;
119     }
120 
121     /***
122      * Gets the average price for SELL transfers
123      *
124      * @return Average price
125      */
126     public final double getSellPriceAvg() {
127         if (number_sell > 0) {
128             return total_sell_price / number_sell;
129         } else {
130             return 0;
131         }
132     }
133 
134     /***
135      * Gets the total price for SELL transfers
136      *
137      * @return Total price
138      */
139     public final int getSellPriceTotal() {
140         return total_sell_price;
141     }
142 
143     /***
144      * Gets the average TSI value for SELL transfers
145      *
146      * @return Average TSI value
147      */
148     public final double getSellTsiAvg() {
149         if (number_sell > 0) {
150             return total_sell_tsi / number_sell;
151         } else {
152             return 0;
153         }
154     }
155 
156     /***
157      * Gets the total TSI value for BUY transfers
158      *
159      * @return Total TSI value
160      */
161     public final int getSellTsiTotal() {
162         return total_sell_tsi;
163     }
164 }