Example usage for java.util LinkedHashMap keySet

List of usage examples for java.util LinkedHashMap keySet

Introduction

In this page you can find the example usage for java.util LinkedHashMap keySet.

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:org.lokra.seaweedfs.core.FileTemplate.java

/**
 * Save files by stream map./*from  w  w w. j  a  v a  2s.co m*/
 *
 * @param streamMap   Map of file name and file stream.
 * @param contentType File content type.
 * @return Files status.
 * @throws IOException Http connection is fail or server response within some error message.
 */
public LinkedHashMap<String, FileHandleStatus> saveFilesByStreamMap(
        LinkedHashMap<String, InputStream> streamMap, ContentType contentType) throws IOException {
    // Assign file key
    final AssignFileKeyParams params = new AssignFileKeyParams(assignFileKeyParams.getReplication(),
            streamMap.size(), assignFileKeyParams.getDataCenter(), assignFileKeyParams.getTtl(),
            assignFileKeyParams.getCollection());

    final AssignFileKeyResult assignFileKeyResult = masterWrapper.assignFileKey(params);
    String uploadUrl;
    if (usingPublicUrl)
        uploadUrl = assignFileKeyResult.getPublicUrl();
    else
        uploadUrl = assignFileKeyResult.getUrl();

    // Upload file
    LinkedHashMap<String, FileHandleStatus> resultMap = new LinkedHashMap<String, FileHandleStatus>();
    int index = 0;
    for (String fileName : streamMap.keySet()) {
        if (index == 0)
            resultMap.put(fileName,
                    new FileHandleStatus(assignFileKeyResult.getFid(),
                            volumeWrapper.uploadFile(uploadUrl, assignFileKeyResult.getFid(), fileName,
                                    streamMap.get(fileName), timeToLive, contentType)));
        else
            resultMap.put(fileName,
                    new FileHandleStatus(assignFileKeyResult.getFid() + "_" + String.valueOf(index),
                            volumeWrapper.uploadFile(uploadUrl,
                                    assignFileKeyResult.getFid() + "_" + String.valueOf(index), fileName,
                                    streamMap.get(fileName), timeToLive, contentType)));
        index++;
    }
    return resultMap;
}

From source file:gate.util.reporting.DocTimeReporter.java

/**
 * Sorts LinkedHashMap by its values(natural descending order). keeps the
 * duplicates as it is.//  w w  w  .  j av  a  2s  .com
 *
 * @param passedMap
 *          An Object of type LinkedHashMap to be sorted by its values.
 * @return An Object containing the sorted LinkedHashMap.
 */
private LinkedHashMap<?, ?> sortHashMapByValues(LinkedHashMap<String, String> passedMap) {
    List<String> mapKeys = new ArrayList<String>(passedMap.keySet());
    List<String> mapValues = new ArrayList<String>(passedMap.values());

    Collections.sort(mapValues, new ValueComparator());
    Collections.sort(mapKeys);
    // Reversing the collection to sort the values in descending order
    Collections.reverse(mapValues);
    LinkedHashMap<String, String> sortedMap = new LinkedHashMap<String, String>();

    Iterator<String> valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        String val = valueIt.next();
        Iterator<String> keyIt = mapKeys.iterator();
        while (keyIt.hasNext()) {
            String key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();

            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put(key, val);
                break;
            }
        }
    }
    return sortedMap;
}

From source file:gate.util.reporting.PRTimeReporter.java

/**
 * Prints a processing elements structure in a tree like format with time
 * taken by each element in milliseconds and in %.
 *
 * @param gStore//from   w  w w .  j  av  a 2 s .c  o  m
 *          An Object of type LinkedHashMap<String, Object> containing the
 *          processing elements (with time in milliseconds) in hierarchical
 *          structure.
 * @param separator
 *          A String separator to indent the processing elements in tree like
 *          structure.
 * @param suppressZeroTimeEntries
 *          Indicate whether or not to show 0 millisecond entries.
 */
@SuppressWarnings("unchecked")
private void prettyPrint(LinkedHashMap<String, Object> gStore, String separator,
        boolean suppressZeroTimeEntries) {

    Iterator<String> i = gStore.keySet().iterator();
    while (i.hasNext()) {
        Object key = i.next();
        if (globalTotal.containsKey(key))
            globalValue = Integer.parseInt(globalTotal.get(key));
        if (gStore.get(key) instanceof LinkedHashMap) {
            int systotal = 0;
            if (((LinkedHashMap<String, Object>) gStore.get(key)).containsKey("systotal")) {
                systotal = Integer
                        .parseInt((String) ((LinkedHashMap<String, Object>) (gStore.get(key))).get("systotal"));
            }
            if (suppressZeroTimeEntries) {
                if (systotal > 0)
                    printLines.add(separator + key + " (" + systotal / 1000.0 + ") ["
                            + Math.round(((systotal / globalValue) * 100) * 10) / 10.0 + "%]");
            } else {
                printLines.add(separator + key + " (" + systotal / 1000.0 + ") ["
                        + Math.round(((systotal / globalValue) * 100) * 10) / 10.0 + "%]");
            }

            prettyPrint((LinkedHashMap<String, Object>) (gStore.get(key)), separator + "\t",
                    suppressZeroTimeEntries);
        } else {
            if (!(key.equals("total") || key.equals("systotal"))) {
                if (suppressZeroTimeEntries) {
                    if (Integer.parseInt((String) (gStore.get(key))) != 0) {
                        printLines.add(separator + key + " ("
                                + Integer.parseInt((String) (gStore.get(key))) / 1000.0 + ") ["
                                + Math.round(
                                        ((Integer.parseInt((String) (gStore.get(key))) / globalValue) * 100)
                                                * 10)
                                        / 10.0
                                + "%]");
                    }
                } else {
                    printLines.add(separator + key + " ("
                            + Integer.parseInt((String) (gStore.get(key))) / 1000.0 + ") ["
                            + Math.round(
                                    ((Integer.parseInt((String) (gStore.get(key))) / globalValue) * 100) * 10)
                                    / 10.0
                            + "%]");
                }
            }
        }
    }
}

From source file:gate.util.reporting.PRTimeReporter.java

/**
 * Creates three tree like ul/li structures 1. A tree to represent processing
 * elements 2. A tree to represent time taken by processing elements 3. A tree
 * to represent time taken by processing elements in %.
 *
 * @param gStore//w ww . j  a v a 2  s  .c o  m
 *          An Object of type LinkedHashMap<String, Object> containing the
 *          processing elements (with time in milliseconds) in hierarchical
 *          structure.
 * @param suppressZeroTimeEntries
 *          Indicate whether or not to show 0 millisecond entries.
 */
@SuppressWarnings("unchecked")
private void generateCollapsibleHTMLTree(LinkedHashMap<String, Object> gStore,
        boolean suppressZeroTimeEntries) {
    Iterator<String> i = gStore.keySet().iterator();
    while (i.hasNext()) {
        Object key = i.next();
        if (globalTotal.containsKey(key))
            globalValue = Integer.parseInt(globalTotal.get(key));

        if (gStore.get(key) instanceof LinkedHashMap) {
            int systotal = 0;
            if (((LinkedHashMap<String, Object>) gStore.get(key)).containsKey("systotal")) {
                systotal = Integer
                        .parseInt((String) ((LinkedHashMap<String, Object>) (gStore.get(key))).get("systotal"));
            }

            if (suppressZeroTimeEntries) {
                if (systotal > 0) {
                    htmlElementTree += "<li id=\"level" + level + "\">"
                            + "<a href=\"#\"  onclick=\"expandCollapseTree(this)\">[+]</a>" + "&nbsp;" + key
                            + "<ul style=\"display:none\">" + NL;
                    htmlTimeTree += "<div id=level" + level + ".1>" + NL + systotal / 1000.0 + NL
                            + "<div style=\"display:none\">" + NL;
                    htmlTimeInPercentTree += "<div id=level" + level + ".2>" + NL
                            + Math.round(((systotal / globalValue) * 100) * 10) / 10.0
                            + "<div style=\"display:none\">" + NL;
                    level++;
                    generateCollapsibleHTMLTree((LinkedHashMap<String, Object>) (gStore.get(key)),
                            suppressZeroTimeEntries);
                    htmlElementTree += "</ul></li>" + NL;
                    htmlTimeTree += "</div></div>" + NL;
                    htmlTimeInPercentTree += "</div></div>" + NL;
                }
            } else {
                htmlElementTree += "<li id=level" + level + ">"
                        + "<a href=\"#\" onclick=\"expandCollapseTree(this)\">[+]</a>" + "&nbsp;" + key
                        + "<ul style=\"display:none\">" + NL;
                htmlTimeTree += "<div id=level" + level + ".1>" + NL + systotal / 1000.0
                        + "<div style=\"display:none\">" + NL;
                htmlTimeInPercentTree += "<div id=level" + level + ".2>" + NL
                        + Math.round(((systotal / globalValue) * 100) * 10) / 10.0
                        + "<div style=\"display:none\">" + NL;
                level++;
                generateCollapsibleHTMLTree((LinkedHashMap<String, Object>) (gStore.get(key)),
                        suppressZeroTimeEntries);
                htmlElementTree += "</ul></li>" + NL;
                htmlTimeTree += "</div></div>" + NL;
                htmlTimeInPercentTree += "</div></div>" + NL;
            }
        } else {
            if (!(key.equals("total") || key.equals("systotal"))) {
                if (suppressZeroTimeEntries) {
                    if (Integer.parseInt((String) (gStore.get(key))) != 0) {
                        htmlElementTree += "<li>&nbsp;&nbsp;&nbsp;" + key + "</li>" + NL;
                        htmlTimeTree += "<div>" + NL + Integer.parseInt((String) (gStore.get(key))) / 1000.0
                                + "</div>" + NL;
                        htmlTimeInPercentTree += "<div>" + NL + Math.round(
                                ((Integer.parseInt((String) (gStore.get(key))) / globalValue) * 100) * 10)
                                / 10.0 + "</div>" + NL;
                    }
                } else {
                    htmlElementTree += "<li>&nbsp;&nbsp;&nbsp;" + key + "</li>" + NL;
                    htmlTimeTree += "<div>" + NL + Integer.parseInt((String) (gStore.get(key))) / 1000.0
                            + "</div>" + NL;
                    htmlTimeInPercentTree += "<div>" + NL
                            + Math.round(
                                    ((Integer.parseInt((String) (gStore.get(key))) / globalValue) * 100) * 10)
                                    / 10.0
                            + "</div>" + NL;
                }
            }
        }
    }
}

From source file:gate.util.reporting.PRTimeReporter.java

/**
 * Calculates the total of the time taken by processing element at each leaf
 * level. Also calculates the difference between the actual time taken by the
 * resources and system noted time./*from w w w  . j ava  2 s .  co  m*/
 *
 * @param reportContainer
 *          An Object of type LinkedHashMap<String, Object> containing the
 *          processing elements (with time in milliseconds) in hierarchical
 *          structure.
 *
 * @return An integer containing the sub total.
 */

@SuppressWarnings("unchecked")
private int getTotal(LinkedHashMap<String, Object> reportContainer) {
    int total = 0;
    int diff = 0;
    int systotal = 0;
    int subLevelTotal = 0;
    Iterator<String> i = reportContainer.keySet().iterator();
    while (i.hasNext()) {
        Object key = i.next();

        if (reportContainer.get(key) instanceof LinkedHashMap) {
            subLevelTotal = getTotal((LinkedHashMap<String, Object>) (reportContainer.get(key)));
            total = total + subLevelTotal;
        } else {
            if (!key.equals("systotal")) {
                total = total + Integer.parseInt((String) (reportContainer.get(key)));
            }
        }
    }
    if (reportContainer.get("systotal") != null) {
        systotal = Integer.parseInt((String) (reportContainer.get("systotal")));
    }
    diff = systotal - total;
    reportContainer.put("total", Integer.toString(total));
    reportContainer.put("All others", Integer.toString(diff));
    total += diff;
    return total;
}

From source file:org.apache.axis2.engine.MessageContextSaveCTest.java

private void showObjectGraphInfo(LinkedHashMap map) {
    if (map == null) {
        return;//  www. j  a  v  a 2  s.com
    }

    Iterator it = map.keySet().iterator();

    while (it.hasNext()) {
        String metaClassName = (String) it.next();
        MetaDataEntry meta = (MetaDataEntry) map.get(metaClassName);

        if (meta != null) {
            String classname = meta.getClassName();
            String name = meta.getName();
            String hashcode = meta.getExtraName();

            log.debug("class[" + classname + "]  id[" + name + "]  hashcode" + hashcode + " ");
        }

    }

}

From source file:com.textocat.textokit.eval.GoldStandardBasedEvaluation.java

private void evaluate(CAS goldCas, CAS sysCas) {
    FSIterator<AnnotationFS> goldAnnoIter = annotationExtractor.extract(goldCas);
    Set<AnnotationFS> goldProcessed = new HashSet<AnnotationFS>();
    // system annotations that exactly match a gold one
    Set<AnnotationFS> sysMatched = newHashSet();
    // matches//from   www.  jav a 2 s. c om
    LinkedHashMap<AnnotationFS, MatchInfo> matchesMap = newLinkedHashMap();
    while (goldAnnoIter.hasNext()) {
        AnnotationFS goldAnno = goldAnnoIter.next();
        if (goldProcessed.contains(goldAnno)) {
            continue;
        }
        MatchInfo mi = new MatchInfo();
        matchesMap.put(goldAnno, mi);

        Set<AnnotationFS> candidates = newLinkedHashSet(matchingStrategy.searchCandidates(goldAnno));

        candidates.removeAll(sysMatched);
        AnnotationFS exactSys = matchingStrategy.searchExactMatch(goldAnno, candidates);
        if (exactSys != null) {
            // sanity check
            assert candidates.contains(exactSys);
            mi.exact = exactSys;
            sysMatched.add(exactSys);
        }
        mi.partialSet.addAll(candidates);

        goldProcessed.add(goldAnno);
    }

    // filter partials that match a next gold
    for (MatchInfo mi : matchesMap.values()) {
        mi.partialSet.removeAll(sysMatched);
    }

    // report for each gold anno
    for (AnnotationFS goldAnno : matchesMap.keySet()) {
        // assert order declared in EvaluationListener javadoc
        MatchInfo mi = matchesMap.get(goldAnno);
        boolean matchedExactly = mi.exact != null;
        if (matchedExactly) {
            evalCtx.reportExactMatch(goldAnno, mi.exact);
        }
        for (AnnotationFS partialSys : mi.partialSet) {
            evalCtx.reportPartialMatch(goldAnno, partialSys);
        }
        if (!matchedExactly) {
            evalCtx.reportMissing(goldAnno);
        }
    }

    // report spurious (false positives)
    FSIterator<AnnotationFS> sysAnnoIter = annotationExtractor.extract(sysCas);
    while (sysAnnoIter.hasNext()) {
        AnnotationFS sysAnno = sysAnnoIter.next();
        if (!sysMatched.contains(sysAnno)) {
            evalCtx.reportSpurious(sysAnno);
        }
    }
}

From source file:com.grarak.kerneladiutor.FileBrowserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    fileBrowserActivity = this;
    boolean dark = Utils.getBoolean("darktheme", false, this);
    if (dark)//w ww .  j  ava2 s  . c  om
        super.setTheme(R.style.AppThemeDark);
    setContentView(R.layout.activity_filebrowser);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar actionBar;
    if ((actionBar = getSupportActionBar()) != null)
        actionBar.setDisplayHomeAsUpEnabled(true);

    String fileType = getIntent().getExtras().getString(FILE_TYPE_ARG);
    String externalStorage = Utils.getExternalStorage();

    LinkedHashMap<String, Fragment> fragments = new LinkedHashMap<>();
    internalStorage = StorageFragment.newInstance(Environment.getExternalStorageDirectory().getPath(),
            fileType);
    fragments.put(getString(R.string.internal_storage), internalStorage);
    if (externalStorage != null) {
        this.externalStorage = StorageFragment.newInstance(externalStorage, fileType);
        fragments.put(getString(R.string.external_storage), this.externalStorage);
    }

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setAdapter(new Adapter(getSupportFragmentManager(), fragments));
    if (dark)
        mViewPager.setBackgroundColor(getResources().getColor(R.color.card_background_dark));

    final SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    for (int i = 0; i < fragments.keySet().toArray().length; i++)
        mSlidingTabLayout.setContentDescription(i, (String) fragments.keySet().toArray()[i]);
    mSlidingTabLayout.setSelectedIndicatorColors(
            getResources().getColor(fragments.size() > 1 ? R.color.white : R.color.color_primary));
    mSlidingTabLayout.setDistributeEvenly(true);
    mSlidingTabLayout.setViewPager(mViewPager);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(getResources().getColor(R.color.color_primary_dark));
    }
}

From source file:gate.util.reporting.DocTimeReporter.java

/**
 * Prints the document level statistics report in HTML format.
 *
 * @param reportSource/*w w w.j a  v a2s  .  com*/
 *          An Object of type LinkedHashMap<String, Object> containing the
 *          document names (with time in milliseconds).
 * @param outputFile
 *          An object of type File representing the output report file to
 *          which the HTML report is to be written.
 */
private void printToHTML(LinkedHashMap<String, Object> reportSource, File outputFile) {
    String htmlReport = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" + NL
            + "\"http://www.w3.org/TR/html4/loose.dtd\">" + NL
            + "<html><head><title>Benchmarking Report</title>" + NL + "<meta http-equiv=\"Content-Type\""
            + " content=\"text/html; charset=utf-8\">" + NL + "<style type=\"text/css\">" + NL
            + "div { font-size:12px; margin-top: 4; }" + NL + "</style>" + NL + "</head>" + NL
            + "<body style=\"font-family:Verdana; color:navy;\">" + NL;
    String hTrace = "<div style=\"right: 0pt; border-top:1px solid #C9D7F1;" + " font-size:1px;\" ></div>" + NL;
    String reportTitle = hTrace;
    String docs = "";
    if (maxDocumentInReport != ALL_DOCS) {
        if (allDocs.size() < maxDocumentInReport) {
            docs = Integer.toString(allDocs.size());
        } else {
            docs = Integer.toString(maxDocumentInReport);
        }
    } else {
        docs = "All";
    }
    if (PRMatchingRegex.equals(MATCH_ALL_PR_REGEX)) {
        reportTitle = reportTitle + "<div style=\"font-size:15px;font-family:Verdana; color:navy;\">Top " + docs
                + " expensive documents matching All PRs in <b>" + pipelineName + "</b></div>" + NL;
    } else {
        if (matchingPRs.size() > 0) {
            reportTitle = reportTitle + "<div style=\"font-size:15px;font-family:Verdana; color:navy;\">Top "
                    + docs + " expensive documents matching following PRs in <b>" + pipelineName + "</b> <ul>"
                    + NL;
            for (String pr : matchingPRs) {
                reportTitle = reportTitle + "<li>" + pr + "</li>";
            }
            reportTitle = reportTitle + "</ul></div>";
        } else {
            reportTitle += "<div style=\"font-size:15px;font-family:Verdana; color:navy;\">"
                    + "No PRs matched to search string \"" + getPRMatchingRegex() + " \" in " + pipelineName
                    + "</div>";
        }
    }
    reportTitle = reportTitle + hTrace;

    if (allDocs.size() > 0) {
        String htmlReportTitle = reportTitle + "<table><tr bgcolor=\"#eeeeff\">"
                + "<td><b>Document Name</b></td>" + "<td><b>Time in seconds</b></td>"
                + "<td><b>% Time taken</b></td>" + "</tr><tr>" + NL;
        String documentNameHTMLString = "<td rowspan = '112' width = '550'>";
        String timeTakenHTMLString = "<td width = '100'>";
        String timeInPercentHTMLString = "<td width = '100'>";
        LinkedHashMap<String, Object> rcHash = reportSource;
        rcHash.remove("total");
        Iterator<String> i = rcHash.keySet().iterator();
        int count = 0;
        while (i.hasNext()) {
            Object key = i.next();
            if (!((String) key).equals("total")) {
                int value = Integer.parseInt((String) rcHash.get(key));
                if (maxDocumentInReport == ALL_DOCS) {
                    documentNameHTMLString += "<div>" + key + "</div>";
                    timeTakenHTMLString += "<div>" + value / 1000.0 + "</div>";
                    timeInPercentHTMLString += "<div>" + Math.round(((value / globalTotal) * 100) * 10) / 10.0
                            + "</div>" + NL;
                } else if (count < maxDocumentInReport) {
                    documentNameHTMLString += "<div>" + key + "</div>";
                    timeTakenHTMLString += "<div>" + value / 1000.0 + "</div>";
                    timeInPercentHTMLString += "<div>" + Math.round(((value / globalTotal) * 100) * 10) / 10.0
                            + "</div>" + NL;
                }
            }
            count++;
        }
        documentNameHTMLString += "<div bgcolor=\"#eeeeff\" style = \"font-size:15px;margin-left:400px;\">"
                + "<b>Total</b></div></td>" + NL;
        timeTakenHTMLString += "<div bgcolor=\"#eeeeff\" style = \"font-size:15px;\"><b>" + globalTotal / 1000.0
                + "</b></div></td>" + NL;
        timeInPercentHTMLString += "<div bgcolor=\"#eeeeff\" style = \"font-size:15px;\">"
                + "<b>100</b></div></td>" + NL;

        if (!outputFile.exists()) {
            htmlReport += htmlReportTitle + documentNameHTMLString + timeTakenHTMLString
                    + timeInPercentHTMLString + "</tr></table>";
        } else {
            htmlReport = "<br/><br/>" + htmlReportTitle + documentNameHTMLString + timeTakenHTMLString
                    + timeInPercentHTMLString + "</tr></table></body></html>";
        }
    } else {
        htmlReport += reportTitle + "</body></html>";
    }

    BufferedWriter out = null;
    try {
        out = new BufferedWriter(new FileWriter(outputFile));
        out.write(htmlReport);

    } catch (IOException e) {
        e.printStackTrace();

    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.kepler.gui.kar.ImportModuleDependenciesAction.java

/** Check the dependencies and ask the user how to proceed. */
public ImportChoice checkDependencies() {

    ConfigurationManager cman = ConfigurationManager.getInstance();
    ConfigurationProperty cprop = cman.getProperty(KARFile.KARFILE_CONFIG_PROP_MODULE);
    ConfigurationProperty KARComplianceProp = cprop.getProperty(KARFile.KAR_COMPLIANCE_PROPERTY_NAME);
    String KARCompliance = KARComplianceProp.getValue();

    final ArrayList<String> dependencies = new ArrayList<String>();
    try {//from   w w  w  . j  a va 2s.  c om
        if (_dependencies != null) {
            // dependencies were given
            dependencies.addAll(_dependencies);
        } else if (_archiveFile != null) {
            // kar file was given
            KARFile karFile = null;
            try {
                karFile = new KARFile(_archiveFile);
                dependencies.addAll(karFile.getModuleDependencies());
            } finally {
                if (karFile != null) {
                    karFile.close();
                }
            }
        } else {
            // karxml was given
            dependencies.addAll(_karXml.getModuleDependencies());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    //ModuleTree moduleTree = ModuleTree.instance();
    //String currentModList = formattedCurrentModuleList(moduleTree);

    boolean dependencyMissingFullVersion = !(ModuleDependencyUtil
            .isDependencyVersioningInfoComplete(dependencies));
    LinkedHashMap<String, Version> unsatisfiedDependencies = ModuleDependencyUtil
            .getUnsatisfiedDependencies(dependencies);

    String keplerRestartMessage = null;
    String unableToOpenOrExportInStrictKARComplianceMessage = null;
    String manualActionRequired = null;
    String unSats = formattedUnsatisfiedDependencies(unsatisfiedDependencies);
    final List<String> unSatsAsList = new ArrayList<String>(unsatisfiedDependencies.keySet());

    String formattedDependencies = formatDependencies(dependencies);
    String htmlBGColor = "#"
            + Integer.toHexString(UIManager.getColor("OptionPane.background").getRGB() & 0x00ffffff);
    //XXX augment if additional strictness levels added
    if (KARCompliance.equals(KARFile.KAR_COMPLIANCE_STRICT)) {
        if (dependencyMissingFullVersion) {
            if (_exportMode) {
                unableToOpenOrExportInStrictKARComplianceMessage = "<html><body bgcolor=\"" + htmlBGColor
                        + "\">This KAR "
                        + "lacks complete versioning information in its module-dependency list:<strong>"
                        + formattedDependencies
                        + "</strong><br><br>You must change your KAR opening compliance "
                        + "preference to Relaxed before trying to export this KAR.<br><br>"
                        + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
            } else {
                unableToOpenOrExportInStrictKARComplianceMessage = "<html><body bgcolor=\"" + htmlBGColor
                        + "\">This KAR "
                        + "lacks complete versioning information in its module-dependency list:<strong>"
                        + formattedDependencies
                        + "</strong><br><br>You must change your KAR opening compliance "
                        + "preference to Relaxed before trying to open this KAR.<br><br>"
                        + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
            }
        } else {
            if (!unsatisfiedDependencies.isEmpty()) {
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To export this KAR in<br>"
                            + "Strict mode you must restart Kepler with these additional module(s):<strong>"
                            + unSats
                            + "</strong><br><br>Would you like to download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To open this KAR in<br>"
                            + "Strict mode you must restart Kepler with these additional module(s):<strong>"
                            + unSats
                            + "</strong><br><br>Would you like to download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            } else {
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To export this KAR in<br>"
                            + "Strict mode you must restart Kepler using this module set in this order:<strong>"
                            + formattedDependencies
                            + "</strong><br><br>Would you like to restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To open this KAR in<br>"
                            + "Strict mode you must restart Kepler using this module set in this order:<strong>"
                            + formattedDependencies
                            + "</strong><br><br>Would you like to restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            }
        }
    } else if (KARCompliance.equals(KARFile.KAR_COMPLIANCE_RELAXED)) {
        if (dependencyMissingFullVersion) {
            // if there's a dependency missing full version info, situation should be either 1) a 2.0 kar, in which case
            // it lacks the full mod dep list and so user must use MM, or 2) it's a 2.1 kar created from an svn 
            // checkout of kepler, in which case, the power user should use the build system to 
            // change to unreleased versions of a suite containing the required modules as necessary
            if (_exportMode) {
                manualActionRequired = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR "
                        + "requires the following unsatisfied module dependencies that lack complete versioning information:<strong>"
                        + unSats
                        + "</strong><br><br>Please use the Module Manager or build system to change to a suite that uses these modules.</strong>"
                        + "<br><br>You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
            } else {
                manualActionRequired = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR "
                        + "requires the following unsatisfied module dependencies that lack complete versioning information:<strong>"
                        + unSats
                        + "</strong><br><br>Please use the Module Manager or build system to change to a suite that uses these modules.</strong>"
                        + "<br><br>You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
            }
        } else {
            if (!unsatisfiedDependencies.isEmpty()) {
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these "
                            + "additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to "
                            + "download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these "
                            + "additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to "
                            + "download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            } else {
                //THIS SHOULDN'T HAPPEN
                log.error(
                        "ImportModuleDependenciesAction WARNING unsatisfiedDependencies is empty, this shouldn't happen, but is non fatal");
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these " + "module(s):<strong>"
                            + formattedDependencies + "</strong><br><br>Would you like to "
                            + "restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these " + "module(s):<strong>"
                            + formattedDependencies + "</strong><br><br>Would you like to "
                            + "restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            }
        }
    }

    String[] optionsOkForceopen = { "OK", "Force Open" };
    String[] optionsOkForceexport = { "OK", "Force Export" };
    String[] optionsYesNoForceopen = { "Yes", "No", "Force Open" };
    String[] optionsYesNoForceexport = { "Yes", "No", "Force Export" };

    if (unableToOpenOrExportInStrictKARComplianceMessage != null) {
        JLabel label = new JLabel(unableToOpenOrExportInStrictKARComplianceMessage);
        if (_exportMode) {
            int choice = JOptionPane.showOptionDialog(parent, label, "Unable to export in Strict mode",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceexport,
                    optionsOkForceexport[0]);
            if (optionsOkForceexport[choice].equals("Force Export")) {
                return ImportChoice.FORCE_EXPORT;
            }
        } else {
            int choice = JOptionPane.showOptionDialog(parent, label, "Unable to open in Strict mode",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceopen,
                    optionsOkForceopen[0]);
            if (optionsOkForceopen[choice].equals("Force Open")) {
                return ImportChoice.FORCE_OPEN;
            }
        }
        return ImportChoice.DO_NOTHING;
    }

    if (manualActionRequired != null) {
        JLabel label = new JLabel(manualActionRequired);
        if (_exportMode) {
            int choice = JOptionPane.showOptionDialog(parent, label, "Use Module Manager",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceexport,
                    optionsOkForceexport[0]);
            if (optionsOkForceexport[choice].equals("Force Export")) {
                return ImportChoice.FORCE_EXPORT;
            }
        } else {
            int choice = JOptionPane.showOptionDialog(parent, label, "Use Module Manager",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceopen,
                    optionsOkForceopen[0]);
            if (optionsOkForceopen[choice].equals("Force Open")) {
                return ImportChoice.FORCE_OPEN;
            }
        }
        return ImportChoice.DO_NOTHING;
    }

    JLabel label = new JLabel(keplerRestartMessage);
    if (_exportMode) {
        int choice = JOptionPane.showOptionDialog(parent, label, "Confirm Kepler Restart",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsYesNoForceexport,
                optionsYesNoForceexport[1]);

        if (optionsYesNoForceexport[choice] == "No") {
            // user doesn't want to download.
            return ImportChoice.DO_NOTHING;
        } else if (optionsYesNoForceexport[choice].equals("Force Export")) {
            return ImportChoice.FORCE_EXPORT;
        }
    } else {
        int choice = JOptionPane.showOptionDialog(parent, label, "Confirm Kepler Restart",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsYesNoForceopen,
                optionsYesNoForceopen[1]);

        if (optionsYesNoForceopen[choice] == "No") {
            // user doesn't want to download.
            return ImportChoice.DO_NOTHING;
        } else if (optionsYesNoForceopen[choice].equals("Force Open")) {
            return ImportChoice.FORCE_OPEN;
        }
    }

    parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground() throws Exception {
            try {

                //download needed modules
                ModuleDownloader downloader = new ModuleDownloader();
                ModuleDownloadProgressMonitor mdpm = new ModuleDownloadProgressMonitor(parent);
                downloader.addListener(mdpm);
                if (!unSatsAsList.isEmpty()) {
                    downloader.downloadModules(unSatsAsList);
                } else {
                    // this shouldn't happen, but if it does, resorting
                    // to downloading all dependencies should be a safe bet
                    log.error("ImportModuleDependenciesAction WARNING unSatsAsList is empty, "
                            + "this shouldn't happen, but is non fatal");
                    downloader.downloadModules(dependencies);
                }

                //rewrite modules.txt
                ModulesTxt modulesTxt = ModulesTxt.instance();
                modulesTxt.clear();
                for (String dependency : dependencies) {
                    //System.out.println("ImportModuleDependency doInBackground modulesTxt.add("+dependency+")");
                    modulesTxt.add(dependency);
                }
                modulesTxt.write();

                //delete and write "unknown" to current-suite.txt
                CurrentSuiteTxt.delete();
                CurrentSuiteTxt.setName("unknown");

                // if KARCompliance is Strict, user is restarting w/ specific versions of modules
                // and we don't want them to potentially auto update on restart to available patches
                turnOffAutoUpdatesIfStrictMode();

                //restart Kepler using new modules
                spawnNewKeplerAndQuitCurrent();

                return null;
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(parent, "Error downloading module: " + ex.getMessage());
                return null;
            }
        }

        @Override
        protected void done() {
            //never reached.
        }

    };

    worker.execute();

    parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

    return ImportChoice.DOWNLOADING_AND_RESTARTING;
}