Example usage for java.util ArrayList equals

List of usage examples for java.util ArrayList equals

Introduction

In this page you can find the example usage for java.util ArrayList equals.

Prototype

public boolean equals(Object o) 

Source Link

Usage

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Checks the contents of a multi color bar chart against the expected
 * values./* w w  w  .  j  av  a 2 s.c  om*/
 * 
 * @param userColumns
 * @param chartElementXpath
 * @param
 */

@SuppressWarnings("rawtypes")
private StringBuffer insightColorBarChartContentCheck(String chartName, String chartLocator,
        ArrayList<String> chartnames, ArrayList<String> chartvalues, ArrayList<String> chartpercentages,
        int startingele, int checkingColCount, HashMap<Integer, ArrayList> userColumns,
        String chartElementCapture, String chartElementXpath) {

    // Portlet content variables
    WebDriver driver = getDriver();
    ArrayList<String> chartelementnames = chartnames;
    ArrayList<String> chartelementvalues = chartvalues;
    // ArrayList<String> chartpercentage = chartpercentages;
    int startingelement = startingele;
    int arraycounter = 0;
    StringBuffer verificationErrors = new StringBuffer();
    int actCategoryCount = 0;
    int actElementCnt = 0;
    int elementOffset = 0;
    ArrayList<String> htmlElementNames = new ArrayList<String>();
    ArrayList<String> htmlElementValues = new ArrayList<String>();

    // chathura
    HashMap<Integer, ArrayList> htmlColumns = new HashMap<Integer, ArrayList>();
    ArrayList htmlColumnValues = new ArrayList();

    JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;

    Actions action = new Actions(driver);

    if (chartName.contains("text")) {

        elementOffset = 3;
    } else if (chartName.contains("img")) {

        elementOffset = 2;
    }

    List<WebElement> locateElementsThree = driver
            .findElements(By.xpath(chartName + "//child::*[position()=2 and name()='g']/child::*[position()=2 "
                    + "and name()='g']/child::*[name()='rect']"));

    actCategoryCount = locateElementsThree.size();

    List<WebElement> locateElementsFour = driver
            .findElements(By.xpath(chartName + "//child::*[position()=2 and name()='g']"));

    actElementCnt = locateElementsFour.size();

    int rectFormat = actCategoryCount / actElementCnt;
    // The first loop of the pie chart check

    for (int i = startingelement; i <= rectFormat; i++) {
        // Accessing the different colored elements in a bar
        // ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT
        // ELEMENT ELEMENT ELEMENT

        htmlElementNames = new ArrayList<String>();
        htmlElementValues = new ArrayList<String>();

        htmlColumnValues = new ArrayList<>();

        for (int colorFieldRect = i; colorFieldRect <= actCategoryCount; colorFieldRect += rectFormat) {

            try {
                try {

                    WebElement chartHeaderEle = driver.findElement(By.xpath(chartElementXpath));
                    jsExecutor.executeScript("var evObj = document.createEvent('MouseEvents');"
                            + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"
                            + "arguments[0].dispatchEvent(evObj);", chartHeaderEle);

                    WebElement element = driver.findElement(By.xpath(chartName
                            + "//child::*[position()=2 and name()='g']/child::*[position()=2 and name()='g']"));
                    jsExecutor.executeScript("var evObj = document.createEvent('MouseEvents');"
                            + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"
                            + "arguments[0].dispatchEvent(evObj);", element);
                    System.out.println(element);
                    Thread.sleep(500);

                    WebElement element2 = driver.findElement(By.xpath(chartName
                            + "//child::*[position()=2 and name()='g']/child::*[position()=2 and name()='g']/child::*[position()="
                            + colorFieldRect + " and name()='rect']"));
                    jsExecutor.executeScript("var evObj = document.createEvent('MouseEvents');"
                            + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"
                            + "arguments[0].dispatchEvent(evObj);", element2);
                    System.out.println(element2);
                    Thread.sleep(500);

                } catch (Exception ex) {
                    if (ex.getMessage().contains("Alert")) {
                        if (ex.getMessage().contains("Alert")) {

                            WebElement element3 = driver.findElement(By.xpath(chartName
                                    + "//child::*[position()=2 and name()='g']/child::*[position()=2 and name()='g']/child::*[position()="
                                    + colorFieldRect + " and name()='rect']"));
                            jsExecutor.executeScript("var evObj = document.createEvent('MouseEvents');"
                                    + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"
                                    + "arguments[0].dispatchEvent(evObj);", element3);

                        }

                    }
                }

                try {
                    driver.findElements(By.xpath(chartName + "//child::*[name()='g' and position()="
                            + (actElementCnt + elementOffset) + "]"));

                } catch (Error e) {
                    verificationErrors.append("\n" + e.toString());
                }
                try {
                    String chartstr12 =

                            driver.findElement(By.xpath(chartName
                                    + "/..//child::*[position()=1 and name()='svg']/child::*[name()='g' and position()="
                                    + (actElementCnt + elementOffset) + "]//*[name()='text' and position()=" + 1
                                    + "]")).getText();
                    System.out.println("chartstr12 : " + chartstr12);
                    htmlElementNames.add(chartstr12);

                } catch (Error e) {
                    verificationErrors.append("\n" + e.toString());
                }
                try {

                    String chartstr22 =

                            driver.findElement(By.xpath(chartName
                                    + "/..//child::*[position()=1 and name()='svg']/child::*[name()='g' and position()="
                                    + (actElementCnt + elementOffset) + "]//*[name()='text' and position()=" + 2
                                    + "]")).getText();
                    System.out.println("chartstr22 : " + chartstr22);

                    htmlElementValues.add(chartstr22);

                } catch (Error e) {
                    verificationErrors.append("\n" + e.toString());
                }
                arraycounter = arraycounter + 1;

            } catch (Error e) {
                verificationErrors.append("\n" + e.toString());
            } catch (Exception e1) {
                verificationErrors.append("\n" + e1.toString());
            }
        } // end of second for loop

        htmlColumnValues.add(htmlElementNames);
        htmlColumnValues.add(htmlElementValues);

        htmlColumns.put(i, htmlColumnValues);

    } // end of first for loop

    for (int i = 1; i <= userColumns.size(); i++) {

        int checkingHtmlColumn = -1;

        for (int j = 1; j <= htmlColumns.size(); j++) {

            if (((ArrayList) userColumns.get(i).get(0)).get(0)
                    .equals(((ArrayList) htmlColumns.get(j).get(0)).get(0))) {
                checkingHtmlColumn = j;
                break;
            }
        }
        // check if the
        if (checkingHtmlColumn < 0) {
            verificationErrors.append("\n Element :" + i + " Input column name : "
                    + ((ArrayList) userColumns.get(i).get(0)).get(0) + " cannot be found in the chart");
            continue;
        } else {
            ArrayList currUserColumnNames = ((ArrayList) userColumns.get(i).get(0));
            ArrayList currUserColumnValues = ((ArrayList) userColumns.get(i).get(1));
            ArrayList currHtmlColumnNames = ((ArrayList) htmlColumns.get(checkingHtmlColumn).get(0));
            ArrayList currHtmlColumnValues = ((ArrayList) htmlColumns.get(checkingHtmlColumn).get(1));

            for (int k = 0; k < currHtmlColumnValues.size(); k++) {
                if (currHtmlColumnValues.get(k).equals("0") || currHtmlColumnValues.get(k) == null) {

                    currHtmlColumnNames.remove(k);
                    currHtmlColumnValues.remove(k);
                    k--;
                }
            }
            // Checking the column names
            if (currHtmlColumnNames.equals(currUserColumnNames)) {

            } else {

                verificationErrors.append("\n Element :" + i + " Expected element names = "
                        + userColumns.get(i).get(0) + " are different from the " + "actual names : "
                        + htmlColumns.get(checkingHtmlColumn).get(0) + " | ");
            }
            // Checking the column values
            if (currHtmlColumnValues.equals(currUserColumnValues)) {

            } else {
                verificationErrors.append("\n Element :" + i + " Expected element values = "
                        + userColumns.get(i).get(1) + " are different from the " + "actual values : "
                        + htmlColumns.get(checkingHtmlColumn).get(1) + " | ");
            }

        }
    }

    return verificationErrors;
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

private void sort(ArrayList<String> l, String objectName, String type, String pattern, String order,
        boolean stopOnFailure, final Object[] customError) {

    for (int i = 0; i < l.size(); i++) {
        // System.out.println(l.get(i));

        if (l.get(i).equals("")) {
            l.set(i, " ");
        }/*  w ww .ja  v a  2s  .c o m*/
    }

    System.out.println("Unsorted ArrayList in Java : " + l);
    System.out.println("Order :" + order);
    System.out.println("Pattern :" + pattern);
    System.out.println("Type :" + type);
    List<String> listOrg = new ArrayList<String>();

    for (int i = 0; i < l.size(); i++) {
        listOrg.add(l.get(i).toString());
    }

    //////////////////////////////////////////////////////////////////////////

    if (type.equals("string")) {

        if ("ascending".equals(order) && "alphabetically".equals(pattern)) {

            //System.out.println("list"+l);
            //Collections.sort(l, ALPHA_ORDER); 
            Collections.sort(l, String.CASE_INSENSITIVE_ORDER);
            //System.out.println("Ordered list"+l);

            if (l.equals(listOrg)) {
                // System.out.println("In ascending Order alphabetically" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //  System.out.println("Not in ascending Order alphabetically" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("descending".equals(order) && "alphabetically".equals(pattern)) {

            // Collections.sort(l, ALPHA_ORDER);
            Collections.sort(l, String.CASE_INSENSITIVE_ORDER);

            //System.out.println("Ordered list"+l);
            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                //System.out.println("In descending Order alphabetically" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in descending Order alphabetically" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }
        } else if ("ascending".equals(order) && "1Aa".equals(pattern)) {

            Collections.sort(l, DiffSort.diffNaturalOrder1Aa);
            //Collections.sort(l);

            //System.out.println("Ordered list"+l);
            if (l.equals(listOrg)) {
                //System.out.println("In Ascending Order 1Aa" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Ascending Order 1Aa" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else if ("descending".equals(order) && "1Aa".equals(pattern)) {

            Collections.sort(l, DiffSort.diffNaturalOrder1Aa);

            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                //System.out.println("In Descending Order 1Aa" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Descending Order 1Aa" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("ascending".equals(order) && "Aa1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderAa1);

            //System.out.println("Ordered list"+l);
            if (l.equals(listOrg)) {
                //System.out.println("In Ascending Order Aa1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Ascending Order Aa1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("descending".equals(order) && "Aa1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderAa1);

            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                //System.out.println("In Descending Order Aa1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //  System.out.println("Not in Descending Order Aa1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("ascending".equals(order) && "aA1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderaA1);

            //System.out.println("Ordered list"+l);
            if (l.equals(listOrg)) {
                // System.out.println("In Ascending Order aA1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                // System.out.println("Not in Ascending Order aA1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else if ("descending".equals(order) && "aA1".equals(pattern)) {
            Collections.sort(l, DiffSort.diffNaturalOrderaA1);

            List<String> listDes = new ArrayList<String>();
            for (int i = l.size() - 1; i >= 0; i--) {
                // System.out.println(l.get(i).toString());
                //String s = (String) l.get( i ) ;
                listDes.add(l.get(i).toString());
            }

            //System.out.println("Ordered list"+listDes);
            if (listDes.equals(listOrg)) {
                // System.out.println("In Descending Order aA1" );

                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");

            } else {
                //System.out.println("Not in Descending Order aA1" );
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");

                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");

                }

            }

        } else {
            if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                        " Custom Error :" + generateCustomError(customError)
                                + " System generated Error : CHECK SORTING command  : Element (" + objectName
                                + ") not sorted");
                checkTrue(false, stopOnFailure,
                        " Custom Error :" + generateCustomError(customError)
                                + " System generated Error : CHECK SORTING command  : Element (" + objectName
                                + ") not sorted");

            } else {
                reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                        "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                checkTrue(false, stopOnFailure,
                        "CHECK SORTING command  : Element (" + objectName + ") not sorted");

            }
        }

        /////////////////////////////////////////////////////////////////////////////////////////
    } else if (type.equals("numeric")) {
        List<Double> DoublelistOrg = new ArrayList<Double>();
        List<Double> DoublelistTemp = new ArrayList<Double>();
        try {
            for (int i = 0; i < l.size(); i++) {
                // System.out.println(l.get(i));       Rs    
                String temp = l.get(i).replace(",", "");
                temp = temp.replace("", "");
                temp = temp.replace("Rs", "");
                temp = temp.replace("$", "");
                temp = temp.replace("", "");
                // System.out.println(temp);

                double value = Double.parseDouble(temp);
                DoublelistOrg.add(value);
                DoublelistTemp.add(value);

            }
        } catch (Exception e) {
            // e.printStackTrace();
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + type + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + type + ") not match");
        }

        // System.out.println(DoublelistOrg);

        if (order.equals("ascending")) {
            Collections.sort(DoublelistTemp);

            if (DoublelistTemp.equals(DoublelistOrg)) {
                // System.out.println("ascending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                //System.out.println("Not ascending"); 

                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else if (order.equals("descending")) {
            Collections.sort(DoublelistTemp);
            Collections.reverse(DoublelistTemp);

            if (DoublelistTemp.equals(DoublelistOrg)) {
                //  System.out.println("descending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                // System.out.println("Not descending"); 
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else {
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + order + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + order + ") not match");
        }

    } else if (type.equals("date")) {
        List<Date> datelistOrg = new ArrayList<Date>();
        List<Date> datelistTemp = new ArrayList<Date>();
        try {
            for (int i = 0; i < l.size(); i++) {
                // System.out.println(l.get(i));       Rs    
                SimpleDateFormat formatter = new SimpleDateFormat(pattern);
                String tempDate = l.get(i);
                //  System.out.println(l.get(i));

                Date date = formatter.parse(tempDate);
                // System.out.println(date);
                //System.out.println(formatter.format(date));
                datelistOrg.add(date);
                datelistTemp.add(date);
            }
        } catch (Exception e) {
            // e.printStackTrace();
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + type + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + type + ") not match");
        }

        //System.out.println( datelistOrg);

        if (order.equals("ascending")) {
            Collections.sort(datelistTemp);

            if (datelistTemp.equals(datelistOrg)) {
                // System.out.println("ascending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                //System.out.println("Not ascending"); 
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else if (order.equals("descending")) {
            Collections.sort(datelistTemp);
            Collections.reverse(datelistTemp);

            if (datelistTemp.equals(datelistOrg)) {
                //  System.out.println("descending");
                reportresult(true, "CHECK SORTING :", "PASSED",
                        "Check sorting command : Element " + objectName + " sorted");
            } else {
                // System.out.println("Not descending"); 
                if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            " Custom Error :" + generateCustomError(customError)
                                    + " System generated Error : CHECK SORTING command  : Element ("
                                    + objectName + ") not sorted");
                } else {
                    reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                    checkTrue(false, stopOnFailure,
                            "CHECK SORTING command  : Element (" + objectName + ") not sorted");
                }

            }

        } else {
            reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                    "CHECK SORTING command  : Element (" + order + ") not match");
            checkTrue(false, stopOnFailure, "CHECK SORTING command  : Element (" + order + ") not match");
        }

    } else {
        reportresult(true, "CHECK SORTING :" + objectName + "", "FAILED",
                "CHECK SORTING command  : Type (" + type + ") not match");
        checkTrue(false, stopOnFailure, "CHECK SORTING command  : Type (" + type + ") not match");
    }
}

From source file:main.java.workload.tpcc.TpccWorkload.java

@Override
// Creates a Tuple set for a specific transaction of type i
public Set<Integer> getTrTupleSet(Database db, int tr_type) {

    Set<Integer> trTupleSet = new HashSet<Integer>();

    ArrayList<Integer> trTupleList = new ArrayList<Integer>();
    ArrayList<Integer> tupleList = null;
    ArrayList<Integer> keyList;
    ArrayList<Integer> _cache_items = null;

    int tuple_nums, action = 0;
    int tpl_pk = Global.global_tupleSeq;
    int d_id = 0;
    int _w = 1, _i = 1, _d = 1, _s = 1, _c = 1, _o = 1, _no = 1, _ol = 1, cache_key = 1;

    //System.out.println("--> Generating a transaction of type "+tr_type+" ...");
    for (Entry<Integer, Table> tbl_entry : db.getDb_tables().entrySet()) {

        Table tbl = tbl_entry.getValue();

        tuple_nums = this.tr_tuple_distributions.get(tr_type).get(tbl.getTbl_id() - 1);
        action = this.tr_changes.get(tr_type).get(tbl.getTbl_id() - 1);

        //System.out.println("--> Table("+tbl.getTbl_name()+") | data = "+tbl.getTbl_tuples().size()+" | action = "+action+" | tuple_nums = "+tuple_nums);

        switch (action) {
        case 0:/*from   w  w w.j  ava 2 s. c om*/
            if (tbl.getTbl_tuples().size() == 1 && tuple_nums != 0) { // e.g. for <Warehouse> table; W=1                  
                for (Entry<Integer, Tuple> data : tbl.getTbl_tuples().entrySet()) {
                    trTupleSet.add(data.getValue().getTuple_pk());
                    _w = data.getValue().getTuple_pk();
                }
            } else {
                for (int d = 1; d <= tuple_nums; d++) {
                    //================new
                    switch (tbl.getTbl_name()) {
                    case TpccConstants.TBL_WAREHOUSE:
                        //_w = Global.rand.nextInt(tbl.getTbl_tuples().size())+1;
                        _w = tbl.zipfDistribution.sample();
                        tupleList = new ArrayList<Integer>();
                        tupleList.add(_w);

                        //System.out.println("\t\t--> W("+_w+")");
                        break;

                    case TpccConstants.TBL_ITEM:
                        _i = tbl.zipfDistribution.sample();

                        // Re-seeding to change Items' popularity
                        /*if(Sim.time() >= timer) {         
                           timer += timer;
                           tbl.zipfDistribution.reseedRandomGenerator(++seed);
                        }*/

                        tupleList = new ArrayList<Integer>();
                        tupleList.add(_i);

                        //System.out.println("\t\t--> I("+_i+")");
                        break;

                    case TpccConstants.TBL_DISTRICT:
                        if (tr_type <= 1 || this._cache.isEmpty()) {
                            keyList = new ArrayList<Integer>();
                            keyList.add(_w);
                            tupleList = tbl.getTableData(keyList);
                            _d = tupleList.get(1);
                        } else {
                            int index = Global.rand.nextInt(_cache.size());
                            cache_key = this._cache_keys.get(index);
                            _cache_items = this._cache.get(cache_key);

                            _d = _cache_items.get(0);
                            _c = _cache_items.get(1);
                            _o = _cache_items.get(2);
                            _no = _cache_items.get(3);
                            _ol = _cache_items.get(4);
                            _s = _cache_items.get(5);

                            //System.out.println("\t\t>> Retrieving cached data <D("+_d+")|C("+_c+")|O("+_o+")|NO("+_no+")|OL("+_ol+")|S("+_s+")>");

                            tupleList = new ArrayList<Integer>();
                            tupleList.add(_d);
                        }

                        //System.out.println("\t\t--> D("+_d+") for W("+_w+")");
                        break;

                    case TpccConstants.TBL_STOCK:
                        if (tr_type <= 1 || this._cache.isEmpty()) {
                            keyList = new ArrayList<Integer>();
                            keyList.add(_w);
                            keyList.add(_i);
                            tupleList = tbl.getTableData(keyList);
                            _s = tupleList.get(1);
                        } else {
                            tupleList = new ArrayList<Integer>();
                            tupleList.add(_s);
                        }

                        //System.out.println("\t\t--> S("+_s+") for W("+_w+") and I("+_i+")");
                        break;

                    case TpccConstants.TBL_CUSTOMER: // District Table
                        if (tr_type <= 1 || this._cache.isEmpty()) {
                            keyList = new ArrayList<Integer>();
                            keyList.add(_d);
                            tupleList = tbl.getTableData(keyList);
                            _c = tupleList.get(1);
                        } else {
                            _cache_items = new ArrayList<Integer>();
                            int index = Global.rand.nextInt(_cache.size());
                            cache_key = this._cache_keys.get(index);
                            _cache_items = this._cache.get(cache_key);

                            _d = _cache_items.get(0);
                            _c = _cache_items.get(1);
                            _o = _cache_items.get(2);
                            _no = _cache_items.get(3);
                            _ol = _cache_items.get(4);
                            _s = _cache_items.get(5);

                            //System.out.println("\t\t>> Retrieving cached data <D("+_d+")|C("+_c+")|O("+_o+")|NO("+_no+")|OL("+_ol+")|S("+_s+")>");

                            tupleList = new ArrayList<Integer>();
                            tupleList.add(_c);
                        }

                        //System.out.println("\t\t--> C("+_c+") for D("+_d+") -- "+tupleList.get(0));                              
                        break;

                    case TpccConstants.TBL_HISTORY: // Customer Table
                        // Nothing to do
                        break;

                    case TpccConstants.TBL_ORDERS:
                        if (tr_type <= 1 || this._cache.isEmpty()) {
                            keyList = new ArrayList<Integer>();
                            keyList.add(_c);
                            tupleList = tbl.getTableData(keyList);
                            _o = tupleList.get(1);
                        } else {
                            d_id = tbl.getTupleByPk(_o).getTuple_pk();
                            tupleList = new ArrayList<Integer>();
                            tupleList.add(d_id);
                            tupleList.add(_o);
                        }

                        //System.out.println("\t\t--> O("+_o+") for C("+_c+") -- "+tupleList.get(0));
                        break;

                    case TpccConstants.TBL_NEW_ORDER: // Customer Table (the last 1/3 values from the Order table)               
                        // Nothing to do
                        break;

                    case TpccConstants.TBL_ORDER_LINE: // Stock Table (10 most popular values from the Stock table)
                        keyList = new ArrayList<Integer>();
                        keyList.add(_s);
                        keyList.add(_o);
                        tupleList = tbl.getTableData(keyList);
                        _ol = tupleList.get(0);

                        //System.out.println("\t\t--> OL("+_ol+") for S("+_s+") and O("+_o+") -- "+tupleList.get(0));
                        break;
                    }

                    if (trTupleList.contains(tupleList.get(0)) && d > 1) {
                        --d;

                    } else {
                        trTupleList.add(tupleList.get(0));
                        //System.out.println("@ "+tupleList.get(0));
                        trTupleSet.add(tbl.getTupleByPk(tupleList.get(0)).getTuple_id());
                    }
                }
            }
            break;

        case 1: //===Insert Operation            
            // Create a new Tuple
            tpl_pk = tbl.getTbl_last_entry();
            ++tpl_pk;

            tbl.setTbl_last_entry(tpl_pk);
            ++Global.global_tupleSeq;

            // Insert
            Tuple tpl = db.insertTuple(tbl.getTbl_id(), tpl_pk);
            trTupleSet.add(tpl.getTuple_id()); // Add Tuple id

            if (!this.warmingup)
                tpl.setTuple_action(WorkloadConstants.TPL_INSERT);

            switch (tbl.getTbl_name()) {
            case (TpccConstants.TBL_HISTORY):
                //tpl.getTuple_fk().put(3, _d); // 3: District Table                  
                // 3: District Table
                if (tpl.getTuple_fk().containsKey(3))
                    tpl.getTuple_fk().get(3).add(_d);
                else {
                    Set<Integer> fkSet = new HashSet<Integer>();
                    fkSet.add(_d);
                    tpl.getTuple_fk().put(3, fkSet);
                }

                //tpl.getTuple_fk().put(5, _c); // 5: Customer Table
                // 5: Customer Table
                if (tpl.getTuple_fk().containsKey(5))
                    tpl.getTuple_fk().get(5).add(_c);
                else {
                    Set<Integer> fkSet = new HashSet<Integer>();
                    fkSet.add(_c);
                    tpl.getTuple_fk().put(5, fkSet);
                }

                //System.out.println("\t\t>> Inserting _h(x) for _c("+_c+") and _d("+_d+")");

                tbl.getIdx_multikey_dependent().put(_d, _c, tbl.getTbl_tuples().size());
                break;

            case (TpccConstants.TBL_ORDERS):
                _o = tbl.getTbl_last_entry();
                //System.out.println("\t\t>> Inserting _o("+_o+") for _c("+_c+") and _d("+_d+")");

                //tpl.getTuple_fk().put(5, _c); // 5: Customer Table

                // 5: Customer Table
                if (tpl.getTuple_fk().containsKey(5))
                    tpl.getTuple_fk().get(5).add(_c);
                else {
                    Set<Integer> fkSet = new HashSet<Integer>();
                    fkSet.add(_c);
                    tpl.getTuple_fk().put(5, fkSet);
                }

                // Insert into Index
                tbl.insertSecondaryIdx(_c, _o);

                //=== Also put an entry in the New-Order and Order-Line Table                                          
                //=== New-Order
                Table _no_tbl = db.getTable(8);

                int _no_tpl_pk = _no_tbl.getTbl_last_entry();
                ++_no_tpl_pk;
                _no_tbl.setTbl_last_entry(_no_tpl_pk);

                ++Global.global_tupleSeq;

                // Insert                        
                Tuple _no_tpl = db.insertTuple(_no_tbl.getTbl_id(), _no_tpl_pk);
                trTupleSet.add(_no_tpl.getTuple_id()); // Add Tuple id

                if (!this.warmingup)
                    _no_tpl.setTuple_action(WorkloadConstants.TPL_INSERT);

                _no = _no_tbl.getTbl_last_entry();
                _no_tpl.setTuple_pk(_no);
                //_no_tpl.getTuple_fk().put(7, _o); // 7: Orders Table                  

                // 7: Orders Table
                if (tpl.getTuple_fk().containsKey(7))
                    tpl.getTuple_fk().get(7).add(_o);
                else {
                    Set<Integer> fkSet = new HashSet<Integer>();
                    fkSet.add(_o);
                    tpl.getTuple_fk().put(7, fkSet);
                }

                //System.out.println("\t\t>> Inserting _no("+_no+") for _o("+_o+")");

                // Insert into Index
                _no_tbl.insertSecondaryIdx(_o, _no_tpl_pk);

                //=== Order-Line
                Table _ol_tbl = db.getTable(9);

                int _ol_tpl_pk = _ol_tbl.getTbl_last_entry();
                ++_ol_tpl_pk;
                _ol_tbl.setTbl_last_entry(_ol_tpl_pk); // Add Tuple id

                ++Global.global_tupleSeq;

                // Insert                        
                Tuple _ol_tpl = db.insertTuple(_ol_tbl.getTbl_id(), _ol_tpl_pk);
                trTupleSet.add(_ol_tpl.getTuple_id());
                if (!this.warmingup)
                    _ol_tpl.setTuple_action(WorkloadConstants.TPL_INSERT);

                _ol = _ol_tbl.getTbl_last_entry();
                _ol_tpl.setTuple_pk(_ol);
                //_ol_tpl.getTuple_fk().put(4, _s); // 4: Stock Table

                // 4: Stock Table
                if (tpl.getTuple_fk().containsKey(4))
                    tpl.getTuple_fk().get(4).add(_s);
                else {
                    Set<Integer> fkSet = new HashSet<Integer>();
                    fkSet.add(_s);
                    tpl.getTuple_fk().put(4, fkSet);
                }

                //_ol_tpl.getTuple_fk().put(7, _o); // 7: Orders Table
                // 7: Orders Table
                if (tpl.getTuple_fk().containsKey(7))
                    tpl.getTuple_fk().get(7).add(_o);
                else {
                    Set<Integer> fkSet = new HashSet<Integer>();
                    fkSet.add(_o);
                    tpl.getTuple_fk().put(7, fkSet);
                }

                //System.out.println("\t\t>> Inserting _ol("+_ol+"|"+ol_tuple_pk+"|"+_ol_tpl.getData_pk()+") for _s("+_s+") and _o("+_o+")");

                _ol_tbl.getIdx_multikey_dependent().put(_s, _o, _ol_tpl_pk);

                // Caching
                _cache_items = new ArrayList<Integer>();
                _cache_items.add(_d);
                _cache_items.add(_c);
                _cache_items.add(_o);
                _cache_items.add(_no);
                _cache_items.add(_ol);
                _cache_items.add(_s);

                boolean _cached = false;
                for (Entry<Integer, ArrayList<Integer>> entry : this._cache.entrySet()) {
                    if (_cache_items.equals(entry.getValue())) {
                        _cached = true;
                        break;
                    }
                }

                if (!_cached) {
                    this._cache.put(this._cache_id, _cache_items);
                    this._cache_keys.add(this._cache_id);
                    this._cache_id++;
                }

                //System.out.println("\t\t>> Caching D-"+_d+"|C-"+_c+"|O-"+_o+"|NO-"+_no+"|OL-"+_ol+"|S-"+_s);                     
                break;
            }

            break;

        case -1://===Delete Operation               
                //System.out.println("\t\t>> *** _d("+_d+")|_c("+_c+")|_o("+_o+")|_no("+_no+")|_ol("+_ol+")|_s("+_s+")");

            // Mark the Tuple as "delete"
            Tuple tuple = db.getTupleByPk(tbl.getTbl_id(), _no);
            trTupleSet.add(tuple.getTuple_id()); // Add Tuple id

            if (!this.warmingup)
                tuple.setTuple_action(WorkloadConstants.TPL_DELETE);

            // Remove from Table index
            tbl.getIdx_multivalue_secondary().remove(_o);

            // Remove from Database
            //db.deleteTupleByPk(tbl.getTbl_id(), _no);

            // Remove from Cache
            this._cache_keys.remove(new Integer(cache_key));
            this._cache.remove(cache_key);
            //System.out.println("\t\t@ Removed D("+_d+") from cache | index ("+cache_key+")"+"|cache size="+_cache.size());

            // Remove all occurrences the tuple from the workload transactions by its pk
            //deleteTupleFromWorkload(tbl.getTbl_id(), tpl_pk); // Actually not required. Will remove in future

            break;
        } //end--switch()
    } //end--for()

    return trTupleSet;
}