Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

In this page you can find the example usage for java.lang String compareToIgnoreCase.

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:org.kalypso.zml.ui.imports.ImportObservationData.java

private INativeObservationAdapter findAdapterByExtension(final String extension) {
    if (StringUtils.isBlank(extension))
        return null;

    final INativeObservationAdapter[] allAdapters = getObservationAdapters();
    for (final INativeObservationAdapter adapter : allAdapters) {
        final String defaultExtension = adapter.getDefaultExtension();
        if (!StringUtils.isBlank(defaultExtension) && extension.compareToIgnoreCase(defaultExtension) == 0)
            return adapter;
    }// ww w.jav a2  s  . c  o  m

    return null;
}

From source file:org.gbif.portal.webservices.actions.ResourceAction.java

/**
 * Gets a list of Data Resources given some parameters
 * //  w ww .  j a va  2s .  c o m
 * @param params
 * @return
 * @throws GbifWebServiceException
 */
@SuppressWarnings("unchecked")
public Map<String, Object> findResourceRecords(ResourceParameters params) throws GbifWebServiceException {

    Map<String, String> headerMap;
    Map<String, String> parameterMap;
    Map<String, String> summaryMap;

    SearchResultsDTO searchResultsDTO = null;
    List<DataResourceDTO> dataResourceDTOList = null;

    Map<String, Object> results = new HashMap<String, Object>();

    Map<String, Set<Map<String, Object>>> dataProviderMap = new HashMap<String, Set<Map<String, Object>>>();

    headerMap = returnHeader(params, true);
    parameterMap = returnParameters(params.getParameterMap(null));

    try {

        searchResultsDTO = dataResourceManager.findDataResources(params.getName(), true,
                params.getProviderKey(), params.getBasisOfRecordCode(), params.getModifiedSince(),
                params.getSearchConstraints());

        //get the DataResource list for the criteria given
        dataResourceDTOList = (List<DataResourceDTO>) searchResultsDTO.getResults();

        summaryMap = returnSummary(params, dataResourceDTOList, true);

        //get the DataProvider list for the criteria given
        //dataProviderList = (List<DataProviderDTO>)searchResultsDTO.getResults();

        //for storing all the DataResources along with its elements
        Set<Map<String, Object>> dataResourceMapList = new HashSet<Map<String, Object>>();

        dataProviderMap = new HashMap<String, Set<Map<String, Object>>>();

        //iterate over the DataResource list to obtain the ResourceNetworks and ResourceAccessPoints for each DR
        for (DataResourceDTO dataResourceDTO : dataResourceDTOList) {
            Map<ResourceAccessPointDTO, List<PropertyStoreNamespaceDTO>> resourceAccessPointMap = new HashMap<ResourceAccessPointDTO, List<PropertyStoreNamespaceDTO>>();
            Map<String, Object> dataResourceMap = new HashMap<String, Object>();

            List<ResourceAccessPointDTO> resourceAccessPointDTOList = dataResourceManager
                    .getResourceAccessPointsForDataResource(dataResourceDTO.getKey());
            List<ResourceNetworkDTO> resourceNetworkDTOList = dataResourceManager
                    .getResourceNetworksForDataResource(dataResourceDTO.getKey());

            //iterate over the ResourceAccessPoints to obtain the PropertyStoreNamespaces
            for (ResourceAccessPointDTO resourceAccessPointDTO : resourceAccessPointDTOList) {
                List<PropertyStoreNamespaceDTO> propertyStoreNamespaceDTOList = dataResourceManager
                        .getPropertyStoreNamespacesForResourceAccessPoint(resourceAccessPointDTO.getKey());

                //associate each ResourceAccessPointDTO to a list of PropertyStoreNamespace
                resourceAccessPointMap.put(resourceAccessPointDTO, propertyStoreNamespaceDTOList);
            }

            dataResourceMap.put("dataResourceDTO", dataResourceDTO);
            dataResourceMap.put("resourceNetworkDTOList", resourceNetworkDTOList);
            dataResourceMap.put("resourceAccessPointMap", resourceAccessPointMap);

            if (dataProviderMap.get(dataResourceDTO.getDataProviderKey()) != null) {
                Set<Map<String, Object>> dataResourceMapListForProvider = dataProviderMap
                        .get(dataResourceDTO.getDataProviderKey());
                dataResourceMapListForProvider.add(dataResourceMap);
                dataProviderMap.put(dataResourceDTO.getDataProviderKey(), dataResourceMapListForProvider);
            } else {
                Set<Map<String, Object>> dataResourceMapListForProvider = new TreeSet<Map<String, Object>>(
                        new Comparator() {
                            public int compare(Object a, Object b) {
                                DataResourceDTO dataResource1 = (DataResourceDTO) ((Map) a)
                                        .get("dataResourceDTO");
                                DataResourceDTO dataResource2 = (DataResourceDTO) ((Map) b)
                                        .get("dataResourceDTO");
                                String key1 = dataResource1.getName().toString();
                                String key2 = dataResource2.getName().toString();
                                return key1.compareToIgnoreCase(key2);
                            }
                        });
                dataResourceMapListForProvider.add(dataResourceMap);
                dataProviderMap.put(dataResourceDTO.getDataProviderKey(), dataResourceMapListForProvider);
            }

        }

        results.put("count", 1);
        results.put("results", dataProviderMap);
        results.put("headerMap", headerMap);
        results.put("parameterMap", parameterMap);
        results.put("summaryMap", summaryMap);
        return results;

    } catch (ServiceException se) {
        log.error("Unregistered data service error: " + se.getMessage(), se);
        throw new GbifWebServiceException("Data service problems - " + se.getMessage());
    } catch (Exception se) {
        log.error("Data service error: " + se.getMessage(), se);
        throw new GbifWebServiceException("Data service problems - " + se.toString());
    }
}

From source file:io.github.tavernaextras.biocatalogue.ui.filtertree.FilterTreePane.java

/**
 * This method loads filter data from API and populates the view.
 *///  w  ww  .  j  av a 2s  .co m
private void loadFiltersAndBuildTheTree() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            resetTreeActionToolbar();

            jpFilters.removeAll();
            jpFilters.setLayout(new BorderLayout());
            jpFilters.add(new JLabel(" Loading filters..."), BorderLayout.NORTH);
            jpFilters.add(new JLabel(ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_ORANGE)),
                    BorderLayout.CENTER);
            thisPanel.validate();
            thisPanel.repaint(); // validate and repaint this component to make sure that
                                 // scroll bar around the filter tree placeholder panel disappears
        }
    });

    new Thread("Load filters") {
        public void run() {
            try {
                // load filter data
                filtersRoot = client.getBioCatalogueFilters(filtersURL);

                // Create root of the filter tree component
                FilterTreeNode root = new FilterTreeNode("root");

                // populate the tree via its root element
                for (FilterGroup fgroup : filtersRoot.getGroupList()) {
                    // attach filter group directly to the root node
                    FilterTreeNode fgroupNode = new FilterTreeNode(
                            "<html><span style=\"color: black; font-weight: bold;\">"
                                    + StringEscapeUtils.escapeHtml(fgroup.getName().toString())
                                    + "</span></html>");
                    root.add(fgroupNode);

                    // go through all filter types in this group and add them to the tree
                    for (FilterType ftype : fgroup.getTypeList()) {
                        // if there's more than one filter type in the group, add the type node as another level of nesting
                        // (otherwise, attach filters inside the single type directly to the group node)
                        FilterTreeNode filterTypeNode = fgroupNode;
                        if (fgroup.getTypeList().size() > 1) {
                            filterTypeNode = new FilterTreeNode(
                                    "<html><span style=\"color: black; font-weight: bold;\">"
                                            + StringEscapeUtils.escapeHtml(ftype.getName().toString())
                                            + "</span></html>");
                            fgroupNode.add(filterTypeNode);
                        }

                        // For some reason sorting the list of filters before inserting into tree
                        // messes up the tree nodes
                        //              Collections.sort(ftype.getFilterList(), new Comparator<Filter>(){
                        //            @Override
                        //            public int compare(Filter f1, Filter f2) {
                        //                return (f1.getName().compareToIgnoreCase(f2.getName()));
                        //            }                
                        //              });
                        addFilterChildren(filterTypeNode, ftype.getUrlKey().toString(), ftype.getFilterList());
                    }
                }

                // Create the tree view with the populated root
                filterTree = new JFilterTree(root);
                filterTree.setRootVisible(false); // don't want the root to be visible; not a standard thing, so not implemented within JTriStateTree
                filterTree.setLargeModel(true); // potentially can have many filters!
                filterTree.addCheckingListener(thisPanel);

                // insert the created tree view into the filters panel
                jpFilters.removeAll();
                jpFilters.setLayout(new GridLayout(0, 1));
                jpFilters.add(filterTree);
                jpFilters.validate();

                // add actions from the contextual menu of the filter tree into the toolbar
                // that replicates those plus adds additional ones in this panel
                tbFilterTreeToolbar.removeAll();
                for (Action a : filterTree.getContextualMenuActions()) {
                    tbFilterTreeToolbar.add(a);
                }

                // enable all actions
                filterTree.enableAllContextualMenuAction(true);
            } catch (Exception e) {
                logger.error("Failed to load filter tree from the following URL: " + filtersURL, e);
            }
        }

        /**
         * Recursive method to populate a node of the filter tree with all
         * sub-filters.
         * 
         * Ontological terms will be underlined.
         * 
         * @param root Tree node to add children to.
         * @param filterList A list of Filters to add to "root" as children.
         */
        private void addFilterChildren(FilterTreeNode root, String filterCategory, List<Filter> filterList) {
            for (Filter f : filterList) {

                // Is this an ontological term?
                String ontology = null;
                if (FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue())) {
                    String nameAndNamespace = f.getUrlValue().substring(1, f.getUrlValue().length() - 1);
                    String[] namePlusNamespace = nameAndNamespace.split("#");
                    ontology = JFilterTree.getOntologyFromNamespace(namePlusNamespace[0]);
                }

                FilterTreeNode fNode = new FilterTreeNode("<html><span color=\"black\""
                        /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? " style=\"text-decoration: underline;\"" : "") */ + ">"
                        + StringEscapeUtils.escapeHtml(f.getName()) + " (" + f.getCount() + ")" + "</span>" +
                /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? "<span color=\"gray\">&nbsp;("+f.getCount().intValue()+")</span></html>" : "</html>"),*/
                (ontology != null ? "<span color=\"#3090C7\"> &lt;" + ontology + "&gt;</span></html>"
                        : "</html>"), filterCategory, f.getUrlValue());
                addFilterChildren(fNode, filterCategory, f.getFilterList());

                // Insert the node into the (alphabetically) sorted children nodes
                List<FilterTreeNode> children = Collections.list(root.children());
                // Search for the index the new node should be inserted at
                int index = Collections.binarySearch(children, fNode, new Comparator<FilterTreeNode>() {
                    @Override
                    public int compare(FilterTreeNode o1, FilterTreeNode o2) {
                        String str1 = ((String) o1.getUserObject()).toString();
                        String str2 = ((String) o2.getUserObject()).toString();
                        return (str1.compareToIgnoreCase(str2));
                    }
                });

                if (index < 0) { // not found - index will be equal to -insertion-point -1
                    index = -index - 1;
                } // else node with the same name found in the array - insert it at that position
                root.insert(fNode, index);

                //root.add(fNode);
            }
        }
    }.start();
}

From source file:org.zaproxy.zap.extension.pscanrules.TestInfoSessionIdURL.java

/**
 * Check if an external link is present inside a vulnerable url
 *
 * @param msg the message that need to be checked
 * @param id the id of the session/*from www  .  j a  va2s.com*/
 * @throws URIException if there're some trouble with the Request
 */
private void checkSessionIDExposure(HttpMessage msg, int id) throws URIException {
    // Vector<String> referrer = msg.getRequestHeader().getHeaders(HttpHeader.REFERER);
    int risk = (msg.getRequestHeader().isSecure()) ? Alert.RISK_MEDIUM : Alert.RISK_LOW;
    String body = msg.getResponseBody().toString();
    String host = msg.getRequestHeader().getURI().getHost();
    String linkHostName;
    Matcher matcher;

    for (Pattern pattern : EXT_LINK_PATTERNS) {
        matcher = pattern.matcher(body);

        if (matcher.find()) {
            linkHostName = matcher.group(1);
            if (host.compareToIgnoreCase(linkHostName) != 0) {

                // Raise an alert according to Passive Scan Rule model
                // description, uri, param, attack, otherInfo,
                // solution, reference, evidence, cweId, wascId, msg
                Alert alert = new Alert(getPluginId(), risk, Alert.CONFIDENCE_MEDIUM, getRefererAlert());
                alert.setDetail(getRefererDescription(), msg.getRequestHeader().getURI().getURI(), "",
                        linkHostName, "", getRefererSolution(), getReference(), linkHostName, // evidence
                        getCweId(), // CWE Id
                        getWascId(), // WASC Id - Info leakage
                        msg);

                parent.raiseAlert(id, alert);

                break; // Only need one
            }
        }
    }
}

From source file:aurelienribon.gdxsetupui.ui.panels.LibrarySelectionPanel.java

public synchronized void rebuildLibraries() {
    List<String> names = new ArrayList<String>(Ctx.libs.getNames());

    for (int i = names.size() - 1; i >= 0; i--) {
        if (Ctx.libs.getDef(names.get(i)) == null)
            names.remove(i);/*w ww .j  ava 2  s.  co m*/
    }

    Collections.sort(names, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            String name1 = Ctx.libs.getDef(o1).name;
            String name2 = Ctx.libs.getDef(o2).name;
            return name1.compareToIgnoreCase(name2);
        }
    });

    librariesPanel.removeAll();
    librariesScrollPane.revalidate();

    for (String name : names) {
        if (!name.equals("libgdx"))
            buildLibraryPanel(name);
        preselectLibraryArchive(name);
    }
}

From source file:org.wso2.carbon.localentry.service.LocalEntryAdmin.java

public String getEntryNamesString() throws LocalEntryAdminException {
    final Lock lock = getLock();
    try {/* w w w.jav a  2s . com*/
        lock.lock();
        SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
        Map gloabalEntriesMap = synapseConfiguration.getLocalRegistry();
        List<String> sequenceList = new ArrayList<String>();
        List<String> endpointList = new ArrayList<String>();
        List<String> entryList = new ArrayList<String>();
        StringBuffer entrySb = new StringBuffer();
        StringBuffer endpointSb = new StringBuffer();
        StringBuffer sequenceSb = new StringBuffer();
        for (Object entryValue : gloabalEntriesMap.values()) {
            if (entryValue instanceof Endpoint) {
                Endpoint endpoint = (Endpoint) entryValue;
                String name = endpoint.getName();
                if (name != null) {
                    endpointList.add(name);
                }
            } else if (entryValue instanceof SequenceMediator) {
                SequenceMediator sequenceMediator = (SequenceMediator) entryValue;
                String name = sequenceMediator.getName();
                if (name != null) {
                    sequenceList.add(name);
                }
            } else if (entryValue instanceof Entry) {
                Entry entry = (Entry) entryValue;
                if (!entry.isDynamic() && !entry.isRemote()) { // only care pre-defined entries
                    String key = entry.getKey();
                    if (SynapseConstants.SERVER_IP.equals(key) || SynapseConstants.SERVER_HOST.equals(key)) {
                        continue;
                    }
                    entryList.add(key);
                }
            }
        }

        if (!sequenceList.isEmpty()) {

            Collections.sort(sequenceList, new Comparator<String>() {
                public int compare(String o1, String o2) {
                    return o1.compareToIgnoreCase(o2);
                }
            });
            for (String name : sequenceList) {
                if (name != null) {
                    sequenceSb.append("[Sequence]-").append(name).append(" ");
                }
            }
        }

        if (!entryList.isEmpty()) {

            Collections.sort(entryList, new Comparator<String>() {
                public int compare(String o1, String o2) {
                    return o1.compareToIgnoreCase(o2);
                }
            });
            for (String name : entryList) {
                if (name != null) {
                    entrySb.append("[Entry]-").append(name).append(" ");
                }
            }
        }

        if (!endpointList.isEmpty()) {

            Collections.sort(endpointList, new Comparator<String>() {
                public int compare(String o1, String o2) {
                    return o1.compareToIgnoreCase(o2);
                }
            });
            for (String name : endpointList) {
                if (name != null) {
                    endpointSb.append("[Enpoint]-").append(name).append(" ");
                }
            }
        }
        return endpointSb.toString() + entrySb.toString() + sequenceSb.toString();
    } finally {
        lock.unlock();
    }
}

From source file:org.apache.directory.fortress.core.util.VUtil.java

/**
 * Perform simple reasonability check on contraint endDate value.
 * @param endDate if set, must be equal to {@link #DATE_LEN}.
 * @throws ValidationException in the event value falls out of range.
 *//*www  . j  a va 2s.c o m*/
public void endDate(String endDate) throws ValidationException {
    if (StringUtils.isNotEmpty(endDate)) {
        if (endDate.compareToIgnoreCase(GlobalIds.NONE) != 0) {
            if (endDate.length() != DATE_LEN || checkDate(endDate)) {
                String error = "endDate - invalid endDate value [" + endDate + "]";
                throw new ValidationException(GlobalErrIds.CONST_ENDDATE_INVLD, error);
            }
        }
    } else {
        String error = "endDate - null or empty endDate value";
        throw new ValidationException(GlobalErrIds.CONST_ENDDATE_NULL, error);
    }
}

From source file:org.apache.directory.fortress.core.util.VUtil.java

/**
 * Perform simple reasonability check on contraint dayMask value.
 * @param dayMask if set, will be validated.
 * @throws ValidationException in the event value falls out of range.
 *///w  w  w.  j  a  va2 s  . co  m
public void dayMask(String dayMask) throws ValidationException {
    if (StringUtils.isNotEmpty(dayMask)) {
        if (dayMask.compareToIgnoreCase(GlobalIds.ALL) != 0) {
            if (dayMask.length() > DAYMASK_LEN || checkMask(dayMask)) {
                String error = "dayMask - invalid dayMask value [" + dayMask + "]";
                throw new ValidationException(GlobalErrIds.CONST_DAYMASK_INVLD, error);
            }
        }
    } else {
        String error = "dayMask - null or empty dayMask value";
        throw new ValidationException(GlobalErrIds.CONST_DAYMASK_NULL, error);
    }
}

From source file:org.apache.directory.fortress.core.util.VUtil.java

/**
 * Perform simple reasonability check on contraint beginDate value.
 * @param beginDate if set, must be equal to {@link #DATE_LEN}.
 * @throws ValidationException in the event value falls out of range.
 *//*from   w w w  . j av  a 2s . c om*/
public void beginDate(String beginDate) throws ValidationException {
    if (StringUtils.isNotEmpty(beginDate)) {
        if ((beginDate.compareToIgnoreCase(GlobalIds.NONE) != 0)
                && ((beginDate.length() != DATE_LEN) || checkDate(beginDate))) {
            String error = "beginDate - invalid beginDate value [" + beginDate + "]";
            throw new ValidationException(GlobalErrIds.CONST_BEGINDATE_INVLD, error);
        }
    } else {
        String error = "beginDate - null or empty beginDate value";
        throw new ValidationException(GlobalErrIds.CONST_BEGINDATE_NULL, error);
    }
}