Example usage for java.util TreeMap entrySet

List of usage examples for java.util TreeMap entrySet

Introduction

In this page you can find the example usage for java.util TreeMap entrySet.

Prototype

EntrySet entrySet

To view the source code for java.util TreeMap entrySet.

Click Source Link

Document

Fields initialized to contain an instance of the entry set view the first time this view is requested.

Usage

From source file:br.bireme.ngrams.NGrams.java

private static String doc2pipe(final Document doc, final TreeMap<Integer, String> fields) {
    final StringBuilder sb = new StringBuilder();
    int cur = 0;//from   w ww  .  j a  v  a  2 s  .  co  m

    for (Map.Entry<Integer, String> entry : fields.entrySet()) {
        if (cur > 0) {
            sb.append("|");
        }
        final int pos = entry.getKey();
        if (cur == pos) {
            final String fld = doc.get(entry.getValue());
            if (fld != null) {
                sb.append(fld);
            }
        }
        cur++;
    }
    return sb.toString();
}

From source file:org.rti.zcore.dar.utils.WidgetUtils.java

/**
 * @return Drug enums list from field enums 1562 and 1584 - Malaria Drug and Deworming Drug
 *//* w w  w. jav a2  s.c  o m*/
public static List getDynaSiteDrugEnums() {
    List list = new ArrayList();
    TreeMap rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 1582);
    Set rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        list.add(fieldEnumeration);
    }

    rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 1584);
    rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        list.add(fieldEnumeration);
    }
    return list;
}

From source file:com.mirth.connect.donkey.util.ActionTimer.java

public String getLog() {
    long totalTime = getTotalTime();

    StringBuilder log = new StringBuilder();
    LongComparator longComparator = new LongComparator(times);
    TreeMap<String, Long> sortedTimes = new TreeMap<String, Long>(longComparator);
    sortedTimes.putAll(times);/*www . ja  v  a  2s  .  co  m*/

    for (Entry<String, Long> logEntry : sortedTimes.entrySet()) {
        String eventName = logEntry.getKey();
        Integer count = counts.get(eventName);
        Long time = logEntry.getValue();

        long pct = (totalTime > 0) ? ((time * 100) / totalTime) : 0;
        log.append(StringUtils.rightPad(eventName + ":", 40)
                + StringUtils.rightPad(count + " occurrence" + ((count != 1) ? "s" : ""), 20)
                + StringUtils.rightPad(time + "ms", 12) + pct + "%\n");
    }

    int totalCount = getTotalCount();
    log.append(StringUtils.rightPad("Totals:", 40)
            + StringUtils.rightPad(totalCount + " occurrence" + ((totalCount != 1) ? "s" : ""), 20) + totalTime
            + "ms\n");
    return log.toString();
}

From source file:org.alfresco.bm.report.CSVReporter.java

protected void export(Writer writer) throws Exception {
    // TODO: Get any nodes
    String notes = "";

    writeTestDetails(writer, notes);/* w w w. j  a v a  2 s .c  o  m*/

    writer.write(",,");
    writer.write("Event Name,Total Count,Success Count,Failure Count,Success Rate (%),"
            + "Min (ms), Max (ms), Arithmetic Mean (ms), Standard Deviation (ms)");
    writer.write(NEW_LINE);
    TreeMap<String, ResultSummary> summaries = collateResults(true);
    for (Map.Entry<String, ResultSummary> entry : summaries.entrySet()) {
        writer.write(",,");
        String eventName = entry.getKey();
        ResultSummary summary = entry.getValue();
        SummaryStatistics statsSuccess = summary.getStats(true);
        SummaryStatistics statsFail = summary.getStats(false);
        // Event Name
        writer.write(String.format("%s,", eventName));
        // Total Count
        writer.write(String.format("%6d,", summary.getTotalResults()));
        // Success Count
        writer.write(String.format("%6d,", statsSuccess.getN()));
        // Failure Count
        writer.write(String.format("%6d,", statsFail.getN()));
        // Success Rate (%)
        writer.write(String.format("%3.1f,", summary.getSuccessPercentage()));
        // Min (ms)
        writer.write(String.format("%10d,", (long) statsSuccess.getMin()));
        // Max (ms)
        writer.write(String.format("%10d,", (long) statsSuccess.getMax()));
        // Arithmetic Mean (ms)
        writer.write(String.format("%10d,", (long) statsSuccess.getMean()));
        // Standard Deviation (ms)
        writer.write(String.format("%10d%s", (long) statsSuccess.getStandardDeviation(), NEW_LINE));
    }
    // Done

}

From source file:com.ecofactor.qa.automation.dao.util.DataUtil.java

/**
 * Prints the test case grid./*w  w w.  jav a 2s .c  om*/
 * @param testCaseMap the test case map
 */
public static void printTestCaseGrid(TreeMap<Integer, TestMethodDetails> testCaseMap) {

    try {
        DriverConfig.setLogString("Test Case Grid", true);
        DriverConfig.setLogString(
                "========================================================================================================",
                true);
        DriverConfig.setLogString(
                "|   S.No.  |                   Test Case Name                               |           ID             |",
                true);
        DriverConfig.setLogString(
                "========================================================================================================",
                true);
        Iterator<Entry<Integer, TestMethodDetails>> testCaseIterator = testCaseMap.entrySet().iterator();
        Integer serialNo = 1;
        while (testCaseIterator.hasNext()) {
            Entry<Integer, TestMethodDetails> pairs = testCaseIterator.next();
            TestMethodDetails testNgDetails = pairs.getValue();
            String testMethod = testNgDetails.getTestCaseName();
            String value = testNgDetails.getTestLinkId();
            if (value == null || value.isEmpty()) {
                value = "--";
            }
            DriverConfig.setLogString("| " + addSpace(serialNo.toString(), 9) + "| " + addSpace(testMethod, 63)
                    + "| " + addSpace(value, 25) + "| ", true);
            serialNo++;
        }
        DriverConfig.setLogString(
                "========================================================================================================",
                true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.commands.ListPools.java

private void printPool(final PoolDefinition pool) throws BackingStoreException {
    printf("Pool %s", pool.getPoolId());
    printf(StringUtils.EMPTY);//from  w w w . j a  va  2  s  .  co  m

    final Properties driverProperties = pool.getDriverProperties();
    if (!driverProperties.isEmpty()) {
        printf("Driver Properties:");
        final SortedSet<String> names = new TreeSet<String>();
        final Enumeration<?> propertyNames = driverProperties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            names.add((String) propertyNames.nextElement());
        }
        for (final String key : names) {
            printf("  %35s: %s", key, StringUtils.trimToEmpty(driverProperties.getProperty(key)));
        }
        printf(StringUtils.EMPTY);
    }

    printf("Pool Statistics:");
    final BoneCPDataSource dataSource = (BoneCPDataSource) PoolActivator.getInstance().getRegistry()
            .getDataSource(pool.getPoolId());

    // test connectivity (this also works around a bug in BoneCP which would result in an NPE below)
    try {
        final Connection connection = dataSource.getConnection();
        if (connection instanceof ConnectionHandle) {
            printf("  %35s: %s", "connectionTest",
                    ((ConnectionHandle) connection).isValid(1000) ? "OK" : "NOT OK");
        } else {
            printf("  %35s: %s", "connectionSample", connection.toString());
        }
        connection.close();
    } catch (final SQLException e) {
        printf("  unable to connect to pool: %s", e.getMessage());
    }

    // total number of leased connections
    printf("  %35s: %d", "totalLeased", dataSource.getTotalLeased());
    printf(StringUtils.EMPTY);

    printf("Effective Pool Config:");
    final TreeMap<String, String> poolConfig = readPoolConfig(dataSource);
    for (final Entry<String, String> entry : poolConfig.entrySet()) {
        printf("  %35s: %s", entry.getKey(), entry.getValue());
    }
}

From source file:org.xwiki.contrib.mailarchive.timeline.internal.TimeLineDataWriterSimile.java

/**
 * {@inheritDoc}/*from   ww  w.ja  va2  s.  c om*/
 * 
 * @see org.xwiki.contrib.mailarchive.timeline.internal.ITimeLineDataWriter#print(java.util.TreeMap)
 */
@Override
public void print(TreeMap<Long, TimeLineEvent> sortedEvents) {
    printXMLStartElement("data");
    for (Entry<Long, TimeLineEvent> event : sortedEvents.entrySet()) {
        print(event.getValue());
    }
    printXMLEndElement("data");

}

From source file:org.apache.juddi.xlt.util.LoggingHandler.java

private void logMessage(SOAPMessageContext context) {
    boolean isOutbound = isOutboundMessage(context);

    // optionally append the HTTP request/response headers
    String headersKey = isOutbound ? MessageContext.HTTP_REQUEST_HEADERS : MessageContext.HTTP_RESPONSE_HEADERS;
    StringBuilder httpHeaders = new StringBuilder();
    Map<Object, Object> headers = (Map<Object, Object>) context.get(headersKey);
    if (headers != null && headers.size() > 0) {
        for (Entry<Object, Object> entry : headers.entrySet()) {
            httpHeaders.append("- " + entry.getKey() + " = " + entry.getValue() + "\n");
        }//from   ww  w.j a v  a  2 s .  c o m
    }

    // append the SOAP message
    String soapMessage = DomUtils.prettyPrintNode(context.getMessage().getSOAPPart());

    // append the message context properties
    StringBuilder messageContextProperties = new StringBuilder();
    TreeMap<String, Object> sortedContextProperties = new TreeMap<String, Object>(context);
    for (Entry<String, Object> entry : sortedContextProperties.entrySet()) {
        messageContextProperties.append("- " + entry.getKey() + " = " + entry.getValue() + "\n");
    }

    // finally log all
    String format = isOutbound ? OUTBOUND_MESSAGE_FORMAT : INBOUND_MESSAGE_FORMAT;
    LOG.debug(String.format(format, httpHeaders, soapMessage, messageContextProperties));
}

From source file:org.rti.zcore.dar.utils.WidgetUtils.java

/**
 * uses enums from ABO Group, Rhesus, Cervical Smear, Sickle Cell Screen, and Malaria Test Results
 *
 * @return list/*from  w  ww . ja v  a  2 s  .c  o  m*/
 */
public static List getDynaSiteLabEnums() {
    List list = new ArrayList();
    TreeMap rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 738); // switched from 193
    Set rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        Long enumId = (Long) entry.getKey();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        if (enumId.intValue() == 1664) {
            // don't add it to the list
        } else {
            list.add(fieldEnumeration);
        }
    }

    rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 196);
    rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        Long enumId = (Long) entry.getKey();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        if (enumId.intValue() == 1115) {
            // don't add it to the list
        } else {
            list.add(fieldEnumeration);
        }
    }

    rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 207);
    rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        Long enumId = (Long) entry.getKey();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        if (enumId.intValue() == 111) {
            // don't add it to the list
        } else {
            list.add(fieldEnumeration);
        }
    }

    rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 1460);
    rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        list.add(fieldEnumeration);
    }

    rawMap = (TreeMap) DynaSiteObjects.getFieldEnumerationsByField().get((long) 1462);
    rawSet = rawMap.entrySet();
    for (Iterator iterator = rawSet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        FieldEnumeration fieldEnumeration = (FieldEnumeration) entry.getValue();
        list.add(fieldEnumeration);
    }
    return list;
}

From source file:eu.europa.esig.dss.DSSASN1Utils.java

/**
 * This method can be removed the simple IssuerSerial verification can be
 * performed. In fact the hash verification is sufficient.
 *
 * @param generalNames//from   w  ww  . ja v  a  2  s.  c om
 * @return
 */
public static String getCanonicalizedName(final GeneralNames generalNames) {
    GeneralName[] names = generalNames.getNames();
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    for (GeneralName name : names) {
        String ldapString = String.valueOf(name.getName());
        LOG.debug("ldapString to canonicalize: {} ", ldapString);
        try {
            LdapName ldapName = new LdapName(ldapString);
            List<Rdn> rdns = ldapName.getRdns();
            for (final Rdn rdn : rdns) {
                treeMap.put(rdn.getType().toLowerCase(), String.valueOf(rdn.getValue()).toLowerCase());
            }
        } catch (InvalidNameException e) {
            throw new DSSException(e);
        }
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (Entry<String, String> entry : treeMap.entrySet()) {
        stringBuilder.append(entry.getKey()).append('=').append(entry.getValue()).append('|');
    }
    final String canonicalizedName = stringBuilder.toString();
    LOG.debug("canonicalizedName: {} ", canonicalizedName);
    return canonicalizedName;
}