//Resilience and Continuous Analysis v2

//Finished and removed single nested loop (advised by chatGPT to reduce time complexity). Also removed if statement identifed previously. 
//Tested code but not extensively.
//It was created based on refinement from several attempts (notably obtaining positive changes in Test case 28)
//And feeding it back into earlier iteration
//All Programiz challenge test cases have passed

//ALL FORMATTED INDENTED CORRECTLY
//TERMS Matrix A and Matrix B will be used to discuss the pairing of the first and second matrix in transaction

//ALSO NOTE, in my comments, there is reference to Matrix A, Matrix B, Matrix C
//In absence of a Matrix C (references are to Matrix A and Matrix B)
//In presence of Matrix C (references are to Matrix A, Matrix B, Matrix C, Matrix, B, Matrix C........)

//ANY CATCH STATEMENT WHICH REQUIRES A MORE USER FRIENDLY MESSAGE CAN INCLUDE ONE OF THESE (IF REQUIRED)
/*
System.out.println("2Matrix("+(counter)+")" + "   row:" + ee +"\thas no content at index["+m+"]");
System.out.println("Hence can not perform multiplication with Matrix("+(counter+1)+")" + "   row:" + (rowCounterNextMatrix+1)+"\t" 
+  "  index["+z+"]: " + rowInfo.get(z));


System.out.println("1Matrix("+(counter)+")" + "   row:" + rowCounterFirstMatrix+"\t" +  "value at index["+z+"]: " + ee.get(posPrevMatrixRowLevel) 
+"  has no available supporting entry in \nMatrix("+(counter+1)+")" + "   row:" + (rowCounterNextMatrix+1)+"\t" +  "\t index["+z+"]: " + " row content:" + rowInfo);
*/


/*
//**********USAGE*************************
BEFORE CONFIGURING TEST CASES REMEMBER THESE CRITERIA AS MINIMUM:

Numbers columms in Matrix A/C  = Number rows in Matrix B 
Jagged arrays supported under validation rules
Size of largest row (number columns) in Matrix A/C and number rows in Matrix B will ALWAYS determine matrixMultiplication size 
//**********************************
*/

import java.util.*;

public class Solution 
{   
    static List<List<Integer>> matrix = new ArrayList<>();
    static List<List <Integer>> nextMatrix;
    
    public static void main (String [] args)
    {
        List <List<List<Integer>>> testMatrix = new ArrayList<>(); 
        
        //TEST CASES
        //We have to ensure that the test case is a 3d array as oppose to a 2d array to contain all the matrixes
        //Integer [][][]test = new Integer[][][] {   {{1},{5}},{{9,88}}};
        
        //Only 1 matrix defined
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}}}; 
        
        //As per challenge  - Test Case 1
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16} } }; 
        
        //Adaptation  Test Case 1
        //Integer [][][]test = new Integer[][][] {   {{1,2,3,5,6},{4,5,6}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16} } }; 
        
        //As per challenge  - Test Case 2
        //Integer [][][]test = new Integer[][][] {   {{1,2,3,4}},{{5},{6},{7},{8}}};
        
        //As per challenge  - Test Case 3/4  (both same)
        //Integer [][][]test = new Integer[][][] {   {{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}, {{9, 10}, {11, 12}}  };
        
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{10},{11,12}},  { {13,14}, {15,16} } };
        
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document) 
        //This relies on the matrixMultiplication initialisation
        Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8,999},{10,11},{11,12}},  { {13,14}, {15,16} } }; 
       
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5}},  {{7,8},{10,11},{11,12}},  { {13,14,17}, {15,16} } }; 
        
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document) 
        //Integer [][][]test = new Integer[][][] {   {{1,2},{4,5,6}},  {{7,8},{10,11},{11,12}},  { {13,14,17}, {15,16,17} } }; 
        
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //This will get picked up on area of code I had written towards bottom part of code
        //Integer [][][]test = new Integer[][][] {   {{},{4,5,6}},  {{7,8,6},{10,14},{11,12}},  { {13}, {15,16} } }; 
    
        //HERE!!!!!!!!!!!!!!!!!!!!!!!! - NEED TO CHECK THIS!!!!
        //Integer [][][]test = new Integer[][][] {   {{1,2},{3,4},{5,6}},  {{7,8},{10,14},{0}},  { {13}, {15,16} } }; 
        
        //With this test case it has not performed jump to new column
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{9,10},{11,12}},  { {0}, {16,17},{5}} }; 
        
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{9,10},{11}},  { {13,14}, {16,17} } }; 
        
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document) 
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{9,2},{11,12}},  { {13,14}, {16,87},{3,4} } }; 
    
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{},{10,14},{11,12}},  { {13}, {15,16} } }; 
       
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{1,7},{25,14},{}},  { {13,15}, {15,16} } };
        
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //This will be handled validation in later part of code
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{}},  {{1,7},{25,14},{4,8}},  { {13,15}, {15,16} } }; 
       
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{1,7},{25,14},{4,8}},  { {}, {15,16} } }; 
       
        //TEST CASES EXPLORING JAGGED ARRAYS (variants of TEST CASE 28 IN Document)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{1,7},{25,14},{4,8}},  { {34,45}, {} } }; 
        
        //TEST CASES EXPLORING JAGGED ARRAYS (TEST CASE 28 IN Document exactly)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8,6},{10,14},{11,12}},  { {13,14}, {15,16} } }; 
       
        //TEST CASES EXPLORING JAGGED ARRAYS (TEST CASE 28 IN Document exactly)
        //But it is error free, so informed end user excess numbers
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6,9}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16} } };
        
        //TEST CASES EXPLORING JAGGED ARRAYS BUT EXPLORING CHANGES IN MATRIX A (TEST CASE 28 IN Document exactly)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16} } };
        
        //TEST CASES EXPLORING JAGGED ARRAYS BUT EXPLORING CHANGES IN MATRIX A (TEST CASE 28 IN Document exactly)
        //But it is error free, so informed end user excess numbers
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,7,2,6}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16} } };
         
        //TEST CASES EXPLORING JAGGED ARRAYS (TEST CASE 28 IN Document exactly)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{},{10,14},{11,12}},  { {13,14}, {15,16} } };
       
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{11,14},{},{19,12}},  { {13,14}, {15,16} } }; 
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{11,14},{44,55},{19,12}},  { {13,14}, {} } };
        
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{11,14},{44,55},{19,12}},  { {13,14}, {0} } }; 
       
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{11,14},{44,55},{19,12}},  { {13,14}, {0,5},{0} } }; 
        
        //TEST CASES EXPLORING JAGGED ARRAYS (TEST CASE 28 IN Document exactly)
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{10,14},{11,12}},  { {13}, {15,16} } }; 
       
        //ADDITIONAL TEST CASES
        
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{11,14},{44,55},{19,12}},  { {13,14}, {0} } }; 
        
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{10,14},{15,12,65,55}},  { {13,99}, {15,16} } }; 
             
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6},{7,8,9}},  {{10,11,12},{13,14,15},{16,17,18}},  { {}, {22,23,24}} };
        
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16} },    { {17,18}, {19,20} },{ {17,18}, {19,20} }}; 
        
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6}},  {{7,8},{9,10},{11,12}},  { {13,14}, {15,16}},  { {17,18}, {19,20},{99,18}, {19,20}}, { {21,22,23,24}, {25,26,27,28},{29,30,31,32}} };
                                                                                            
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6},{7,8,9}},  {{10,11,12},{13,14,15},{16,17,18}},  { {19,20,21}, {22,23,24}} };
        
        //active
        //Integer [][][]test = new Integer[][][] {   {{1,2,3},{4,5,6},{7,8,9}},  {{11,12},{13,14,15},{16,17,18}} };
        
        //Integer [][][]test = new Integer[][][] {   {{},{4,5,6},{7,8,9}},  {{10,11,12},{13,14,15},{16,17,18}} };
        
        //***********AI generates test cases  v3.4***********************************
        //Integer[][][] test = new Integer[][][] {{{1,2,3},{4,5,6},{7,8,9}},{{9,8,7},{6,5,4},{3,2,1}}};
        
        //Integer[][][] test = new Integer[][][] {{{1},{2,3},{4,5,6}},{{6,7},{8,9},{10,11}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2}},{{3},{4}},{{5,6}},{{7},{8}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3,4}},{{5},{6},{7},{8}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,null,3},{4,5,null}},{{7,8},{9,10},{11,12}}};
        
        //Integer[][][] test = new Integer[][][] {{{}},{{1,2},{3,4}}};
        
        //Integer[][][] test = new Integer[][][] {{{1},{2},{3},{4}},{{1,2,3,4}}};
        
        //Integer[][][] test = new Integer[][][] {{{1}},{{2,3}},{{4},{5},{6}},{{7,8,9}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2},{3,4}},{{1,2},{3,4}},{{1,2},{3,4}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3,4,5}},{{6},{7},{8},{9},{10}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2},{3}},{{4,5,6}},{{7},{8,9}}};

        //Integer[][][] test = new Integer[][][] {{{1}},{{2}},{{3}},{{4}},{{5}}};
        
        //Integer[][][] test = new Integer[][][] {{{},{1,2}},{{3},{4,5}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5}},{{1,2},{3,4},{5,6},{7,8},{9,10}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2},{3}},{{4,5},{6,7},{8,9}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2},{3,4}},{{5,6,7},{8,9,10}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2}},{{}},{{3,4}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3},{4,5}},{{6},{7},{8}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,null,3,4},{5,6,null,8}},{{9,10},{11,12},{13,14},{15,16}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2}},{{3,4,5}},{{6,7}}};
        
        //Integer[][][] test = new Integer[][][] {{{5}},{{6}},{{7}}};
        
        //Integer[][][] test = new Integer[][][] {{{0,0,0},{null,0}},{{0},{0},{0}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3,4}},{{1},{null},{3},{4}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2},{3,4,5},{6}},{{7},{8},{9}}};
        
        //Integer[][][] test = new Integer[][][] {{{10,11,12},{13,14,15}},{{2,3},{4,5},{6,7}},{{1},{2}}};

        //Integer[][][] test = new Integer[][][] {{{1,2}},{{},{}},{{3,4}}};

        //Integer[][][] test = new Integer[][][] {{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}},{{16,15,14,13},{12,11,10,9},{8,7,6,5},{4,3,2,1}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3},{},{4,5}},{{6},{7,8},{9,10,11}}};
        
        //Integer[][][] test = new Integer[][][] {{{1,2,3},{4,5,6}},{{7},{8},{9}}};
        
        //Integer[][][] test = new Integer[][][] {{{3,1,8,null,0}},{{9}}};

        
        System.out.println("***********ENFORCES Resilience and Continuous Analysis***********");
        
        
        for (Integer [][] item: test)
        {
            matrix = new ArrayList<>();
            
            for (Integer [] row: item)
            {
                matrix.add(Arrays.asList(row));
            }
            testMatrix.add(matrix);
        }
        
        System.out.println("\n\n***FINAL OUTCOME***: \n" + matrixMultiplication(testMatrix));
    }
    
    public static List<List<Integer>> matrixMultiplication(List<List<List<Integer>>> matrices) 
    {
        List<Integer> rowInfo = new ArrayList<>();
                            
        int rowCounterNextMatrix;
        int seekPosition=0;        
        int numWritesAtIndexWithinMultiplicationMatrix;
        
        StringJoiner matrixRowCalculations = new StringJoiner("");
        StringJoiner excessRowItems=new StringJoiner(",");
        
        String rowMatrix=null;
        String currentEntry=null;
        String prevEntry=null;
        
        StringJoiner excessRowReport = new StringJoiner("\n");
        StringJoiner excessColReport = new StringJoiner("\n");
        StringJoiner [][] matrixMultiplicationCalculations=null;
        int numWritesToLastIndexOnRowMultiplicationMatrix;
        boolean hasReachedEndRow=false;
        boolean hasStartedMultiplication=false;
        Integer multiplication=0;
        
        int rowCounterFirstMatrix=0;
        int rowsNextMatrix=0;
        int matricesSize=matrices.size();
        
        int counter=0;
        
        int numElementsInRow=0;
        int posPrevMatrixRowLevel=0;
        int numMatrixes=0;
        
        //-------------------------------------------------------------------------------------------
        //This has been included to support 'resilience and continuous analysis'
        //We need to get longest row (most columns) to maximise calculations.
        //swapping references of nextMatrix.get(0).size() with maximumColumns
        int maximumColumns = 0;
         
        Integer [][]matrixMultiplication = null;
        
        List <List<Integer>> matrixMultiplicationList = new ArrayList<>();
        
        String currentColumnEntry;
        
        StringJoiner excessColItems=new StringJoiner(",");

        System.out.println("***ALL MATRIX*******: " + matrices.size());
        
        do
        {
            matrix=matrices.get(numMatrixes);
            
            System.out.println("\nMatrix" +"("+numMatrixes+"):");

            for (List<Integer> row: matrix)
            {
                System.out.println(row);
            }
            numMatrixes++;
            
        }while(numMatrixes<matrices.size());
        
        System.out.println("\n\n\n");
        numMatrixes=0;
        
        do
        {
            matrix=matrices.get(counter);
           
            if (counter>0 && hasStartedMultiplication)
            {
                System.out.println("\n***SUMMARY****");
                System.out.println("Matrix multiplication: " + "Matrix ("+(counter-2)+") x Matrix ("+(counter-1)+")");
                
                if (matrices.size()!=2)
                {
                    System.out.println("ADDED Multiplication Matrix into the chain at index: " + (counter));
                    matrices.add(counter,matrixMultiplicationList);
                    hasStartedMultiplication=false;
                    System.out.println("Matrix("+counter+")");
                    
                    for (Integer []m: matrixMultiplication)
                    {
                        System.out.println(Arrays.toString(m));
                        
                        matrixMultiplicationList.add(Arrays.asList(m));
                    }
                    
                    System.out.println("\n***CALCULATION STEPS*******");
                    
                    for (int q=0; q<matrixMultiplicationCalculations.length; q++)
                    {
                        matrixRowCalculations = new StringJoiner("   ");
                
                        for (int r=0; r<matrixMultiplicationCalculations[0].length; r++)
                        {
                            matrixRowCalculations.add(" ["+matrixMultiplicationCalculations[q][r]+"]");
                        }
                        System.out.println(matrixRowCalculations);
                    }
                    System.out.println("\nIt will perform: " + "Matrix("+counter+")   x  Matrix("+(counter+1)+")");
                    
                    for (List<Integer> w: matrices.get((counter+1)))
                    {
                        System.out.println("\t\t\t\t"+String.valueOf(w));
                    }
                    
                    matricesSize=matrices.size();
                    matrix=matrices.get(counter);
                }
            } 
            System.out.println("\n\n------Matrix" +"("+counter+"):");
            matrix=matrices.get(counter);
            
            for (List<Integer> row: matrix)
            {
                System.out.println(row);
            }
            
            matrixMultiplicationList = new ArrayList<>();
            
            try
            {
                nextMatrix=matrices.get(counter+1);
            }
            catch (IndexOutOfBoundsException e)
            {
                System.out.println("Single matrix only");
                matrix=matrices.get(counter);
                System.out.println("\n***CALCULATION STEPS*******");
            
                for (List<Integer> row: matrix)
                {
                    System.out.println(row);
                }
                System.exit(0);
            }
            
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            
            for (int j=0; j<nextMatrix.size();j++)
            {
                if (nextMatrix.get(j).size()>maximumColumns)
                {
                    maximumColumns=nextMatrix.get(j).size();
                }
            }
            //matrixMultiplicationCalculations=new StringJoiner[matrix.size()][nextMatrix.get(0).size()];
            matrixMultiplicationCalculations=new StringJoiner[matrix.size()][maximumColumns];
            
            System.out.println("Size of Matrix multiplication row: " + matrix.size());
            System.out.println("Size of Matrix multiplication columns: " + maximumColumns);
            
            System.out.println("*******Customising Storage Grid for Multiplication Matrix**********["+matrix.size()+"]["+maximumColumns+"]***************");
            
            for (int r=0; r<matrix.size(); r++)
            {
                for (int q=0; q<maximumColumns; q++)
                {
                    System.out.println("Configuring for index: " + r + "," + q);
                    matrixMultiplicationCalculations[r][q] = new StringJoiner("+");
                }
            }
            
            for (List<Integer> ee: matrix)
            {
                rowMatrix = String.valueOf(ee);
                System.out.println("THIS IS ROW COUNTER MATRIX("+counter+"): " + rowCounterFirstMatrix);
                System.out.println("------------------------------------------THIS IS ROW DATA MATRIX("+counter+"): " + ee);
                
                numWritesToLastIndexOnRowMultiplicationMatrix=0;
                hasReachedEndRow=false;
                
                for (int k=0; k<ee.size(); k++)
                {
                    if(counter!=matricesSize-1)
                    {
                        rowCounterNextMatrix=0;
                        
                        if (!hasStartedMultiplication)
                        {
                            System.out.println("****************************CONFIGURING SIZE FOR BLANK MULTIPLICATION MATRIX*******************************************");
                            matrixMultiplication = new Integer[matrix.size()][maximumColumns];
                                
                            System.out.println("Multiplication matrix (W=" + matrix.size()+")  x  (H=" + maximumColumns+")" 
                            + " configured to store Matrix " + counter + " x  Matrix " + (counter+1));
                                
                            try
                            {
                                for (int a = 0; a < matrix.size(); a++) 
                                {
                                    for (int b = 0; b < maximumColumns; b++) 
                                    {
                                        matrixMultiplication[a][b] = 0;
                                    }
                                }
                            }
                    //--------------------------------------------------------------------------------            
                            catch (ArrayIndexOutOfBoundsException e)
                            {
                                System.out.println("\n33The current dimension of matrixMultiplication: " 
                                + "["+matrix.size()+"]"+ "["+maximumColumns+"]");
                            }
                            hasStartedMultiplication=true;
                        }
                        
                        if (maximumColumns==0)
                        {
                            System.out.println("8The current dimension of matrixMultiplication: " 
                            + "["+matrix.size()+"]"+"["+maximumColumns+"]");
                            System.out.println("2It EXPECTS: " + maximumColumns + " elements per row");
                            System.out.println("Hence multiplication matrix has no width");
                            System.out.println("matrix" + "("+(counter+1)+")" + " row:" + rowCounterNextMatrix +  " " 
                            + nextMatrix.get(0) + " size: " + nextMatrix.get(0).size());
                            System.out.println(matrices);
                            
                            //This has been included to support 'resilience and continuous analysis'
                            //System.exit(0);
                        }
                        
                        for (int z=0; z<maximumColumns; z++)
                        {
                            System.out.println("\n*****************Column number: " + z);
                            posPrevMatrixRowLevel=0;
                            numWritesAtIndexWithinMultiplicationMatrix=0;
                                         
                            for (int m=0; m<nextMatrix.size(); m++)
                            {
                                for (int j=0;j<nextMatrix.get(m).size();j++)
                                {
                                                
                                    if (numWritesAtIndexWithinMultiplicationMatrix==nextMatrix.size())
                                    {
                                        System.out.println("****************************************************************");
                                        break;
                                    }
                                    else
                                    {
                                        System.out.println("retrieving row: " + rowCounterNextMatrix 
                                        + " from matrix (" + (counter+1)+")");    
                                    }        
                                    rowInfo=new ArrayList<>(nextMatrix.get(m));
                                    
                                    if (!hasReachedEndRow)
                                    {
                                        seekPosition=0;
                                        excessRowItems = new StringJoiner(",");
                                        
                                        if (rowInfo.size()!=matrixMultiplication[0].length)
                                        {
                                            currentEntry = "2Row length:" + rowInfo.size()+" (matrix" + "("+(counter+1)+") row:" 
                                            +rowCounterNextMatrix+ "   " + nextMatrix.get(m)+") "  
                                            + " inconsistent with length expectations" 
                                            + "("+matrixMultiplication[0].length+") in multiplcation matrix";
                                            
                                            if (!currentEntry.equals(prevEntry))
                                            {
                                                System.out.println(currentEntry);
                                                excessRowReport.add(currentEntry);
                                                
                                                for (int x: nextMatrix.get(m))
                                                {
                                                    seekPosition++;
                                                                                                                            
                                                    if (seekPosition>matrixMultiplication[0].length)
                                                    {
                                                        excessRowItems.add(String.valueOf(x));
                                                    }
                                                }
                                            }
                                        }
                                        
                                        prevEntry = currentEntry;
                                        
                                        if (seekPosition!=0)
                                        {
                                            System.out.println("["+excessRowItems+"] are exempt from multiplcation matrix");
                                            excessRowReport.add("["+excessRowItems+"] are exempt from multiplcation matrix");
                                            
                                            if(excessRowItems.toString().length()==0)
                                            {
                                                System.out.println("10The current dimension of matrixMultiplication: " 
                                                + "["+matrix.size()+"]"+"["+maximumColumns+"]");
                                                System.out.println("3It EXPECTS: " + maximumColumns + " elements per row");
                                                
                                                System.out.println("matrix" + "("+(counter+1)+")" + " row:" + rowCounterNextMatrix 
                                                +  " " + "(content:"+nextMatrix.get(m) +")" + " size:" + nextMatrix.get(m).size() 
                                                + " invalidates this");
                                                System.out.println(matrices);
                                            }
                                        }
                                        try
                                        {
                                            System.out.println("Matrix["+(counter+1)+"] \trow element["+z+"]: " + rowInfo.get(z) +"\t\t" + nextMatrix.get(m));
                                                        
                                        }
                                        catch (IndexOutOfBoundsException e)
                                        {
                                            System.out.println("\n24The current dimension of matrixMultiplication: " 
                                            + "["+maximumColumns+"]"+"["+matrix.size()+"]");
                                            System.out.println("4It EXPECTS: " + maximumColumns + " elements per row");
                                            System.out.println("matrix" + "("+(counter+1)+")" + " row:" + rowCounterNextMatrix 
                                            +  " " + nextMatrix.get(m) + " size: " + nextMatrix.get(m).size() + " invalidates this");
                                            System.out.println(matrices);
                                        }
                                                    
                                        try
                                        {
                                            System.out.println("Matrix["+counter+"] \trow element["+posPrevMatrixRowLevel+"]: " +ee.get(posPrevMatrixRowLevel) +"\t\t" + ee);
                                        }
                                        catch (ArrayIndexOutOfBoundsException e)
                                        {
                                            System.out.println("\n1The current dimension of matrixMultiplication: " 
                                            + "["+matrixMultiplication.length+"]"+"["+matrixMultiplication[0].length+"]");
                                            
                                            if (rowInfo.size()>matrixMultiplication.length)
                                            {
                                                System.out.println("--1Accessing matrix(" + counter+") row index: " 
                                                + rowCounterNextMatrix + " from " + nextMatrix.get(m) + " invalidates this");
                                                System.out.println("Remove " + nextMatrix.get(m) + " and rows beyond from matrix(" 
                                                + (counter+1)+") row index: " + m);
                                            }
                                	    
					                        if(ee.size()>matrixMultiplication.length)
                                            {
                                                System.out.println("--5It EXPECTS: " + matrix.size() + " elements per row");
                                                System.out.println("matrix" + "("+(counter)+")" + " row:" + rowCounterFirstMatrix 
                                                +  " " + matrix.get(rowCounterFirstMatrix) + " size: " 
                                                + matrix.get(rowCounterFirstMatrix).size() + " invalidates this");
                                            }
                                			
                                            //I do not expect this statement to be correct now since we are now using maxColumns
                                            //it might be matrixMultiplication[0].length but necessarily the case.
                                            /*		
                                            if(nextMatrix.get(m).size()>matrixMultiplication[0].length)
                                            {
                                                System.out.println("--6It EXPECTS: " + matrix.size() + " elements per row");
                                                System.out.println("matrix" + "("+(counter+1)+")" 
                                                + " row:" + rowCounterNextMatrix +  " " + nextMatrix.get(m) + " size: " 
                                                + nextMatrix.get(m).size() + " invalidates this");
                                            }
                                            */

                                            
                                            if (ee.size()<rowCounterNextMatrix)
                                            {
                                                System.out.println("--2Accessing matrix(" + counter+") row index: " 
                                                + rowCounterNextMatrix + " from " + ee + " invalidates this");
                                                System.out.println("Remove " + nextMatrix.get(m) 
                                                + " and rows beyond from matrix(" + (counter+1)+") row index: " + m);
                                                System.out.println(matrices);
                                                
                                                //has been included to support 'resilience and continuous analysis'
                                                //System.exit(0);
                                            }
                                        }
                                                    
                                        try
                                        {
                                            multiplication =  ee.get(posPrevMatrixRowLevel) *rowInfo.get(z);
                                        }
                                        
                                        //This catch block has been included to support 'resilience and continuous analysis'
                                        catch (NullPointerException q)
                                        {
                                            multiplication=0;
                                        }
                                        
                                        catch (ArrayIndexOutOfBoundsException e)
                                        {
                                            //This try block has been included to support 'resilience and continuous analysis'
                                            try
                                            {
                                                System.out.println("2Matrix("+(counter)+")" + "   row:" + ee +"\thas no content at index["+m+"]");
                                                System.out.println("Hence can not perform multiplication with Matrix("+(counter+1)+")" + "   row:" + (rowCounterNextMatrix+1)+"\t" 
                                                +  "  index["+z+"]: " + rowInfo.get(z));
                                            
                                                //This has been included to support 'resilience and continuous analysis'
                                                multiplication =  0;
                                            
                                                //This has been included to support 'resilience and continuous analysis'
                                                //System.exit(0);
                                            }
                                            //This has been included to support 'resilience and continuous analysis'
                                            catch(IndexOutOfBoundsException w)
                                            {
                                                
                                            }
                                        }
                                        
                                        catch (IndexOutOfBoundsException e)
                                        {
                                            System.out.println("1Matrix("+(counter)+")" + "   row:" + rowCounterFirstMatrix+"\t" +  "value at index["+z+"]: " + ee.get(posPrevMatrixRowLevel) 
                                            +"  has no available supporting entry in \nMatrix("+(counter+1)+")" + "   row:" + (rowCounterNextMatrix+1)+"\t" +  "\t index["+z+"]: " + " row content:" + rowInfo);
                                            
                                            //This has been included to support 'resilience and continuous analysis'
                                            multiplication =  0;
                                            
                                            //This has been included to support 'resilience and continuous analysis' 
                                            //System.exit(0);
                                        }
                                                    
                                        try
                                        {
                                            //This has been included to support 'resilience and continuous analysis' 
                                            System.out.println(ee.get(posPrevMatrixRowLevel) + " X " + rowInfo.get(z) + "= " + multiplication);
                                            matrixMultiplication[rowCounterFirstMatrix][z] = matrixMultiplication[rowCounterFirstMatrix][z]  
                                            + multiplication;
                                        }
                                        
                                        catch (ArrayIndexOutOfBoundsException e)
                                        {
                                            System.out.println("\n2The current dimension of matrixMultiplication: " 
                                            + "["+matrix.size()+"]"+"["+maximumColumns+"]");
                                            System.out.println("1It EXPECTS: " + maximumColumns + " elements per row");
                                            
                                            System.out.println("matrix" + "("+(counter+1)+")" + " row:" + rowCounterNextMatrix +  " " 
                                            + nextMatrix.get(m) + " size: " + nextMatrix.get(m).size() + " invalidates this");
                                            
                                            //This has been included to support 'resilience and continuous analysis'
                                            try
                                            {
                                                System.out.println("2Matrix("+(counter)+")" + "   row:" + rowCounterFirstMatrix+"\t" 
                                                +  "value at index["+z+"]: " + ee.get(posPrevMatrixRowLevel) 
                                                +"  has no available supporting entry in \nMatrix("+(counter+1)+")" + "   row:" 
                                                + (rowCounterNextMatrix+1)+"\t" +  "\t index["+z+"]: " + " row content:" + nextMatrix.get(m+1));
                                            }
                                            catch (ArrayIndexOutOfBoundsException r)
                                            {
                                                
                                            }
                                            
                                            //This has been included to support 'resilience and continuous analysis'
                                            //System.exit(0);
                                        }
                                        //This has been included to support 'resilience and continuous analysis'
                                        //it supports this new entry in the try block
                                        catch (IndexOutOfBoundsException d)
                                        {
                                            
                                        }
                                        System.out.println("Value in multiplication matrix: " 
                                        + matrixMultiplication[rowCounterFirstMatrix][z] + "\t\t" 
                                        + "["+rowCounterFirstMatrix+"],["+z+"]" );
                                        numWritesAtIndexWithinMultiplicationMatrix++;
                                        
                                        
                                        //This try/catch block has been included to support 'resilience and continuous analysis'
                                        try
                                        {
                                            matrixMultiplicationCalculations[rowCounterFirstMatrix][z].add("(" + ee.get(posPrevMatrixRowLevel) 
                                            + "x" +rowInfo.get(z) +" ="+String.valueOf(multiplication)+")");
                                        }
                                        catch (IndexOutOfBoundsException g)
                                        {
                                            
                                        }
                                        
                                        System.out.println(matrixMultiplicationCalculations[rowCounterFirstMatrix][z]+"\n");
                                        
                                        if (z==(matrixMultiplication[0].length-1))
                                        {
                                            numWritesToLastIndexOnRowMultiplicationMatrix++;
                                            
                                            if (numWritesToLastIndexOnRowMultiplicationMatrix==nextMatrix.size())
                                            {
                                                hasReachedEndRow=true;
                                            }
                                        }           
                                        posPrevMatrixRowLevel++;
                                        
                                        break;
                                    }
                                    else
                                    {
                                        System.out.println("---------------------------------------------------");
                                        System.out.println("previous written to each index location of multiplication matrix: " 
                                        + nextMatrix.size() + "  MAXIMUM times");
                                        System.out.println("---------------------------------------------------");
                                        
                                        j=nextMatrix.get(m).size();
                                        m=nextMatrix.size()-1;
                                    }
                                }
                                rowCounterNextMatrix=0;
                            }
                        }
                        System.out.println("Processed matrix("+(counter+1)+")  column("+k+")"+  " AGAINST " + "MATRIX("+counter+")  row("+rowCounterFirstMatrix+"): " + ee);
                    }
                    numElementsInRow++;
                }
                if(counter!=(matricesSize-1))
                {
                    for (List<Integer> rows: matrices.get((counter+1)))
                    {
                        rowsNextMatrix++;
                    }
                    if ((numElementsInRow!=rowsNextMatrix && numElementsInRow<matrices.get(counter+1).size()) || numElementsInRow==0)
                    {
                        System.out.println("INVALID VERIFICATION=>  columns " + "("+numElementsInRow+") in Matrix"  + "("+counter+")" 
                        + "(Row:" +rowCounterFirstMatrix + " content: " +  rowMatrix +  ") should match " 
                        +  rowsNextMatrix + " rows in matrix("+(counter+1)+")");
                        System.out.println(matrices);
                        //This try block has been included to support 'resilience and continuous analysis'
                        //System.exit(0);
                    }
                    else
                    {
                        System.out.println("VERIFICATION SUCCESSFUL(MATRIX("+counter+")  row("+rowCounterFirstMatrix+")) =>  ***COLUMNS" + "("+numElementsInRow+")\t   Matrix("+(counter+1)+") =>  ***ROWS("+rowsNextMatrix+")");
                        
                        excessColItems = new StringJoiner(",");
                        
                        if (numElementsInRow>nextMatrix.size())
                        {
                            currentColumnEntry = "columns" + "("+numElementsInRow+") in Matrix"  + "("+counter+")" 
                        + "(Row:" +rowCounterFirstMatrix + " content: " +  rowMatrix +  ") inconsistent with " 
                        +  rowsNextMatrix + " rows in matrix("+(counter+1)+").";
                            
                            System.out.println(currentColumnEntry);
                           
                           //This try/catch block has been included to support 'resilience and continuous analysis'
                            try
                            {
                                for (int x: matrix.get(rowCounterFirstMatrix))
                                {
                                    seekPosition++;
                                            
                                    if (seekPosition>rowsNextMatrix)
                                    {
                                        excessColItems.add(String.valueOf(x));
                                    }
                                }
                            }
                            catch (NullPointerException l)
                            {
                                System.out.println("null value found in row");
                            }
                            
                            if (seekPosition!=0)
                            {
                                System.out.println("["+excessColItems+"] are exempt from multiplcation matrix");
                                
                                excessColReport.add(currentColumnEntry);
                                excessColReport.add("["+excessColItems+"] are exempt from multiplcation matrix"+"\n");
                            }
                            seekPosition=0;
                        }
                    }
                    rowsNextMatrix=0;
                }
                numElementsInRow=0;
                rowCounterFirstMatrix++;
            }
            rowCounterFirstMatrix=0;
                    
            counter=counter+2;
            rowsNextMatrix=0;
        
        }while (counter<matricesSize);
        
        System.out.println("\nMatrix Multiplication");
        //This try/catch block has been included to support 'resilience and continuous analysis'
        try
        {
            for (Integer []m: matrixMultiplication)
            {
                System.out.println(Arrays.toString(m));
            }
        }
        catch (NullPointerException w)
        {
            
        }
        
        System.out.println("\n***CALCULATION STEPS*******");
    
        for (int q=0; q<matrixMultiplicationCalculations.length; q++)
        {
            matrixRowCalculations = new StringJoiner("");
                
            for (int r=0; r<matrixMultiplicationCalculations[0].length; r++)
            {
                matrixRowCalculations.add(" ["+matrixMultiplicationCalculations[q][r]+"]");
                    
            }
            System.out.println(matrixRowCalculations);
        }
        
        try
        {
            for (Integer []m: matrixMultiplication)
            {
                matrixMultiplicationList.add(Arrays.asList(m));
            }
        }
        catch (NullPointerException dd)
        {
            
        }
        
        System.out.println("\n-----MATRIX A   Analysis------");
        System.out.println(excessColReport);
        
        System.out.println("\n\n-----MATRIX B   Analysis------");
        System.out.println(excessRowReport);
        
        return matrixMultiplicationList;
    }
}