Example usage for java.util ArrayList listIterator

List of usage examples for java.util ArrayList listIterator

Introduction

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

Prototype

public ListIterator<E> listIterator() 

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8DictionaryTable.java

public MSSBamDictionaryBuff[] readDerivedByDictTenantIdx(MSSBamAuthorization Authorization, long DictTenantId) {
    final String S_ProcName = "readDerivedByDictTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*w  ww  .  ja  va  2 s  .  c  om*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectDictionaryDistinctClassCode + "WHERE " + "dict.DictTenantId = "
                + Long.toString(DictTenantId) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamDictionaryBuff> resultList = new ArrayList<MSSBamDictionaryBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("DICT")) {
            MSSBamDictionaryBuff[] subList = readBuffByDictTenantIdx(Authorization, DictTenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("RMD")) {
            MSSBamMSSBamBuff[] subList = schema.getTableMSSBam().readBuffByDictTenantIdx(Authorization,
                    DictTenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamDictionaryBuff[0]));

}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8DictionaryTable.java

public MSSBamDictionaryBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
    final String S_ProcName = "readDerivedByScopeIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }// w w  w. jav a2s .  c o  m
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectDictionaryDistinctClassCode + "WHERE "
                + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ");
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamDictionaryBuff> resultList = new ArrayList<MSSBamDictionaryBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("DICT")) {
            MSSBamDictionaryBuff[] subList = readBuffByScopeIdx(Authorization, ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("RMD")) {
            MSSBamMSSBamBuff[] subList = schema.getTableMSSBam().readBuffByScopeIdx(Authorization, ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamDictionaryBuff[0]));

}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8DictionaryTable.java

public MSSBamDictionaryBuff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
    final String S_ProcName = "readDerivedByAuthorIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/* ww  w  .  j  a  v  a  2 s  .c o m*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectDictionaryDistinctClassCode + "WHERE "
                + ((AuthorId == null) ? "anyo.AuthorId is null "
                        : "anyo.AuthorId = " + AuthorId.toString() + " ");
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamDictionaryBuff> resultList = new ArrayList<MSSBamDictionaryBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("DICT")) {
            MSSBamDictionaryBuff[] subList = readBuffByAuthorIdx(Authorization, AuthorId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("RMD")) {
            MSSBamMSSBamBuff[] subList = schema.getTableMSSBam().readBuffByAuthorIdx(Authorization, AuthorId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamDictionaryBuff[0]));

}

From source file:net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl.java

@Override
public Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) {
    ListIterator<OFMatchReconcile> iter = ofmRcList.listIterator();
    while (iter.hasNext()) {
        OFMatchReconcile ofm = iter.next();

        // Remove the STOPPed flow.
        if (Command.STOP == reconcileFlow(ofm)) {
            iter.remove();//from w  w  w  .j a  v  a  2  s .c om
        }
    }

    if (ofmRcList.size() > 0) {
        return Command.CONTINUE;
    } else {
        return Command.STOP;
    }
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8LegalEntityTable.java

public MSSBamLegalEntityBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/* w w  w. j ava 2s  .c om*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectLegalEntityDistinctClassCode + "WHERE " + "anyo.TenantId = "
                + Long.toString(TenantId) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamLegalEntityBuff> resultList = new ArrayList<MSSBamLegalEntityBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("LENT")) {
            MSSBamLegalEntityBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("COM")) {
            MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("USR")) {
            MSSBamUserBuff[] subList = schema.getTableUser().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamLegalEntityBuff[0]));

}

From source file:com.aol.framework.helper.report.CustomizedReporter.java

synchronized private void generateModuleWiseTestReport(String testName, List<ISuite> suites, String newFileName,
        String passedModule, String nodeIp) throws IOException {
    final PrintWriter pw = TestHelper.createFileWriter(TestHelper.customReportDir + newFileName);

    startHtmlPage(pw);/*from  www . jav  a 2 s . c  om*/

    pw.println("<button class=\"sexybutton sexysimple sexylarge sexyblack\" onClick=\"location.href='"
            + passedModule + "-Overall-customized-report.html"
            + "'\"><span class=\"prev\">Back to Modulewise Test Execution Summary</span></button>");

    pw.println(
            "<br/><br/><br/><fieldset><legend><b>Modulewise Execution Details</b></legend><br/><table class=\"details\" cellspacing=0 cellpadding=0><tr><td><b>Test Name: </b></td><td>"
                    + testName + "</td></tr>");

    pw.println("<tr><td><b>Node IP: </b></td><td>" + nodeIp + "</td></tr></table></fieldset><br/><br/>");
    pw.println("<table id=\"myTable\" width=\"100%\" cellspacing=0 cellpadding=0 class=\"tablesorter\">");
    pw.println("<thead><tr><th>Module Name</th><th># Passed</th>" + "<th># Failed</th><th># Warning</th>"
            + "<th># Skipped</th><th># Total</th><th>Success Rate</th></tr></thead>");

    HashMap<String, ArrayList<ITestNGMethod>> moduleMap = new HashMap<String, ArrayList<ITestNGMethod>>();

    ITestContext overview = null;

    for (ISuite suite : suites) {
        Map<String, ISuiteResult> tests = suite.getResults();
        for (ISuiteResult r : tests.values()) {
            overview = r.getTestContext();
            if ((overview.getName()).equalsIgnoreCase(testName)) {
                ITestNGMethod[] testngMethods = overview.getAllTestMethods();

                ArrayList<HashMap<String, ITestNGMethod>> moduleMethods = new ArrayList<HashMap<String, ITestNGMethod>>();

                for (ITestNGMethod testngMethod : testngMethods) {
                    String[] groups = testngMethod.getGroups();
                    for (String group : groups) {
                        for (String module : TestHelper.MODULES) {
                            if (group.equalsIgnoreCase(module)) {
                                HashMap<String, ITestNGMethod> tempMap = new HashMap<String, ITestNGMethod>();
                                tempMap.put(module, testngMethod);
                                moduleMethods.add(tempMap);
                            }
                        }
                    }
                }

                for (String module : TestHelper.MODULES) {
                    ArrayList<ITestNGMethod> moduleTestMethods = new ArrayList<ITestNGMethod>();

                    Iterator<HashMap<String, ITestNGMethod>> it = moduleMethods.iterator();

                    while (it.hasNext()) {
                        String moduleName = "";
                        ITestNGMethod testMethod = null;

                        HashMap<String, ITestNGMethod> moduleWithTestMethod = it.next();
                        if (moduleWithTestMethod.containsKey(module)) {
                            moduleName = module;
                            testMethod = moduleWithTestMethod.get(module);
                        }

                        if (module.equalsIgnoreCase(moduleName)) {
                            moduleTestMethods.add(testMethod);
                        }
                    }

                    moduleMap.put(module, moduleTestMethods);
                }
            }
        }
    }

    Set<String> keySet = moduleMap.keySet();
    Iterator<String> it = keySet.iterator();

    for (ISuite suite : suites) {
        Map<String, ISuiteResult> tests = suite.getResults();
        for (ISuiteResult r : tests.values()) {
            overview = r.getTestContext();
            if ((overview.getName()).equalsIgnoreCase(testName)) {
                while (it.hasNext()) {
                    String moduleName = it.next();

                    int totalPassedMethods = 0;
                    int totalFailedMethods = 0;
                    int totalAutomationErrors = 0;
                    int totalSkippedMethods = 0;
                    int totalSkippedConfigurations = 0;
                    int totalFailedConfigurations = 0;

                    ArrayList<ITestNGMethod> values = moduleMap.get(moduleName);
                    ListIterator<ITestNGMethod> it2 = values.listIterator();

                    while (it2.hasNext()) {
                        ITestNGMethod method = it2.next();

                        int failedMethods = overview.getFailedTests().getResults(method).size();
                        int failedAutomationErrors = overview.getFailedButWithinSuccessPercentageTests()
                                .getResults(method).size();
                        int passedMethods = overview.getPassedTests().getResults(method).size();
                        int skippedMethods = overview.getSkippedTests().getResults(method).size();
                        int failedConfiguration = overview.getFailedConfigurations().getResults(method).size();
                        int skippedConfiguration = overview.getSkippedConfigurations().getResults(method)
                                .size();

                        totalPassedMethods += passedMethods;
                        totalFailedMethods += failedMethods;
                        totalAutomationErrors += failedAutomationErrors;
                        totalSkippedMethods += skippedMethods;
                        totalFailedConfigurations += failedConfiguration;
                        totalSkippedConfigurations += skippedConfiguration;

                    }

                    if (values.size() > 0) {
                        String fileName = testName + "-" + moduleName + "-customized-report.html";
                        try {
                            generateModuleTestMethodSummary(testName, moduleName, suites, fileName, values,
                                    nodeIp);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                        int totalMethods = totalPassedMethods + totalFailedMethods + totalAutomationErrors
                                + totalSkippedMethods;

                        NumberFormat nf = NumberFormat.getInstance();
                        nf.setMaximumFractionDigits(2);
                        nf.setGroupingUsed(false);

                        String passPercentage = getPercentage(nf, totalPassedMethods, totalMethods);

                        generateModulesRow(pw, fileName, moduleName, totalPassedMethods, totalFailedMethods,
                                totalAutomationErrors, totalSkippedMethods, totalSkippedConfigurations,
                                totalFailedConfigurations, totalMethods, passPercentage);
                    }
                }
                break;
            }
        }
    }

    pw.println("</table>");
    endHtmlPage(pw);
    pw.flush();
    pw.close();
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java

public MSSBamBaseDomainBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from w ww  .  ja  v a 2s .  co  m*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE " + "anyo.TenantId = "
                + Long.toString(TenantId) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamBaseDomainBuff> resultList = new ArrayList<MSSBamBaseDomainBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("BDM")) {
            MSSBamBaseDomainBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("DOM")) {
            MSSBamDomainBuff[] subList = schema.getTableDomain().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("LENT")) {
            MSSBamLegalEntityBuff[] subList = schema.getTableLegalEntity().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("COM")) {
            MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("USR")) {
            MSSBamUserBuff[] subList = schema.getTableUser().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("PRJ")) {
            MSSBamProjectBuff[] subList = schema.getTableProject().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("VER")) {
            MSSBamVersionBuff[] subList = schema.getTableVersion().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MJV")) {
            MSSBamMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MNV")) {
            MSSBamMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("TLD")) {
            MSSBamTLDBuff[] subList = schema.getTableTLD().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamBaseDomainBuff[0]));

}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8LegalEntityTable.java

public MSSBamLegalEntityBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
    final String S_ProcName = "readDerivedByScopeIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//w ww  . j  a v a2  s  .  c o  m
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectLegalEntityDistinctClassCode + "WHERE "
                + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ");
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamLegalEntityBuff> resultList = new ArrayList<MSSBamLegalEntityBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("LENT")) {
            MSSBamLegalEntityBuff[] subList = readBuffByScopeIdx(Authorization, ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("COM")) {
            MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByScopeIdx(Authorization, ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("USR")) {
            MSSBamUserBuff[] subList = schema.getTableUser().readBuffByScopeIdx(Authorization, ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamLegalEntityBuff[0]));

}

From source file:ffx.potential.MolecularAssembly.java

/**
 * <p>/*  w  ww.ja va2s  .c o m*/
 * sidePolymerCOM</p>
 */
public void sidePolymerCOM() {
    ArrayList residues = getResidueList();
    Residue r;

    ListIterator li;

    for (li = residues.listIterator(); li.hasNext();) {
        r = (Residue) li.next();
        r.logSideChainCOM();
    }
}

From source file:ipnat.skel.Strahler.java

/**
 * This method is called when the plugin is loaded.
 *
 * @param arg//from www. j  a va2 s . c  o m
 *            the arguments as specified in {@code plugins.config}
 *
 */
@Override
public void run(final String arg) {

    // Retrieve analysis image and its ROI
    srcImp = WindowManager.getCurrentImage();
    if (!validRequirements(srcImp))
        return;

    title = srcImp.getTitle();
    rootRoi = srcImp.getRoi();
    validRootRoi = (rootRoi != null && rootRoi.getType() == Roi.RECTANGLE);

    // TODO: 3D Roots are special. We need to:
    // 1) Check if ROI is associated with all slices or just one
    // 2) Ignore counts above/below the ROI, as needed
    // 3) Extend ip operations to stack
    if (srcImp.getNSlices() > 1) {
        final String warning = "3D images are currently supported with the following limitations:\n"
                + "    - 'Root-protecting' ROIs are not yet supported\n"
                + "    - Lengths are estimated from Z-projections\n \n"
                + "These issues will be addressed in future releases.";
        if (IJ.macroRunning())
            IJ.log(warning);
        else
            IJ.showMessage("Warning", warning);
        validRootRoi = false;
    }

    // Retrieve grayscale image for intensity-based pruning of skel. loops
    if (!getSettings())
        return;

    // Work on a skeletonized copy since we'll be modifing the image
    if (rootRoi != null)
        srcImp.killRoi();
    final ImagePlus imp = srcImp.duplicate();
    if (rootRoi != null)
        srcImp.setRoi(rootRoi);
    ip = imp.getProcessor();
    skeletonizeWithoutHermits(imp);

    // Initialize ResultsTable: main and detailed info
    final ResultsTable rt = Utils.getTable(STRAHLER_TABLE);
    final ResultsTable logrt = Utils.getTable(VERBOSE_TABLE);

    // Analyze root
    ImagePlus rootImp;
    ImageProcessor rootIp = null;
    SkeletonResult rootResult = null;
    ArrayList<Point> rootEndpointsList = null;
    int nRootEndpoints = 0, nRootJunctions = 0;

    if (validRootRoi && verbose) {

        // Duplicate entire canvas. Ignore tree(s) outside ROI
        rootImp = imp.duplicate();
        rootIp = rootImp.getProcessor();
        rootIp.setValue(0.0);
        rootIp.fillOutside(rootRoi);

        // Get root properties
        final AnalyzeSkeleton_ root = new AnalyzeSkeleton_();
        root.setup("", rootImp);
        rootResult = root.run(pruneChoice, false, false, grayscaleImp, true, false);
        rootImp.flush();

        // We assume ROI contains only end-point branches, slab voxels and
        // no junction points. We'll thus remove end-points at ROI
        // boundaries
        nRootJunctions = sum(rootResult.getJunctions());
        rootEndpointsList = rootResult.getListOfEndPoints();
        final ListIterator<Point> it = rootEndpointsList.listIterator();
        final Rectangle r = rootRoi.getBounds();
        while (it.hasNext()) {
            final Point p = it.next();
            if (p.x == r.x || p.y == r.y || p.x == (int) (r.x + r.getWidth() - 1)
                    || p.y == (int) (r.y + r.getHeight() - 1))
                it.remove();
        }
        rootResult.setListOfEndPoints(rootEndpointsList);
        nRootEndpoints = rootEndpointsList.size();

    }

    // Initialize display images. Use Z-projections to populate
    // iteration stack when dealing with 3D skeletons
    final int nSlices = imp.getNSlices();
    ZProjector zp = null;

    final ImageStack iterationStack = new ImageStack(imp.getWidth(), imp.getHeight());
    if (nSlices > 1) {
        zp = new ZProjector(imp);
        zp.setMethod(ZProjector.MAX_METHOD);
        zp.setStartSlice(1);
        zp.setStopSlice(nSlices);
    }

    // Initialize AnalyzeSkeleton_
    final AnalyzeSkeleton_ as = new AnalyzeSkeleton_();
    as.setup("", imp);

    // Perform the iterative pruning
    int order = 1, nEndpoints = 0, nJunctions = 0, nJunctions2 = 0;
    ArrayList<Point> endpointsList = null, junctionsList = null;
    String errorMsg = "";

    do {

        IJ.showStatus("Retrieving measurements for order " + order + "...");
        IJ.showProgress(order, getMaxOrder());

        // (Re)skeletonize image
        if (order > 1)
            skeletonizeWithoutHermits(imp);

        // Get properties of loop-resolved tree(s)
        final SkeletonResult sr = as.run(pruneChoice, false, false, grayscaleImp, true, false);
        nEndpoints = sum(sr.getEndPoints());
        nJunctions = sum(sr.getJunctions());

        if (order == 1) {
            // Remember initial properties
            endpointsList = sr.getListOfEndPoints();
            junctionsList = sr.getListOfJunctionVoxels();

            // Do not include root in 1st order calculations
            nEndpoints -= nRootEndpoints;
            nJunctions -= nRootJunctions;
        }

        // Is it worth proceeding?
        if (nEndpoints == 0 || nJunctions2 == nJunctions) {
            errorMsg = "Error! Iteration " + order + " aborted: ";
            errorMsg += (nEndpoints == 0) ? "No end-poins found" : "Unsolved loop(s) detected";
            break;
        }

        // Add current tree(s) to debug animation
        ImageProcessor ipd;
        if (nSlices > 1) {
            zp.doProjection();
            ipd = zp.getProjection().getProcessor();
        } else {
            ipd = ip.duplicate();
        }
        iterationStack.addSlice("Order " + IJ.pad(order, 2), ipd);

        // Report properties of pruned structures
        if (verbose) {
            logrt.incrementCounter();
            logrt.addValue("Image", title);
            logrt.addValue("Structure", "Skel. at iteration " + Integer.toString(order));
            logrt.addValue("Notes", errorMsg);
            logrt.addValue("# Trees", sr.getNumOfTrees());
            logrt.addValue("# Branches", sum(sr.getBranches()));
            logrt.addValue("# End-points", nEndpoints);
            logrt.addValue("# Junctions", nJunctions);
            logrt.addValue("# Triple points", sum(sr.getTriples()));
            logrt.addValue("# Quadruple points", sum(sr.getQuadruples()));
            logrt.addValue("Average branch length", average(sr.getAverageBranchLength()));
        }

        // Remember main results
        nJunctions2 = nJunctions;

        // Eliminate end-points
        as.run(pruneChoice, true, false, grayscaleImp, true, false, rootRoi);

    } while (order++ <= getMaxOrder() && nJunctions > 0);

    // Set counter to the de facto order
    order -= 1;

    // Append root properties to log table
    if (validRootRoi && verbose) {

        // Check if ROI contains unexpected structures
        final String msg = (nRootJunctions > 0) ? "Warning: ROI contains ramified root(s)"
                : "Root-branches inferred from ROI";
        logrt.incrementCounter();
        logrt.addValue("Image", title);
        logrt.addValue("Structure", "Root");
        logrt.addValue("Notes", msg);
        logrt.addValue("# Trees", rootResult.getNumOfTrees());
        logrt.addValue("# Branches", sum(rootResult.getBranches()));
        logrt.addValue("# End-points", nRootEndpoints);
        logrt.addValue("# Junctions", nRootJunctions);
        logrt.addValue("# Triple points", sum(rootResult.getTriples()));
        logrt.addValue("# Quadruple points", sum(rootResult.getQuadruples()));
        logrt.addValue("Average branch length", average(rootResult.getAverageBranchLength()));

    }

    // Safety check
    if (iterationStack == null || iterationStack.getSize() < 1) {
        error("Enable \"detailed\" mode and check " + VERBOSE_TABLE + " for details.");
        return;
    }

    // Create iteration stack
    final Calibration cal = srcImp.getCalibration();
    final ImagePlus imp2 = new ImagePlus("StrahlerIteration_" + title, iterationStack);
    imp2.setCalibration(cal);
    if (outIS) {
        if (validRootRoi) {
            iterationStack.addSlice("Root", rootIp);
            paintPoints(iterationStack, rootEndpointsList, 255, "Root end-points");
            imp2.setRoi(rootRoi);
        }
        paintPoints(iterationStack, endpointsList, 255, "End-points");
        paintPoints(iterationStack, junctionsList, 255, "Junction-points");
    }

    // Generate Strahler mask
    zp = new ZProjector(imp2);
    zp.setMethod(ZProjector.SUM_METHOD);
    zp.setStartSlice(1);
    zp.setStopSlice(order);
    zp.doProjection();
    final ImageProcessor ip3 = zp.getProjection().getProcessor().convertToShortProcessor(false);
    clearPoints(ip3, junctionsList); // disconnect branches
    ip3.multiply(1 / 255.0); // map intensities to Strahler orders
    final ImagePlus imp3 = new ImagePlus("StrahlerMask_" + title, ip3);
    imp3.setCalibration(cal);

    // Measure segmented orders
    double prevNbranches = Double.NaN;
    for (int i = 1; i <= order; i++) {

        // Segment branches by order
        final ImagePlus maskImp = imp3.duplicate(); // Calibration is
        // retained
        IJ.setThreshold(maskImp, i, i);
        IJ.run(maskImp, "Convert to Mask", "");

        // Analyze segmented order
        final AnalyzeSkeleton_ maskAs = new AnalyzeSkeleton_();
        maskAs.setup("", maskImp);
        final SkeletonResult maskSr = maskAs.run(pruneChoice, false, false, grayscaleImp, true, false);
        maskImp.flush();

        // Since all branches are disconnected at this stage, the n. of
        // branches is
        // the same as the # the trees unless zero-branches trees exist,
        // i.e., trees
        // with no slab voxels (defined by just an end-point). We will
        // ignore those
        // trees if the user requested it
        final int nBranches = (erodeIsolatedPixels) ? sum(maskSr.getBranches()) : maskSr.getNumOfTrees();

        // Log measurements
        rt.incrementCounter();
        rt.addValue("Image", title);
        rt.addValue("Strahler Order", i);
        rt.addValue("# Branches", nBranches);
        rt.addValue("Ramification ratios", prevNbranches / nBranches);
        rt.addValue("Average branch length", average(maskSr.getAverageBranchLength()));
        rt.addValue("Unit", cal.getUnit());
        String noteMsg = "";
        if (i == 1) {
            noteMsg = (erodeIsolatedPixels) ? "Ignoring" : "Including";
            noteMsg += " single-point arbors...";
        }
        rt.addValue("Notes", noteMsg);

        // Remember results for previous order
        prevNbranches = nBranches;

    }

    // Append any errors to last row
    rt.addValue("Notes", errorMsg);

    // Display outputs
    if (!tabular) {
        if (outIS)
            imp2.show();
        ip3.setMinAndMax(0, order);
        ColorMaps.applyMagmaColorMap(imp3, 200, false);
        if (validRootRoi)
            imp3.setRoi(rootRoi);
        imp3.show();
        addCalibrationBar(imp3, Math.min(order, 5), "Black");
    }
    if (verbose)
        logrt.show(VERBOSE_TABLE);
    rt.show(STRAHLER_TABLE);

    IJ.showProgress(0, 0);
    IJ.showTime(imp, imp.getStartTime(), "Strahler Analysis concluded... ");
    imp.flush();

}