Example usage for java.util Map clear

List of usage examples for java.util Map clear

Introduction

In this page you can find the example usage for java.util Map clear.

Prototype

void clear();

Source Link

Document

Removes all of the mappings from this map (optional operation).

Usage

From source file:com.china317.gmmp.gmmp_report_analysis.App.java

private static void IntOutNoneRecordsStoreIntoDB(Map<String, AlarmNoMark> iniOutNoneRecords,
        ApplicationContext context) {/*from w w w. jav  a  2  s.  c  o m*/
    Connection conn = null;
    String sql = "";
    try {
        SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientLybc");
        conn = sc.getDataSource().getConnection();
        conn.setAutoCommit(false);
        Statement st = conn.createStatement();
        Iterator<String> it = iniOutNoneRecords.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            AlarmNoMark pos = iniOutNoneRecords.get(key);
            sql = "insert into TAB_ALARM_NOMARK " + " (LICENCE,BEGIN_TIME,END_TIME,ROAD) " + " values (" + "'"
                    + pos.getLicense() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTime() + "',"
                    + "'" + pos.getRoad() + "')";
            log.info(sql);
            st.addBatch(sql);
        }
        st.executeBatch();
        conn.commit();
        log.info("[insertIntoDB TAB_ALARM_NOMARK success!!!]");
    } catch (Exception e) {
        e.printStackTrace();
        log.error(sql);
    } finally {
        iniOutNoneRecords.clear();
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.ec2box.manage.socket.SecureShellWS.java

@OnClose
public void onClose() {

    if (SecureShellAction.getUserSchSessionMap() != null) {
        UserSchSessions userSchSessions = SecureShellAction.getUserSchSessionMap().get(sessionId);
        if (userSchSessions != null) {
            Map<Integer, SchSession> schSessionMap = userSchSessions.getSchSessionMap();

            for (Map.Entry<Integer, SchSession> entry : schSessionMap.entrySet()) {
                Integer sessionKey = entry.getKey();
                SchSession schSession = entry.getValue();

                //disconnect ssh session
                schSession.getChannel().disconnect();
                schSession.getSession().disconnect();
                schSession.setChannel(null);
                schSession.setSession(null);
                schSession.setInputToChannel(null);
                schSession.setCommander(null);
                schSession.setOutFromChannel(null);
                //remove from map
                schSessionMap.remove(sessionKey);
            }/*  ww w.  j a v  a  2  s.c  om*/

            //clear and remove session map for user
            schSessionMap.clear();
            SecureShellAction.getUserSchSessionMap().remove(sessionId);
            SessionOutputUtil.removeUserSession(sessionId);
        }
    }

}

From source file:com.wso2telco.dep.reportingservice.BillingHostObject.java

/**
 * Js function_get cost per api.//from  w  w w .j a  va 2  s  . c om
 *
 * @param cx the cx
 * @param thisObj the this obj
 * @param args the args
 * @param funObj the fun obj
 * @return the native array
 * @throws Exception 
 */
public static NativeArray jsFunction_getCostPerAPI(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) throws BusinessException {
    List<APIVersionUserUsageDTO> list = null;
    if (args == null || args.length == 0) {
        log.error("jsFunction_getCostPerAPI Invalid number of parameters");
        throw new BusinessException(ReportingServiceError.INPUT_ERROR);
    }
    NativeArray myn = new NativeArray(0);
    if (!SbHostObjectUtils.checkDataPublishingEnabled()) {
        return myn;
    }
    String subscriberName = (String) args[0];
    String period = (String) args[1];

    String opcode = (String) args[2];
    String application = (String) args[3];
    if ((application == null) || (application.equalsIgnoreCase("0"))) {
        application = "__All__";
    }

    boolean isNorthbound = (Boolean) args[4];

    NativeArray ret = generateReport(subscriberName, period, false, isNorthbound, opcode);
    NativeArray arr = (NativeArray) ret;

    Map<String, Double> apiPriceMap = new HashMap<String, Double>();
    apiPriceMap.clear();

    NativeArray apiPriceResponse = new NativeArray(0);

    for (Object o : arr.getIds()) {
        int i = (Integer) o;
        NativeObject subs = (NativeObject) arr.get(i);
        String subscriber = subs.get("subscriber").toString();
        log.info(subscriber);
        NativeArray applicatons = (NativeArray) subs.get("applications");

        for (Object o2 : applicatons.getIds()) {
            int j = (Integer) o2;
            NativeObject app = (NativeObject) applicatons.get(j);
            String appname = app.get("applicationname").toString();

            if (application.equalsIgnoreCase("__All__")) {
                NativeArray subscriptions = (NativeArray) app.get("subscriptions");
                for (Object o3 : subscriptions.getIds()) {
                    int k = (Integer) o3;
                    NativeObject apis = (NativeObject) subscriptions.get(k);
                    String api = apis.get("subscriptionapi").toString();
                    Double price = 0.0;
                    NativeArray operators = (NativeArray) apis.get("operators");
                    for (Object o4 : operators.getIds()) {
                        int l = (Integer) o4;
                        NativeObject opis = (NativeObject) operators.get(l);
                        String operator = opis.get("operator").toString();
                        if ((opcode.equalsIgnoreCase("__All__")) || (operator.equalsIgnoreCase(opcode))) {
                            price = price + Double.valueOf(opis.get("price").toString());
                        }
                    }

                    if (apiPriceMap.containsKey(api)) {
                        apiPriceMap.put(api, (apiPriceMap.get(api) + Double.valueOf(price)));
                    } else {
                        apiPriceMap.put(api, Double.valueOf(price));
                    }
                }
            } else {
                try {
                    String applicationName = SbHostObjectUtils.getApplicationNameById(application);
                    if (appname.equalsIgnoreCase(applicationName)) {
                        NativeArray subscriptions = (NativeArray) app.get("subscriptions");
                        for (Object o3 : subscriptions.getIds()) {
                            int k = (Integer) o3;
                            NativeObject apis = (NativeObject) subscriptions.get(k);
                            String api = apis.get("subscriptionapi").toString();
                            Double price = 0.0;
                            NativeArray operators = (NativeArray) apis.get("operators");
                            for (Object o4 : operators.getIds()) {
                                int l = (Integer) o4;
                                NativeObject opis = (NativeObject) operators.get(l);
                                String operator = opis.get("operator").toString();
                                if ((opcode.equalsIgnoreCase("__All__"))
                                        || (operator.equalsIgnoreCase(opcode))) {
                                    price = price + Double.valueOf(opis.get("price").toString());
                                }
                            }

                            if (apiPriceMap.containsKey(api)) {
                                apiPriceMap.put(api, (apiPriceMap.get(api) + Double.valueOf(price)));
                            } else {
                                apiPriceMap.put(api, Double.valueOf(price));
                            }
                        }
                    }
                } catch (Exception e) {

                    log.error("jsFunction_getCostPerAPI", e);
                    throw new BusinessException(ReportingServiceError.INTERNAL_SERVER_ERROR);
                }
            }

        }
    }

    short i = 0;
    for (Map.Entry pairs : apiPriceMap.entrySet()) {
        NativeObject row = new NativeObject();
        String apiName = pairs.getKey().toString();
        row.put(apiName, row, pairs.getValue().toString());
        apiPriceResponse.put(i, apiPriceResponse, row);
        i++;
    }

    return apiPriceResponse;
}

From source file:org.eclipse.swordfish.core.interceptor.EndpointResolverInterceptor.java

public void process(MessageExchange messageExchange) throws SwordfishException {
    Assert.notNull(wsdlStorage, "wsdlStorage is not loaded");
    Exchange exchange = ServiceMixSupport.toNMRExchange(messageExchange);
    try {//w  w w.j  a v a2  s . c  o  m
        if (exchange.getRole() != Role.Consumer) {
            return;
        }
        if (exchange.getTarget() != null && ServiceMixSupport.getEndpoint(exchange.getTarget()) != null) {
            return;
        }
        QName interfaceName = (QName) exchange.getProperty(Endpoint.INTERFACE_NAME);

        if (interfaceName == null) {
            interfaceName = (QName) exchange.getProperty(MessageExchangeImpl.INTERFACE_NAME_PROP);
        }
        if (interfaceName == null) {
            return;
        }
        QName operation = exchange.getOperation();
        if (operation == null)
            return;
        ServiceDescription serviceDescription;
        try {
            serviceDescription = wsdlManager.getServiceDescription(interfaceName);
        } catch (WSDLException e) {
            throw new SwordfishException(
                    "Error resolving endpoint - cannot retrieve service description for port type "
                            + interfaceName + " message: " + e.getMessage());
        }
        if (serviceDescription != null) {
            //         SwordfishPort port = serviceDescription.choosePort(operation.getLocalPart(), Transport.HTTP_STR);
            //         Binding binding = port.getBinding();
            //         Map<String,String> props = new HashMap<String, String>();
            //         props.put(Endpoint.SERVICE_NAME, serviceDescription.getServiceQName().toString());
            //         Reference reference = lookup(props);
            QName service = serviceDescription.getServiceQName();
            if (service == null)
                throw new SwordfishException("Error resolving endpoint - cannot resolve service for port type "
                        + interfaceName + " operation " + operation);
            Map<String, Object> props = new HashMap<String, Object>();
            props.put(Endpoint.SERVICE_NAME, service.toString());
            InternalEndpoint serviceEndpoint = ServiceMixSupport.getEndpoint(nmr, props);
            if (serviceEndpoint != null) {
                logger.info("The service endpoint for the servicename + [" + service + "} has been found");
                exchange.setTarget(new StaticReferenceImpl(Arrays.asList(serviceEndpoint)));
            } else {
                logger.info("The service endpoint for the servicename + [" + service + "} not found");
                logger.info("Trying to find the transport endpoint");
                serviceDescription.getAvailableLocations();
                for (Map.Entry<SOAPAddress, SOAPBinding> entry : serviceDescription.getAvailableLocations()
                        .entrySet()) {
                    props.clear();
                    props.put(JbiConstants.PROTOCOL_TYPE, entry.getValue().getTransportURI());
                    serviceEndpoint = ServiceMixSupport.getEndpoint(nmr, props);
                    if (serviceEndpoint != null) {
                        logger.info("Have found the suitable endpoint with transport = "
                                + entry.getValue().getTransportURI());
                        exchange.setTarget(new StaticReferenceImpl(Arrays.asList(serviceEndpoint)));
                        exchange.getIn().setHeader(JbiConstants.HTTP_DESTINATION_URI,
                                entry.getKey().getLocationURI());
                    }
                }
            }
        } else {
            logger.info("Error resolving endpoint - wsdl cannot be found for port type " + interfaceName);
        }
    } catch (Exception ex) {
        logger.warn("The exception happened while trying to resolve service name via supplied wsdls ", ex);
    }
}

From source file:com.impetus.client.neo4j.Neo4JClient.java

/**
 * Gets the entity with association from node.
 * /*  w  ww  . j a v a 2s  .  c  om*/
 * @param m
 *            the m
 * @param node
 *            the node
 * @return the entity with association from node
 */
private Object getEntityWithAssociationFromNode(EntityMetadata m, Node node) {
    Map<String, Object> relationMap = new HashMap<String, Object>();

    /**
     * Map containing Node ID as key and Entity object as value. Helps cache
     * entity objects found earlier for faster lookup and prevents repeated
     * processing
     */
    Map<Long, Object> nodeIdToEntityMap = new HashMap<Long, Object>();

    Object entity = mapper.getEntityFromNode(node, m);

    nodeIdToEntityMap.put(node.getId(), entity);
    populateRelations(m, entity, relationMap, node, nodeIdToEntityMap);

    nodeIdToEntityMap.clear();

    if (!relationMap.isEmpty() && entity != null) {
        return new EnhanceEntity(entity, PropertyAccessorHelper.getId(entity, m), relationMap);
    } else {
        return entity;
    }

}

From source file:fr.gael.dhus.service.job.SearchesJob.java

@Override
protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
    if (!configurationManager.getSearchesCronConfiguration().isActive())
        return;//from   w w  w.java 2 s . c o  m
    long time_start = System.currentTimeMillis();
    logger.info("SCHEDULER : User searches mailings.");
    if (!DHuS.isStarted()) {
        logger.warn("SCHEDULER : Not run while system not fully initialized.");
        return;
    }
    Map<String, String> cids = new HashMap<String, String>();
    for (User user : userDao.readNotDeleted()) {
        List<Search> searches = userDao.getUserSearches(user);
        if (searches == null || (searches.size() == 0)) {
            logger.debug("No saved search for user \"" + user.getUsername() + "\".");
            continue;
        }

        if (user.getEmail() == null) {
            logger.error(
                    "User \"" + user.getUsername() + "\" email not configured to send search notifications.");
            continue;
        }

        HtmlEmail he = new HtmlEmail();
        cids.clear();

        int maxResult = searches.size() >= 10 ? 5 : 10;
        String message = "<html><style>" + "a { font-weight: bold; color: #205887; "
                + "text-decoration: none; }\n" + "a:hover { font-weight:bold; color: #FF790B"
                + "; text-decoration: none; }\na img { border-style: none; }\n"
                + "</style><body style=\"font-family: Trebuchet MS, Helvetica, "
                + "sans-serif; font-size: 14px;\">Dear " + getUserWelcome(user) + ",<p/>\n\n";
        message += "You requested periodic notification for the following " + "searches. Here are the top "
                + maxResult + " results for " + "each search:<p/>";
        message += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" "
                + "style=\"width: 100%;font-family: Trebuchet MS, Helvetica, "
                + "sans-serif; font-size: 14px;\"><tbody>";

        boolean atLeastOneResult = false;
        for (Search search : searches) {
            if (search.isNotify()) {
                message += "<tr><td colspan=\"3\" style=\"font-size: 13px; "
                        + "font-weight: bold; color: white; background-color: "
                        + "#205887; text-align: center;\"><b>";
                message += search.getValue();
                message += "</b></td></tr>\n";

                Map<String, String> advanceds = search.getAdvanced();
                if (advanceds != null && !advanceds.isEmpty()) {
                    message += "<tr><td style=\"font-size: 13px; padding:0px; "
                            + "margin:0px; font-weight:normal; background-color: "
                            + "#799BB7; text-align: center; border-left: 1px solid "
                            + "#205887; border-right: 1px solid #205887; "
                            + "border-bottom: 1px solid #205887;\">";
                    boolean first = true;
                    List<String> keys = new ArrayList<String>(advanceds.keySet());
                    Collections.sort(keys);
                    String lastKey = "";
                    for (String key : keys) {
                        if ((lastKey + "End").equals(key)) {
                            message += " to " + advanceds.get(key);
                        } else {
                            if (key.endsWith("End")) {
                                message += (first ? "" : ", ") + key.substring(0, key.length() - 3) + ": * to "
                                        + advanceds.get(key);
                            } else {
                                message += (first ? "" : ", ") + key + ": " + advanceds.get(key);
                            }
                        }
                        first = false;
                        lastKey = key;
                    }
                    message += "</td></tr>";
                }

                Iterator<Product> results;
                try {
                    results = searchService.search(search.getComplete());
                } catch (Exception e) {
                    message += "<tr><td colspan=\"3\" style=\""
                            + "text-align: center; border-left: 1px solid #205887; "
                            + "border-right: 1px solid #205887;\">" + "No result found</td></tr>";
                    logger.debug("There was an error when executing query : \"" + e.getMessage() + "\"");
                    continue;
                }

                if (!results.hasNext()) {
                    message += "<tr><td colspan=\"3\" style=\""
                            + "text-align: center; border-left: 1px solid #205887; "
                            + "border-right: 1px solid #205887;\">" + "No result found</td></tr>";
                    logger.debug("No result matches query : \"" + search.getComplete() + "\"");
                }

                boolean first = true;
                int searchIndex = 0;
                while (results.hasNext() && searchIndex < maxResult) {

                    if (!first) {
                        message += "<tr><td colspan=\"3\" style=\""
                                + "background-color: #205887; height:1px;\" /></tr>";
                    }
                    first = false;

                    Product product = results.next();
                    // WARNING : must implement to schedule fix of this issue...
                    if (product == null)
                        continue;

                    atLeastOneResult = true;
                    searchIndex++;

                    logger.debug("Result found: " + product.getIdentifier());

                    String purl = configurationManager.getServerConfiguration().getExternalUrl()
                            + "odata/v1/Products('" + product.getUuid() + "')";

                    // EMBEDED THUMBNAIL
                    String cid = null;
                    if (product.getThumbnailFlag()) {
                        File thumbnail = new File(product.getThumbnailPath());
                        String thumbname = thumbnail.getName();
                        if (cids.containsKey(thumbname)) {
                            cid = cids.get(thumbname);
                        } else {
                            try {
                                cid = he.embed(thumbnail);
                                cids.put(thumbname, cid);
                            } catch (Exception e) {
                                logger.warn("Cannot embed image \"" + purl + "/Products('Quicklook')/$value\" :"
                                        + e.getMessage());
                                cid = null;
                            }
                        }
                    }
                    boolean downloadRight = user.getRoles().contains(Role.DOWNLOAD);
                    String link = downloadRight
                            ? "(<a target=\"_blank\" href=\"" + purl + "/$value\">download</a>)"
                            : "";
                    message += "   <tr><td colspan=\"3\" style=\"" + "font-size: 14px; text-align: center; "
                            + "border-left: 1px solid #205887; border-right: 1px "
                            + "solid #205887;\"><a target=\"_blank\" href=\"" + purl + "/$value\">"
                            + product.getIdentifier() + "</a> " + link + "</td>\n</tr>\n";
                    if (cid != null) {
                        message += "   <tr><td rowspan=\"8\" style=\""
                                + "text-align: center; vertical-align: middle;"
                                + " border-left: 1px solid #205887;\">" + "<a target=\"_blank\" href=\"" + purl
                                + "/Products('Quicklook')/$value\"><img src=cid:" + cid
                                + " style=\"max-height: 64px; max-width:" + " 64px;\"></a></td>\n";
                    }

                    // Displays metadata
                    List<MetadataIndex> indexes = new ArrayList<>(productService.getIndexes(product.getId()));
                    Collections.sort(indexes, new Comparator<MetadataIndex>() {
                        @Override
                        public int compare(MetadataIndex o1, MetadataIndex o2) {
                            if ((o1.getCategory() == null) || o1.getCategory().equals(o2.getCategory()))
                                return o1.getName().compareTo(o2.getName());
                            return o1.getCategory().compareTo(o2.getCategory());
                        }
                    });
                    int i = 0;
                    for (MetadataIndex index : indexes) {
                        String queryable = index.getQueryable();
                        String name = index.getName();
                        String value = index.getValue();

                        if (value.length() > 50)
                            continue;

                        if (queryable != null)
                            name += "(" + queryable + ")";

                        if (i != 0) {
                            message += "<tr>";
                        }
                        String start = "<td";
                        if (cid == null || i >= 8) {
                            start += " style=\"width: 120px;" + " border-left: 1px solid #205887;\"><td";
                        }
                        i++;
                        message += start + ">" + name + "</td>"
                                + "<td style=\"border-right: 1px solid #205887;\">" + value + "</td>";
                        message += "</tr>";
                    }
                    if (indexes == null || indexes.size() == 0) {
                        message += "</tr>";
                    }
                }
            }
        }
        // No result: next user, no mail.
        if (!atLeastOneResult)
            continue;
        message += "<tr><td colspan=\"3\" style=\"background-color: #205887;" + " height:1px;\" /></tr>";
        message += "</tbody></table><p/>\n";
        message += "You can configure which searches are sent by mail in the " + "<i>saved searches</i> tab in "
                + configurationManager.getNameConfiguration().getShortName()
                + " system at <a target=\"_blank\" href=\""
                + configurationManager.getServerConfiguration().getExternalUrl() + "\">"
                + configurationManager.getServerConfiguration().getExternalUrl()
                + "</a><br/>To stop receiving this message, just disable " + "all searches.<p/>";

        message += "Thanks for using " + configurationManager.getNameConfiguration().getShortName() + ",<br/>"
                + configurationManager.getSupportConfiguration().getName();
        message += "</body></html>";

        logger.info("Sending search results to " + user.getEmail());
        logger.debug(message);

        try {
            he.setHtmlMsg(message);
            mailServer.send(he, user.getEmail(), null, null, "Saved searches notifications");
        } catch (EmailException e) {
            logger.error("Cannot send mail to \"" + user.getEmail() + "\" :" + e.getMessage());
        }
    }
    logger.info(
            "SCHEDULER : User searches mailings done - " + (System.currentTimeMillis() - time_start) + "ms");
}

From source file:com.linkedin.pinot.queries.QueriesSentinelTest.java

@Test
public void testAggregationGroupBy() throws Exception {
    final List<TestGroupByAggreationQuery> groupByCalls = AVRO_QUERY_GENERATOR
            .giveMeNGroupByAggregationQueries(10000);
    int counter = 0;
    final Map<ServerInstance, DataTable> instanceResponseMap = new HashMap<ServerInstance, DataTable>();
    for (final TestGroupByAggreationQuery groupBy : groupByCalls) {
        LOGGER.info("running " + counter + " : " + groupBy.pql);
        final BrokerRequest brokerRequest = REQUEST_COMPILER.compileToBrokerRequest(groupBy.pql);
        InstanceRequest instanceRequest = new InstanceRequest(counter++, brokerRequest);
        instanceRequest.setSearchSegments(new ArrayList<String>());
        instanceRequest.getSearchSegments().add(segmentName);
        QueryRequest queryRequest = new QueryRequest(instanceRequest);
        final DataTable instanceResponse = QUERY_EXECUTOR.processQuery(queryRequest);
        instanceResponseMap.clear();
        instanceResponseMap.put(new ServerInstance("localhost:0000"), instanceResponse);
        final BrokerResponseNative brokerResponse = REDUCE_SERVICE.reduceOnDataTable(brokerRequest,
                instanceResponseMap);// w  w w.j  a  v a  2 s . c o  m
        LOGGER.info("BrokerResponse is " + brokerResponse.getAggregationResults().get(0));
        LOGGER.info("Result from avro is : " + groupBy.groupResults);

        assertGroupByResults(brokerResponse.getAggregationResults().get(0).getGroupByResult(),
                groupBy.groupResults);
    }
}

From source file:fr.landel.utils.assertor.AssertorMapTest.java

/**
 * Test method for {@link AssertorMap#isNotEmpty}.
 * /* www.  j a va  2s .c  o m*/
 * @throws IOException
 *             On error
 */
@Test
public void testIsNotEmpty() throws IOException {
    final String el = "element";

    final Map<String, Integer> map = new HashMap<>();
    map.put(el, 1);

    final AssertorStepMap<String, Integer> assertMap = Assertor.that(map);

    assertMap.isNotEmpty().orElseThrow();

    assertException(() -> {
        assertMap.not().isNotEmpty().orElseThrow();
        fail(ERROR);
    }, IllegalArgumentException.class);

    map.clear();

    assertException(() -> {
        assertMap.isNotEmpty().orElseThrow();
        fail(ERROR);
    }, IllegalArgumentException.class);

    assertException(() -> {
        assertMap.isNotEmpty().orElseThrow("map is empty");
        fail(ERROR);
    }, IllegalArgumentException.class, "map is empty");

    assertException(() -> {
        assertMap.isNotEmpty().orElseThrow(new IOException(), true);
        fail(ERROR);
    }, IOException.class);

    assertFalse(Assertor.that((Map<String, Integer>) null).isNotEmpty().isOK());
}

From source file:fr.landel.utils.assertor.predicate.PredicateAssertorMapTest.java

/**
 * Test method for {@link AssertorMap#isNotEmpty}.
 * //  www .  ja  v  a  2 s.  c o  m
 * @throws IOException
 *             On error
 */
@Test
public void testIsNotEmpty() throws IOException {
    final String el = "element";

    final Map<String, Integer> map = new HashMap<>();
    map.put(el, 1);

    final PredicateAssertorStepMap<String, Integer> assertMap = Assertor.<String, Integer>ofMap();

    assertMap.isNotEmpty().that(map).orElseThrow();

    assertException(() -> {
        assertMap.not().isNotEmpty().that(map).orElseThrow();
        fail(ERROR);
    }, IllegalArgumentException.class);

    map.clear();

    assertException(() -> {
        assertMap.isNotEmpty().that(map).orElseThrow();
        fail(ERROR);
    }, IllegalArgumentException.class);

    assertException(() -> {
        assertMap.isNotEmpty().that(map).orElseThrow("map is empty");
        fail(ERROR);
    }, IllegalArgumentException.class, "map is empty");

    assertException(() -> {
        assertMap.isNotEmpty().that(map).orElseThrow(new IOException(), true);
        fail(ERROR);
    }, IOException.class);

    assertFalse(Assertor.<String, Integer>ofMap().isNotEmpty().that((Map<String, Integer>) null).isOK());
}

From source file:org.spantus.exp.segment.draw.AbstractGraphGenerator.java

protected Map<String, Double> sortTotals(Map<String, Double> result) {
    // Get a list of the entries in the map
    List<Map.Entry<String, Double>> list = new Vector<Map.Entry<String, Double>>(result.entrySet());

    // Sort the list using an annonymous inner class implementing Comparator
    // for the compare method
    java.util.Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
        public int compare(Map.Entry<String, Double> entry, Map.Entry<String, Double> entry1) {
            // Return 0 for a match, -1 for less than and +1 for
            // more then
            return (entry.getValue().equals(entry1.getValue()) ? 0
                    : (entry.getValue() > entry1.getValue() ? 1 : -1));
        }/*ww w. j  a  v a2  s. c  o m*/
    });

    // Clear the map
    result.clear();

    // Copy back the entries now in order
    for (Map.Entry<String, Double> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}