Example usage for java.util HashMap isEmpty

List of usage examples for java.util HashMap isEmpty

Introduction

In this page you can find the example usage for java.util HashMap isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:org.xchain.namespaces.jsl.BaseTestSaxEvents.java

public void assertStartPrefixMappings(Iterator<SaxEventRecorder.SaxEvent> eventIterator,
        Map<String, String> prefixMappings, boolean allowOthers) throws Exception {
    // make sure that the event is there and of the proper type.
    assertTrue("There is not a start prefix event.", eventIterator.hasNext());
    SaxEventRecorder.SaxEvent event = eventIterator.next();
    assertEquals("There was not a start prefix mappings event.",
            SaxEventRecorder.EventType.START_PREFIX_MAPPING, event.getType());

    HashMap<String, String> eventMapping = new HashMap<String, String>();
    eventMapping.putAll(event.getPrefixMapping());

    for (Map.Entry<String, String> entry : prefixMappings.entrySet()) {
        String definedNamespace = eventMapping.remove(entry.getKey());
        assertEquals("The namespace for prefix " + entry.getKey() + " has the wrong definition.",
                entry.getValue(), definedNamespace);
    }//  w  w w. j ava 2  s. co m

    if (!allowOthers && !eventMapping.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        sb.append("Extra prefixes found on element:");
        for (Map.Entry<String, String> entry : eventMapping.entrySet()) {
            sb.append(" xmlns:").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
        }
        fail(sb.toString());
    }
}

From source file:gr.iit.demokritos.cru.cps.ai.ComputationalCreativityMetrics.java

public double Surprise(String new_frag, ArrayList<String> frags)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    //split the story in fragments (sentences)
    if (frags.isEmpty()) {
        return 0.0;
    }//from w w  w .  java2  s  .c  o  m
    double dist = 0;
    //calculate AvgSemDist for the first fragment
    HashMap<ArrayList<String>, Double> top = inf.TopTerms(frags.get(0), false);
    double older = 0.0;
    Set<String> terms = new HashSet<String>();
    if (!top.isEmpty()) {
        //cumpute the average semantic distance of this fragment
        for (ArrayList<String> stems : top.keySet()) {
            //if it is in compact form , there is only one term for each stem
            for (int j = 0; j < stems.size(); j++) {
                terms.add(stems.get(j));
            }
        }
        older = AvgSemDist(terms);
    }
    double newer = 0.0;
    //put the new story as the last fragment
    if (new_frag.length() > 0) {
        frags.add(new_frag);
    }
    //frags.remove(0);//fragment 0 is already calculated
    for (int i = 1; i < frags.size(); i++) {
        //calculate AvgSemDist for every fragment
        top = inf.TopTerms(frags.get(i), false);
        if (top.isEmpty()) {
            //if the framgent has only stopwords, it has 0.0 avg sem distance
            //newer = 0.0;
            //if the fragment had only stopoff words, step it
            continue;
        } else {
            terms = new HashSet<String>();
            //cumpute the average semantic distance of this story
            for (ArrayList<String> stems : top.keySet()) {
                //if it is in compact form , there is only one term for each stem
                for (int j = 0; j < stems.size(); j++) {
                    terms.add(stems.get(j));
                }
            }
            newer = AvgSemDist(terms);
            //System.out.println(newer);
        }
        //and abstract it with the previous
        dist += abs(older - newer);// / top.size();
        //the new becomes the older to be abstracted with the next fragment
        older = newer;
    }
    //calculate the final formula
    double sur = 0.0;
    if (dist != 0) {
        sur = dist * 2 / (frags.size() - 1);
    }
    return sur;

}

From source file:com.coreform.open.android.formidablevalidation.ValidationManager.java

public boolean validateAllAndSetError() {
    //validateAll
    HashMap<String, FinalValidationResult> finalValidationResultMap = validateAll(true);
    if (finalValidationResultMap.isEmpty()) {
        //all valid
        return true;
    } else {//  w  ww.  j  ava  2  s  .  c o m
        //something invalid
        if (DEBUG)
            Log.d(TAG, "...at least one field is invalid, perhaps more.");
        if (DEBUG)
            Log.d(TAG, "...number of invalid fields: " + Integer.toString(finalValidationResultMap.size()));
        boolean setErrorAlreadyShown = false;
        View firstInvalidView = null;
        SpannableStringBuilder firstInvalidErrorText = null;
        validationLoop: for (Entry<String, FinalValidationResult> entry : finalValidationResultMap.entrySet()) {
            if (DEBUG)
                Log.d(TAG, "...validation result failed for field: " + entry.getKey());
            FinalValidationResult aFinalValidationResult = entry.getValue();
            boolean invalidDependencyTakesPrecedence = false;
            boolean invalidFieldHasAlreadyBeenFocused = false; //used to force focus to the first invalid field in List instead of last
            if (!aFinalValidationResult.isDependencyValid()) {
                if (DEBUG)
                    Log.d(TAG, "...dependency validation failed, with message: "
                            + aFinalValidationResult.getDependencyInvalidMessage());
                invalidDependencyTakesPrecedence = true;
                //if(DEBUG) Log.d(TAG, "aFinalValidationResult source's class: "+aFinalValidationResult.getSource().getClass().getSimpleName());
                if ("EditText".equals(aFinalValidationResult.getSource().getClass().getSimpleName())) {
                    if (!invalidFieldHasAlreadyBeenFocused) {
                        invalidFieldHasAlreadyBeenFocused = true;
                    }
                    //setError
                    SpannableStringBuilder errorText = new SpannableStringBuilder(
                            aFinalValidationResult.getDependencyInvalidMessage());
                    ((EditText) aFinalValidationResult.getSource()).setError(errorText);
                    setErrorAlreadyShown = true;
                    if (firstInvalidView == null) {
                        firstInvalidView = (View) aFinalValidationResult.getSource();
                        firstInvalidErrorText = errorText;
                    }
                }
            }
            if (!aFinalValidationResult.isValueValid()) {
                //note: ValueValidationResults for which careInvalid = false should NOT have caused a submission of FinalValidationResult to this List
                if (DEBUG)
                    Log.d(TAG, "...value validation failed, with message: "
                            + aFinalValidationResult.getValueInvalidMessage());
                //only display value invalid message if dependency(ies) satisfied for this field
                if (!invalidDependencyTakesPrecedence) {
                    if (aFinalValidationResult.getSource() == null) {
                        if (DEBUG)
                            Log.d(TAG, "...cannot display error balloon because source is null!");
                        //do nothing
                    } else if (aFinalValidationResult.getSource() instanceof SetErrorAble) {
                        //only set (don't show) error for a SetErrorAble View if no other Views have had their error set.
                        //...to avoid having multiple ErrorPopups displayed at same time (at least until User moves focus)
                        SpannableStringBuilder errorText = new SpannableStringBuilder(
                                aFinalValidationResult.getValueInvalidMessage());
                        if (DEBUG)
                            Log.d(TAG, "...set and show custom error balloon...");
                        if (true || !invalidFieldHasAlreadyBeenFocused) {
                            invalidFieldHasAlreadyBeenFocused = true;
                        }
                        //setError (for a button, this won't requestFocus() and won't show the message in a popup...it only sets the exclamation inner drawable)
                        ((SetErrorAble) aFinalValidationResult.getSource()).betterSetError(errorText, false);
                        setErrorAlreadyShown = true;
                        if (firstInvalidView == null) {
                            firstInvalidView = (View) aFinalValidationResult.getSource();
                            firstInvalidErrorText = errorText;
                        }
                    } else if (aFinalValidationResult.getSource() instanceof TextView) {
                        if (DEBUG)
                            Log.d(TAG, "...set and show native error balloon...");
                        if (!invalidFieldHasAlreadyBeenFocused) {
                            invalidFieldHasAlreadyBeenFocused = true;
                        }
                        //setError
                        SpannableStringBuilder errorText = new SpannableStringBuilder(
                                aFinalValidationResult.getValueInvalidMessage());
                        ((TextView) aFinalValidationResult.getSource()).setError(errorText);
                        setErrorAlreadyShown = true;
                        if (firstInvalidView == null) {
                            firstInvalidView = (View) aFinalValidationResult.getSource();
                            firstInvalidErrorText = errorText;
                        }
                    } else {
                        if (DEBUG)
                            Log.d(TAG, "...field does not support .setError()!");
                    }
                }
            }
        }
        //need to delay accessibility announcement so its the last View to steal focus
        if (DEBUG)
            Log.d(TAG, "firstInvalidErrorText: " + firstInvalidErrorText);
        AnnounceForAccessibilityRunnable announceForAccessibilityRunnable = new AnnounceForAccessibilityRunnable(
                firstInvalidErrorText);
        mHandler.postDelayed(announceForAccessibilityRunnable, ACCESSIBILITY_ANNOUNCE_DELAY);
        if (((View) firstInvalidView).isFocusable() && ((View) firstInvalidView).isFocusableInTouchMode()) {
            ((View) firstInvalidView).requestFocus();
        } else if (firstInvalidView instanceof SetErrorAble) {
            ((SetErrorAble) firstInvalidView).betterSetError(firstInvalidErrorText, true);
            ((View) firstInvalidView).requestFocusFromTouch(); //probably won't do much

        }
        return false;
    }
}

From source file:org.apache.axis2.transport.http.ListingAgent.java

public void processExplicitSchemaAndWSDL(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {
    HashMap services = configContext.getAxisConfiguration().getServices();
    String filePart = req.getRequestURL().toString();
    String schema = filePart.substring(filePart.lastIndexOf("/") + 1, filePart.length());
    if ((services != null) && !services.isEmpty()) {
        Iterator i = services.values().iterator();
        while (i.hasNext()) {
            AxisService service = (AxisService) i.next();
            InputStream stream = service.getClassLoader().getResourceAsStream("META-INF/" + schema);
            if (stream != null) {
                OutputStream out = res.getOutputStream();
                res.setContentType("text/xml");
                copy(stream, out);/*w  w  w  .ja  v  a  2s  .co  m*/
                out.flush();
                out.close();
                return;
            }
        }
    }
}

From source file:org.wso2.carbon.core.deployment.DeploymentInterceptor.java

private void removeFaultyServiceDueToModule(String moduleName, String serviceGroupName) {
    synchronized (faultyServicesDueToModules) {
        HashMap<String, AxisDescription> faultyServices = faultyServicesDueToModules.get(moduleName);
        if (faultyServices != null) {
            faultyServices.remove(serviceGroupName);
            if (faultyServices.isEmpty()) {
                faultyServicesDueToModules.remove(moduleName);
            }/* w  ww.  java2  s. c  o  m*/
        }
    }
}

From source file:org.nuxeo.binary.metadata.internals.BinaryMetadataServiceImpl.java

/**
 * Maps inspector only.//from  w  w  w .  j  ava2 s.  c o  m
 */
protected boolean isDirtyMapping(MetadataMappingDescriptor mappingDescriptor, DocumentModel doc) {
    Map<String, String> mappingResult = new HashMap<>();
    for (MetadataMappingDescriptor.MetadataDescriptor metadataDescriptor : mappingDescriptor
            .getMetadataDescriptors()) {
        mappingResult.put(metadataDescriptor.getXpath(), metadataDescriptor.getName());
    }
    // Returning only dirty properties
    HashMap<String, Object> resultDirtyMapping = new HashMap<>();
    for (String metadata : mappingResult.keySet()) {
        Property property = doc.getProperty(metadata);
        if (property.isDirty()) {
            resultDirtyMapping.put(mappingResult.get(metadata), doc.getPropertyValue(metadata));
        }
    }
    return !resultDirtyMapping.isEmpty();
}

From source file:org.kuali.coeus.propdev.impl.s2s.schedule.S2SPollingTask.java

/**
 * /*from ww w .ja  va  2 s  .c o  m*/
 * This method sends mail for all submission status records that have changed relative to database
 * 
 * @param htMails
 * @throws InvalidAddressException
 * @throws Exception
 */
private void sendMail(HashMap<String, Vector<SubmissionData>> htMails)
        throws InvalidAddressException, MessagingException {
    if (htMails.isEmpty()) {
        return;
    }
    List<MailInfo> mailList = getMailInfoList();
    for (MailInfo mailInfo : mailList) {
        String dunsNum = mailInfo.getDunsNumber();
        Vector<SubmissionData> propList = htMails.get(dunsNum);
        if (propList == null) {
            continue;
        }
        htMails.remove(dunsNum);
        MailMessage mailMessage = parseNGetMailAttr(propList, mailInfo);
        if (mailMessage != null) {
            mailService.sendMessage(mailMessage);
        }
    }

    if (mailList.size() > 0 && !htMails.isEmpty()) {
        Iterator<String> it = htMails.keySet().iterator();
        while (it.hasNext()) {
            Vector<SubmissionData> nonDunsPropList = htMails.get(it.next());
            MailInfo mailInfo = mailList.get(0);
            MailMessage mailMessage = parseNGetMailAttr(nonDunsPropList, mailInfo);
            if (mailMessage != null) {
                mailService.sendMessage(mailMessage);
                LOG.debug("Sent mail with default duns to " + mailMessage.getToAddresses() + " Subject as "
                        + mailMessage.getSubject() + " Message as " + mailMessage.getMessage());
            }
        }
    }
}

From source file:org.springframework.cloud.gateway.actuate.GatewayControllerEndpoint.java

@GetMapping("/routes")
public Mono<List<Map<String, Object>>> routes() {
    Mono<Map<String, RouteDefinition>> routeDefs = this.routeDefinitionLocator.getRouteDefinitions()
            .collectMap(RouteDefinition::getId);
    Mono<List<Route>> routes = this.routeLocator.getRoutes().collectList();
    return Mono.zip(routeDefs, routes).map(tuple -> {
        Map<String, RouteDefinition> defs = tuple.getT1();
        List<Route> routeList = tuple.getT2();
        List<Map<String, Object>> allRoutes = new ArrayList<>();

        routeList.forEach(route -> {//from   www  .j  av a 2  s. c  om
            HashMap<String, Object> r = new HashMap<>();
            r.put("route_id", route.getId());
            r.put("order", route.getOrder());

            if (defs.containsKey(route.getId())) {
                r.put("route_definition", defs.get(route.getId()));
            } else {
                HashMap<String, Object> obj = new HashMap<>();

                obj.put("predicate", route.getPredicate().toString());

                if (!route.getFilters().isEmpty()) {
                    ArrayList<String> filters = new ArrayList<>();
                    for (GatewayFilter filter : route.getFilters()) {
                        filters.add(filter.toString());
                    }

                    obj.put("filters", filters);
                }

                if (!obj.isEmpty()) {
                    r.put("route_object", obj);
                }
            }
            allRoutes.add(r);
        });

        return allRoutes;
    });
}

From source file:org.kuali.kra.s2s.polling.S2SPollingTask.java

/**
 * //from w  w w.  j  av  a  2 s  .c om
 * This method sends mail for all submission status records that have changed relative to database
 * 
 * @param htMails
 * @throws InvalidAddressException
 * @throws Exception
 */
private void sendMail(HashMap<String, Vector<SubmissionData>> htMails) throws InvalidAddressException {
    MailService mailService = KNSServiceLocator.getMailService();
    if (htMails.isEmpty()) {
        return;
    }
    List<MailInfo> mailList = getMailInfoList();
    for (MailInfo mailInfo : mailList) {
        String dunsNum = mailInfo.getDunsNumber();
        Vector<SubmissionData> propList = htMails.get(dunsNum);
        if (propList == null) {
            continue;
        }
        htMails.remove(dunsNum);
        MailMessage mailMessage = parseNGetMailAttr(propList, mailInfo);
        if (mailMessage != null) {
            mailService.sendMessage(mailMessage);
        }
    }

    if (mailList.size() > 0 && !htMails.isEmpty()) {
        Iterator<String> it = htMails.keySet().iterator();
        while (it.hasNext()) {
            Vector<SubmissionData> nonDunsPropList = htMails.get(it.next());
            MailInfo mailInfo = mailList.get(0);
            MailMessage mailMessage = parseNGetMailAttr(nonDunsPropList, mailInfo);
            if (mailMessage != null) {
                mailService.sendMessage(mailMessage);
                LOG.debug("Sent mail with default duns to " + mailMessage.getToAddresses() + " Subject as "
                        + mailMessage.getSubject() + " Message as " + mailMessage.getMessage());
            }
        }
    }
}

From source file:me.aphymi.newbiechat.NewbieChatExecutor.java

private boolean chatters(CommandSender sender, Command cmd, String[] args) {
    if (!sender.hasPermission("newbiechat.chatters")) {
        sender.sendMessage(noPerms);//from   w ww  .  j  av  a 2 s . co  m
        return true;
    }
    HashMap<Integer, ArrayList<String>> chatterList = new HashMap<Integer, ArrayList<String>>();
    for (Player player : Bukkit.getOnlinePlayers()) {
        if (player.hasMetadata(meta)) {
            int room = player.getMetadata(meta).get(0).asInt();
            if (!chatterList.containsKey(room)) {
                chatterList.put(room, new ArrayList<String>());
            }
            chatterList.get(room).add(player.getName());
        }
    }
    if (chatterList.isEmpty()) {
        sender.sendMessage(name + "No one is currently in a chat room.");
        return true;
    }
    ArrayList<String> lines = new ArrayList<String>();
    for (Integer room : chatterList.keySet()) {
        lines.add(String.format("eRoom %s: f%s", room, StringUtils.join(chatterList.get(room), ", ")));
    }
    sender.sendMessage(StringUtils.join(lines, "\n"));
    return true;
}