/Users/johnr/Dropbox/johnrayworth.info/largeFilesOutsideJSR/__IB-Other/Other/IA-Solutions-2019/Guy/Product/Investor's Application IA Working Final Draft/src/investor/s/application/ia/SortAndSearchTransactions.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package investor.s.application.ia;
  7 
  8 import java.util.ArrayList;
  9 
 10 /**
 11  *
 12  * @author 17887
 13  */
 14 public class SortAndSearchTransactions {
 15     
 16     public static void main(String []args){
 17 
 18     }
 19 
 20     public void selectionSortOfTransactionsTime(ArrayList<Transaction> transactions) {
 21         for (int i = 0; i < transactions.size() - 1; i++) {
 22             int minIndex = i;      // Assumed index of smallest remaining value.
 23             for (int j = i + 1; j < transactions.size(); j++) {
 24                 if (transactions.get(j).getTimeStamp() < transactions.get(minIndex).getTimeStamp()) {
 25                     minIndex = j;  // Remember index of new minimum
 26                 }
 27             }
 28             if (minIndex != i) {
 29                 //Exchange current element with smallest remaining.
 30                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 31                 Transaction temp = transactions.get(i);
 32                 transactions.set(i, transactions.get(minIndex));
 33                 transactions.set(minIndex, temp);
 34             }
 35         }
 36     }
 37 
 38     public void selectionSortOFTransactionsMaxToMinTime(ArrayList<Transaction> transactions) {
 39         for (int i = 0; i < transactions.size() - 1; i++) {
 40             int maxIndex = i;      // Assumed index of largest remaining value.
 41             for (int j = i + 1; j < transactions.size(); j++) {
 42                 if (transactions.get(j).getTimeStamp() > transactions.get(maxIndex).getTimeStamp()) {
 43                     maxIndex = j;  // Remember index of new maximum
 44                 }
 45             }
 46             if (maxIndex != i) {
 47                 //Exchange current element with largest remaining.
 48                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 49                 Transaction temp = transactions.get(i);
 50                 transactions.set(i, transactions.get(maxIndex));
 51                 transactions.set(maxIndex, temp);
 52             }
 53         }
 54     }
 55     
 56     public void selectionSortOFTransactionsPrice(ArrayList<Transaction> transactions) {
 57         for (int i = 0; i < transactions.size() - 1; i++) {
 58             int minIndex = i;      // Assumed index of smallest remaining value.
 59             for (int j = i + 1; j < transactions.size(); j++) {
 60                 if (transactions.get(j).getPrice() < transactions.get(minIndex).getPrice()) {
 61                     minIndex = j;  // Remember index of new minimum
 62                 }
 63             }
 64             if (minIndex != i) {
 65                 //Exchange current element with smallest remaining.
 66                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 67                 Transaction temp = transactions.get(i);
 68                 transactions.set(i, transactions.get(minIndex));
 69                 transactions.set(minIndex, temp);
 70             }
 71         }
 72     }
 73 
 74     public void selectionSortOFTransactionsMaxToMinPrice(ArrayList<Transaction> transactions) {
 75         for (int i = 0; i < transactions.size() - 1; i++) {
 76             int maxIndex = i;      // Assumed index of largest remaining value.
 77             for (int j = i + 1; j < transactions.size(); j++) {
 78                 if (transactions.get(j).getPrice() > transactions.get(maxIndex).getPrice()) {
 79                     maxIndex = j;  // Remember index of new maximum
 80                 }
 81             }
 82             if (maxIndex != i) {
 83                 //Exchange current element with largest remaining.
 84                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 85                 Transaction temp = transactions.get(i);
 86                 transactions.set(i, transactions.get(maxIndex));
 87                 transactions.set(maxIndex, temp);
 88             }
 89         }
 90     }
 91     
 92     public void selectionSortOFTransactionsNumberOfShares(ArrayList<Transaction> transactions) {
 93         for (int i = 0; i < transactions.size() - 1; i++) {
 94             int minIndex = i;      // Assumed index of smallest remaining value.
 95             for (int j = i + 1; j < transactions.size(); j++) {
 96                 if (transactions.get(j).getNumberOfShares() < transactions.get(minIndex).getNumberOfShares()) {
 97                     minIndex = j;  // Remember index of new minimum
 98                 }
 99             }
100             if (minIndex != i) {
101                 //Exchange current element with smallest remaining.
102                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
103                 Transaction temp = transactions.get(i);
104                 transactions.set(i, transactions.get(minIndex));
105                 transactions.set(minIndex, temp);
106             }
107         }
108     }
109 
110     public void selectionSortOFTransactionsMaxToMinNumberOfShares(ArrayList<Transaction> transactions) {
111         for (int i = 0; i < transactions.size() - 1; i++) {
112             int maxIndex = i;      // Assumed index of largest remaining value.
113             for (int j = i + 1; j < transactions.size(); j++) {
114                 if (transactions.get(j).getNumberOfShares() > transactions.get(maxIndex).getNumberOfShares()) {
115                     maxIndex = j;  // Remember index of new maximum
116                 }
117             }
118             if (maxIndex != i) {
119                 //Exchange current element with largest remaining.
120                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
121                 Transaction temp = transactions.get(i);
122                 transactions.set(i, transactions.get(maxIndex));
123                 transactions.set(maxIndex, temp);
124             }
125         }
126     }
127     
128     public void selectionSortOFTransactionsTransactionProfit(ArrayList<Transaction> transactions) {
129         for (int i = 0; i < transactions.size() - 1; i++) {
130             int minIndex = i;      // Assumed index of smallest remaining value.
131             for (int j = i + 1; j < transactions.size(); j++) {
132                 if (transactions.get(j).getTransactionProfit() < transactions.get(minIndex).getTransactionProfit()) {
133                     minIndex = j;  // Remember index of new minimum
134                 }
135             }
136             if (minIndex != i) {
137                 //Exchange current element with smallest remaining.
138                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
139                 Transaction temp = transactions.get(i);
140                 transactions.set(i, transactions.get(minIndex));
141                 transactions.set(minIndex, temp);
142             }
143         }
144     }
145 
146     public void selectionSortOFTransactionsMaxToMinTransactionProfit(ArrayList<Transaction> transactions) {
147         for (int i = 0; i < transactions.size() - 1; i++) {
148             int maxIndex = i;      // Assumed index of largest remaining value.
149             for (int j = i + 1; j < transactions.size(); j++) {
150                 if (transactions.get(j).getTransactionProfit() > transactions.get(maxIndex).getTransactionProfit()) {
151                     maxIndex = j;  // Remember index of new maximum
152                 }
153             }
154             if (maxIndex != i) {
155                 //Exchange current element with largest remaining.
156                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
157                 Transaction temp = transactions.get(i);
158                 transactions.set(i, transactions.get(maxIndex));
159                 transactions.set(maxIndex, temp);
160             }
161         }
162     }
163 
164 }
165