04fad3768b2e — Quintillus 2 months ago
Display profit/book and market cap info.
M src/main/java/com/ajtjp/gearcityuserinterface/controller/IndustryProfitabilityController.java +48 -18
@@ 6,17 6,18 @@ 
 package com.ajtjp.gearcityuserinterface.controller;
 
 import com.ajtjp.gearcitydata.AnnualFinancialResult;
+import com.ajtjp.gearcitydata.PBResult;
 import com.ajtjp.gearcitydata.SaveFile;
-import java.net.URL;
+import com.ajtjp.gearcityuserinterface.data.IndustryProfitabilityData;
 import java.text.DecimalFormat;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.ResourceBundle;
+import java.util.Optional;
 import javafx.beans.property.ReadOnlyObjectWrapper;
 import javafx.beans.property.SimpleStringProperty;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.fxml.FXML;
-import javafx.fxml.Initializable;
 import javafx.geometry.Pos;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;

          
@@ 43,10 44,12 @@ public class IndustryProfitabilityContro
     private SaveFile saveFile;
     
     
-    TableColumn<AnnualFinancialResult, Long> incomeColumn = new TableColumn<>();
-    TableColumn<AnnualFinancialResult, Long> expensesColumn = new TableColumn<>();
-    TableColumn<AnnualFinancialResult, Long> profitColumn = new TableColumn<>();
-    TableColumn<AnnualFinancialResult, Float> marginColumn = new TableColumn<>();
+    TableColumn<IndustryProfitabilityData, Long> incomeColumn = new TableColumn<>();
+    TableColumn<IndustryProfitabilityData, Long> expensesColumn = new TableColumn<>();
+    TableColumn<IndustryProfitabilityData, Long> profitColumn = new TableColumn<>();
+    TableColumn<IndustryProfitabilityData, Float> marginColumn = new TableColumn<>();
+    TableColumn<IndustryProfitabilityData, Float> marketCapColumn = new TableColumn<>();
+    TableColumn<IndustryProfitabilityData, Float> pbColumn = new TableColumn<>();
     
     @FXML
     private TableView tblYearlyProfitsAndLosses;

          
@@ 57,10 60,10 @@ public class IndustryProfitabilityContro
     @FXML
     public void initialize() {
         
-        Callback currencyFactory = new Callback<TableColumn<AnnualFinancialResult, Long>, TableCell<AnnualFinancialResult, Long>>() {
+        Callback currencyFactory = new Callback<TableColumn<IndustryProfitabilityData, Long>, TableCell<IndustryProfitabilityData, Long>>() {
             @Override
-            public TableCell<AnnualFinancialResult, Long> call(TableColumn<AnnualFinancialResult, Long> col) {
-                TableCell<AnnualFinancialResult, Long> cell = new TableCell<AnnualFinancialResult, Long>()  {
+            public TableCell<IndustryProfitabilityData, Long> call(TableColumn<IndustryProfitabilityData, Long> col) {
+                TableCell<IndustryProfitabilityData, Long> cell = new TableCell<IndustryProfitabilityData, Long>()  {
                     
                     @Override
                     protected void updateItem(Long item, boolean empty) {

          
@@ 82,10 85,10 @@ public class IndustryProfitabilityContro
         };
         
         
-        Callback percentFactory = new Callback<TableColumn<AnnualFinancialResult, Float>, TableCell<AnnualFinancialResult, Float>>() {
+        Callback percentFactory = new Callback<TableColumn<IndustryProfitabilityData, Float>, TableCell<IndustryProfitabilityData, Float>>() {
             @Override
-            public TableCell<AnnualFinancialResult, Float> call(TableColumn<AnnualFinancialResult, Float> col) {
-                TableCell<AnnualFinancialResult, Float> cell = new TableCell<AnnualFinancialResult, Float>()  {
+            public TableCell<IndustryProfitabilityData, Float> call(TableColumn<IndustryProfitabilityData, Float> col) {
+                TableCell<IndustryProfitabilityData, Float> cell = new TableCell<IndustryProfitabilityData, Float>()  {
                     
                     @Override
                     protected void updateItem(Float item, boolean empty) {

          
@@ 106,7 109,7 @@ public class IndustryProfitabilityContro
             }
         };
         
-        TableColumn<AnnualFinancialResult, String> companyColumn = new TableColumn<>();
+        TableColumn<IndustryProfitabilityData, String> companyColumn = new TableColumn<>();
         companyColumn.setText("Company");
         companyColumn.setCellValueFactory(cellData -> {
             return new SimpleStringProperty(cellData.getValue().getCompanyName());

          
@@ 139,12 142,27 @@ public class IndustryProfitabilityContro
         });
         marginColumn.setCellFactory(percentFactory);
         
+        marketCapColumn.setText("Market Cap");
+        marketCapColumn.setCellValueFactory(cellData -> {
+            return new ReadOnlyObjectWrapper(cellData.getValue().getMarketCap());
+        });
+        marketCapColumn.setCellFactory(currencyFactory);
+        
+        
+        pbColumn.setText("Price to Book");
+        pbColumn.setCellValueFactory(cellData -> {
+            return new ReadOnlyObjectWrapper(cellData.getValue().getPriceToBook());
+        });
+        pbColumn.setCellFactory(percentFactory);
+        
         
         tblYearlyProfitsAndLosses.getColumns().add(companyColumn);
         tblYearlyProfitsAndLosses.getColumns().add(incomeColumn);
         tblYearlyProfitsAndLosses.getColumns().add(expensesColumn);
         tblYearlyProfitsAndLosses.getColumns().add(profitColumn);
         tblYearlyProfitsAndLosses.getColumns().add(marginColumn);
+        tblYearlyProfitsAndLosses.getColumns().add(marketCapColumn);
+        tblYearlyProfitsAndLosses.getColumns().add(pbColumn);
         
     }
     

          
@@ 179,14 197,14 @@ public class IndustryProfitabilityContro
     }
 
     private void updateData() {
-        List<AnnualFinancialResult> results = saveFile.getAnnualProfitabilityForAllCompanies(year);
+        List<AnnualFinancialResult> afrResults = saveFile.getAnnualProfitabilityForAllCompanies(year);
         
         if (yearsIncluded > 1) {
             for (int i = 1; i < yearsIncluded; i++) {
                 List<AnnualFinancialResult> previousYearResults = saveFile.getAnnualProfitabilityForAllCompanies(year - i);
                 for (AnnualFinancialResult companyOldResult : previousYearResults) {
                     boolean foundOldResults = false;
-                    for (AnnualFinancialResult existing : results) {
+                    for (AnnualFinancialResult existing : afrResults) {
                         if (existing.getCompanyName().equals(companyOldResult.getCompanyName())) {
                             existing.setIncome(existing.getIncome() + companyOldResult.getIncome());
                             existing.setExpenses(existing.getExpenses() + companyOldResult.getExpenses());

          
@@ 197,13 215,25 @@ public class IndustryProfitabilityContro
                         }
                     }
                     if (!foundOldResults) {
-                        results.add(companyOldResult);
+                        afrResults.add(companyOldResult);
                     }
                 }
             }
         }
         
-        ObservableList ol = FXCollections.observableList(results);
+        List<IndustryProfitabilityData> ipd = new ArrayList<>();
+        List<PBResult> pbResults = saveFile.getMarketCapAndPB();
+        for (AnnualFinancialResult afr : afrResults) {
+            Optional<PBResult> matchingPB = pbResults.stream().filter(pbResult -> pbResult.getName().equals(afr.getCompanyName())).findFirst();
+            if (matchingPB.isPresent()) {
+                ipd.add(new IndustryProfitabilityData(afr, matchingPB.get()));
+            }
+            else {
+                ipd.add(new IndustryProfitabilityData(afr));
+            }
+        }
+        
+        ObservableList ol = FXCollections.observableList(ipd);
         this.tblYearlyProfitsAndLosses.setItems(ol);
         this.tblYearlyProfitsAndLosses.refresh();
         txtYear.setText(year + "");

          
A => src/main/java/com/ajtjp/gearcityuserinterface/data/IndustryProfitabilityData.java +60 -0
@@ 0,0 1,60 @@ 
+
+package com.ajtjp.gearcityuserinterface.data;
+
+import com.ajtjp.gearcitydata.AnnualFinancialResult;
+import com.ajtjp.gearcitydata.PBResult;
+
+/**
+ *
+ * @author Andrew
+ */
+public class IndustryProfitabilityData {
+    final private String companyName;
+    private long income;
+    private long expenses;
+    private long profit;
+    
+    private long marketCap;
+    private float priceToBook;
+    
+    public IndustryProfitabilityData(AnnualFinancialResult afr, PBResult pb) {
+        this.companyName = afr.getCompanyName();
+        this.income = afr.getIncome();
+        this.expenses = afr.getExpenses();
+        this.profit = afr.getProfit();
+        
+        this.marketCap = pb.getMarketCap();
+        this.priceToBook = pb.getPriceToBook();
+    }
+    
+    public IndustryProfitabilityData(AnnualFinancialResult afr) {
+        this.companyName = afr.getCompanyName();
+        this.income = afr.getIncome();
+        this.expenses = afr.getExpenses();
+        this.profit = afr.getProfit();
+    }
+
+    public String getCompanyName() {
+        return companyName;
+    }
+
+    public long getIncome() {
+        return income;
+    }
+
+    public long getExpenses() {
+        return expenses;
+    }
+
+    public long getProfit() {
+        return profit;
+    }
+
+    public long getMarketCap() {
+        return marketCap;
+    }
+
+    public float getPriceToBook() {
+        return priceToBook;
+    }
+}