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:alter.vitro.vgw.service.ContinuationOfProvisionService.java

public String[] findNextEquivalentNode(String vsnId, List<String> nodeIdsInThisVSN, String sourceNode,
        String capabilityId) {/*ww  w. j av  a  2  s .c  om*/
    String[] retNodeReplacingInfo = null;
    boolean foundCachedReplacement = false;
    boolean foundAReplacement = false;
    // first search in the replacement cache for this VSNid
    if (!cachedReplacedResources.isEmpty() && cachedReplacedResources.containsKey(vsnId)) {
        List<String[]> nodeReplaceEntries = cachedReplacedResources.get(vsnId);
        for (String[] entryTmp : nodeReplaceEntries) {
            if (entryTmp.length == 3 && entryTmp[0] != null && !entryTmp[0].isEmpty()
                    && entryTmp[0].compareToIgnoreCase(sourceNode) == 0 && nodeIdsInThisVSN != null
                    && !nodeIdsInThisVSN.contains(entryTmp[1]) && entryTmp[1] != null && !entryTmp[1].isEmpty()
                    && entryTmp[1].compareToIgnoreCase(sourceNode) != 0 && entryTmp[2] != null
                    && !entryTmp[2].isEmpty() && entryTmp[2].compareToIgnoreCase(capabilityId) == 0) {
                // check if this node is enabled (or also disabled)
                if (ResourceAvailabilityService.getInstance().isNodeResourceAvailable(vsnId, entryTmp[1],
                        capabilityId)
                        && !replacesOtherNodeInVSN(vsnId, sourceNode, entryTmp[1], capabilityId)) {
                    // DONE: check if this node is enabled (or also disabled)

                    retNodeReplacingInfo = entryTmp;
                    foundCachedReplacement = true;
                }
                if (!foundCachedReplacement) {
                    // TODO: if this entry is stale or the node is disabled we should also remove it!
                    removeReplacementVectorForNodeOfVSN(vsnId, sourceNode, capabilityId);
                }
                break;
            }
        }
    }
    // if not found a replacement in cache, then search based on stored equiv lists and also if found a match, then
    //                  add to the replacement cache and return it.
    if (!foundCachedReplacement && !cachedSetsOfEquivalency.isEmpty()) {
        for (Integer setIdTmp : cachedSetsOfEquivalency.keySet()) {
            if (foundAReplacement) {
                break;
            }
            List<String> setOfEquivEntry = cachedSetsOfEquivalency.get(setIdTmp);
            if (setOfEquivEntry != null && !setOfEquivEntry.isEmpty()) {
                for (String itemNode : setOfEquivEntry) {
                    if (itemNode.compareToIgnoreCase(sourceNode) == 0) {
                        // we iterate the set one more time
                        for (String itemReplaceCandidateNode : setOfEquivEntry) {
                            if (!foundAReplacement
                                    && itemReplaceCandidateNode.compareToIgnoreCase(sourceNode) != 0
                                    && nodeIdsInThisVSN != null
                                    && !nodeIdsInThisVSN.contains(itemReplaceCandidateNode)
                                    && ResourceAvailabilityService.getInstance().isNodeResourceAvailable(vsnId,
                                            itemReplaceCandidateNode, capabilityId)
                                    && !replacesOtherNodeInVSN(vsnId, sourceNode, itemReplaceCandidateNode,
                                            capabilityId)) {

                                // DONE: check if this node is enabled (or also disabled)\
                                // TODO: check if this node actually exists in the VGW currently (or is it stale)!
                                // TODO: if capability is set as an argument, we should check that if the (alive) replacement has also this capability
                                // DONE: add node in the cache of replacements!
                                retNodeReplacingInfo = updateReplacementVectorForNodeOfVSN(vsnId, sourceNode,
                                        itemReplaceCandidateNode, capabilityId);

                                foundAReplacement = true;
                                break;
                            }

                        }
                        break;
                    }
                } // end of loop over nodes of an equiv set
            }

        } // an of loop over equiv sets of the cache
    }
    return retNodeReplacingInfo;
}

From source file:com.sshtools.common.hosts.AbstractHostKeyVerification.java

/**
 *
 *
 * @param host/*from  w  w w.  j a  v a 2s . c o  m*/
 * @param pk
 *
 * @return
 *
 * @throws TransportProtocolException
 */
public boolean verifyHost(String host, SshPublicKey pk) throws TransportProtocolException {
    String fingerprint = pk.getFingerprint();
    log.info("Verifying " + host + " host key");

    if (log.isDebugEnabled()) {
        log.debug("Fingerprint: " + fingerprint);
    }

    // See if the host is denied by looking at the denied hosts list
    if (deniedHosts.contains(host)) {
        onDeniedHost(host);

        return false;
    }

    // Try the allowed hosts by looking at the allowed hosts map
    if (allowedHosts.containsKey(host)) {
        // The host is allowed so check the fingerprint
        String currentFingerprint = (String) allowedHosts.get(host);

        if (currentFingerprint.compareToIgnoreCase(fingerprint) == 0) {
            return true;
        }

        // The host key does not match the recorded so call the abstract
        // method so that the user can decide
        onHostKeyMismatch(host, currentFingerprint, fingerprint);

        // Recheck the after the users input
        return checkFingerprint(host, fingerprint);
    } else {
        // The host is unknown os ask the user
        onUnknownHost(host, fingerprint);

        // Recheck ans return the result
        return checkFingerprint(host, fingerprint);
    }
}

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

/**
 * Gets a list of Data Providers given some parameters
 * //from  w w w . ja  v  a2 s. c o m
 * @param params
 * @return
 * @throws GbifWebServiceException
 */
@SuppressWarnings("unchecked")
public Map<String, Object> findProviderRecords(ProviderParameters params) throws GbifWebServiceException {

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

    SearchResultsDTO searchResultsDTO = null;
    List<DataProviderDTO> dataProviderList = null;

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

    //a Tree Map to be able to arrange providers by their name
    Map<DataProviderDTO, Set<Map<String, Object>>> dataProviderMap = new TreeMap<DataProviderDTO, Set<Map<String, Object>>>(
            new Comparator() {
                public int compare(Object a, Object b) {
                    DataProviderDTO dataProvider1 = (DataProviderDTO) a;
                    DataProviderDTO dataProvider2 = (DataProviderDTO) b;
                    String key1 = dataProvider1.getName().toString();
                    String key2 = dataProvider2.getName().toString();
                    return key1.compareToIgnoreCase(key2);
                }
            });

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

    try {
        searchResultsDTO = dataResourceManager.findDataProviders(params.getName(), true,
                params.getIsoCountryCode(), params.getModifiedSince(), params.getSearchConstraints());

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

        summaryMap = returnSummary(params, dataProviderList, true);

        dataProviderMap = new TreeMap<DataProviderDTO, Set<Map<String, Object>>>(new Comparator() {
            public int compare(Object a, Object b) {
                DataProviderDTO dataProvider1 = (DataProviderDTO) a;
                DataProviderDTO dataProvider2 = (DataProviderDTO) b;
                String key1 = dataProvider1.getName().toString();
                String key2 = dataProvider2.getName().toString();
                return key1.compareToIgnoreCase(key2);
            }
        });

        //iterate over the DataProvider list to obtain the DataResources for each DP
        for (DataProviderDTO dataProviderDTO : dataProviderList) {
            //obtain the DataResourceDTOs for this DataProvider
            List<DataResourceDTO> dataResourceDTOList = dataResourceManager
                    .getDataResourcesForProvider(dataProviderDTO.getKey());

            //for storing all the DataResources along with its elements
            Set<Map<String, Object>> dataResourceMapList = 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 = "";
                    String key2 = "";

                    if (dataResource1.getName() != null)
                        key1 = dataResource1.getName().toString();
                    if (dataResource2.getName() != null)
                        key2 = dataResource2.getName().toString();

                    return key1.compareToIgnoreCase(key2);
                }
            });

            //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);

                //add the data resource map to the list
                dataResourceMapList.add(dataResourceMap);
            }

            dataProviderMap.put(dataProviderDTO, dataResourceMapList);

        }

        results.put("count", searchResultsDTO.getResults().size());
        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:com.sshtools.common.hosts.AbstractHostKeyVerification.java

private boolean checkFingerprint(String host, String fingerprint) {
    String currentFingerprint = (String) allowedHosts.get(host);

    if (currentFingerprint != null) {
        if (currentFingerprint.compareToIgnoreCase(fingerprint) == 0) {
            return true;
        }/* w  w w  .j  a va  2s . com*/
    }

    return false;
}

From source file:org.onesun.atomator.core.SubscriptionManager.java

public static Channel newSubscription(SubscriptionEntry subscriptionEntry, boolean persist) {
    String type = subscriptionEntry.getChannelType();

    Channel channel = null;/*ww  w .  j  av  a  2 s.co  m*/
    SecretEntry entry = OAuthSecretsManager.get(type);
    Properties properties = null;
    Map<String, String> extendedParams = null;

    // There must be an entry for all authenticable sources
    if (entry != null) {
        // KeyStore must exist for authenticated sources
        properties = toProperties(entry);

        // Load any additional properties for the channels
        PropertyEntry propertyEntry = ScribePropertiesManager.getEntries().get(type);
        if (propertyEntry != null) {
            if (propertyEntry.getType().compareToIgnoreCase("scribe") == 0) {
                properties.put(propertyEntry.getKey(), propertyEntry.getValue());
            }
            if (propertyEntry.getType().compareToIgnoreCase("oauth.extension") == 0) {
                if (extendedParams == null) {
                    extendedParams = new HashMap<String, String>();
                }

                extendedParams.put(propertyEntry.getKey(), propertyEntry.getValue());
            }
        }
    }

    if (persist == true) {
        DAOFactory.getSubscriptionDAO().append(subscriptionEntry);
    }

    if (type.compareToIgnoreCase(AdaptorFactory.GENERIC_ADAPTOR_NAME) == 0) {
        channel = new UnAuthenticatedChannel(subscriptionEntry);
    } else {
        channel = new AuthenticatedChannel(subscriptionEntry, properties, extendedParams,
                Configuration.getAuthenticator());
    }

    if (channel != null)
        channel.setup();
    return channel;
}

From source file:com.example.mobileid.GcmIntentService.java

private void sendNotification(Intent intent) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Bundle extras = intent.getExtras();//from w  w w  . ja  v a  2 s. c  o  m
    JSONObject gcmObj;
    try {
        gcmObj = new JSONObject(extras.getString("message"));
        String msg = gcmObj.getString("info");

        Intent passIntent = new Intent();
        passIntent.setClass(this, MainActivity.class);
        passIntent.putExtra("gcmMsg", gcmObj.toString());

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, passIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

        if (msg.compareToIgnoreCase("websign") != 0) {
            //              NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            mBuilder.setSmallIcon(R.drawable.ic_launcher).setContentTitle("mobileID")
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);
        } else {
            //            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            mBuilder.setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Web Sign - " + gcmObj.getString("title"))
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                    .setContentText(gcmObj.getString("content"));
        }

        //default notification sound
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);

        //cleared after clicking
        mBuilder.setAutoCancel(true);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.hops.hopsworks.api.jupyter.JupyterService.java

@GET
@Path("/running")
@Produces(MediaType.APPLICATION_JSON)/*ww w . j a  v a2s.  c  o  m*/
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
public Response isRunning(@Context SecurityContext sc, @Context HttpServletRequest req)
        throws ServiceException {

    String hdfsUser = getHdfsUser(sc);
    JupyterProject jp = jupyterFacade.findByUser(hdfsUser);
    if (jp == null) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_SERVERS_NOT_FOUND, Level.FINE);
    }
    // Check to make sure the jupyter notebook server is running
    boolean running = jupyterProcessFacade.pingServerJupyterUser(jp.getPid());
    // if the notebook is not running but we have a database entry for it,
    // we should remove the DB entry (and restart the notebook server).
    if (!running) {
        jupyterFacade.removeNotebookServer(hdfsUser);
        throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_SERVERS_NOT_RUNNING, Level.FINE);
    }
    String externalIp = Ip.getHost(req.getRequestURL().toString());
    settings.setHopsworksExternalIp(externalIp);
    Integer port = req.getLocalPort();
    String endpoint = externalIp + ":" + port;
    if (endpoint.compareToIgnoreCase(jp.getHostIp()) != 0) {
        // update the host_ip to whatever the client saw as the remote host:port
        jp.setHostIp(endpoint);
        jupyterFacade.update(jp);
    }

    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(jp).build();
}

From source file:org.apache.flume.sink.hive.HiveSink.java

private HiveEventSerializer createSerializer(String serializerName) {
    if (serializerName.compareToIgnoreCase(HiveDelimitedTextSerializer.ALIAS) == 0
            || serializerName.compareTo(HiveDelimitedTextSerializer.class.getName()) == 0) {
        return new HiveDelimitedTextSerializer();
    } else if (serializerName.compareToIgnoreCase(HiveJsonSerializer.ALIAS) == 0
            || serializerName.compareTo(HiveJsonSerializer.class.getName()) == 0) {
        return new HiveJsonSerializer();
    }//from   w  w  w  . j av a  2 s  .  c  o m

    try {
        return (HiveEventSerializer) Class.forName(serializerName).newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "Unable to instantiate serializer: " + serializerName + " on sink: " + getName(), e);
    }
}

From source file:alter.vitro.vgw.service.ContinuationOfProvisionService.java

/**
 * Processes synch updates to the sets of equivalency received from the VSP.
 *//*from  w w  w .  jav a  2  s . com*/
public void handleVSPUpdateForSetsOfEquivalency(EquivNodesListItemType reqItem) {
    if (reqItem != null && reqItem.getListId() != null && !reqItem.getListId().isEmpty()
            && reqItem.getNodeVec() != null && reqItem.getNodeVec().getNodeId() != null
            && !reqItem.getNodeVec().getNodeId().isEmpty()) {
        Integer listCandId = 0;
        try {
            listCandId = Integer.valueOf(reqItem.getListId());
        } catch (Exception ex) {
            listCandId = 0;
            logger.error("Could not convert list id to integer!");
            return;
        }
        List<Integer> listsToBeMerged = new ArrayList<Integer>();
        for (String nodeCandId : reqItem.getNodeVec().getNodeId()) {

            for (Integer cachedListId : getCachedSetsOfEquivalency().keySet()) {
                if (getCachedSetsOfEquivalency().get(cachedListId) != null) {
                    for (String cachedNodeInList : getCachedSetsOfEquivalency().get(cachedListId)) {
                        if (cachedNodeInList.compareToIgnoreCase(nodeCandId) == 0) {
                            if (!listsToBeMerged.contains(cachedListId)) {

                                listsToBeMerged.add(cachedListId);
                            }
                        }
                    }
                }

            }
        }
        // merge all the listsToBeMerged. Be careful not to add duplicates of node names.
        List<String> resultMergedList = new ArrayList<String>();
        if (listsToBeMerged.size() > 0) {
            listCandId = listsToBeMerged.get(0); //as long as it's something
        } //else it's the id retrieved from the query/request (which is unique in the VSP, and VGW gets all ids from VSP anyway
        for (int i = 0; i < listsToBeMerged.size(); i++) {
            Integer idOfListToBeMerged = listsToBeMerged.get(i);
            // safe-double-check
            if (getCachedSetsOfEquivalency().containsKey(idOfListToBeMerged)
                    && getCachedSetsOfEquivalency().get(idOfListToBeMerged) != null) {
                for (String nodeInAList : getCachedSetsOfEquivalency().get(idOfListToBeMerged)) {
                    if (!resultMergedList.contains(nodeInAList)) {
                        resultMergedList.add(nodeInAList);
                    }
                }
                getCachedSetsOfEquivalency().remove(idOfListToBeMerged);
            }
        }
        // and after the merge, merge also the nodes in the request list (still checking for duplicates)
        for (String nodeCandId : reqItem.getNodeVec().getNodeId()) {
            if (!resultMergedList.contains(nodeCandId)) {
                resultMergedList.add(nodeCandId);
            }
        }
        getCachedSetsOfEquivalency().put(listCandId, resultMergedList);
    }
}

From source file:com.orange.oidc.tim.service.SIMStorage.java

static byte[] makeRequestBuffer(String server_url, String client_id, String scope) {

    Logd(TAG, "makeRequestBuffer " + server_url + " / " + client_id + " / " + scope);
    try {//from ww  w.j a va2 s.  c  om

        // sort scope in alphabetical order
        if (scope != null) {
            scope = scope.toLowerCase(Locale.getDefault());
            // offline_access is mandatory
            if (!scope.contains("offline_access")) {
                scope += " offline_access";
            }
            String scopes[] = scope.split("\\ ");
            if (scopes != null) {
                Arrays.sort(scopes, new Comparator<String>() {
                    @Override
                    public int compare(String s1, String s2) {
                        return s1.compareToIgnoreCase(s2);
                    }
                });
                scope = null;
                // filter null or empty strings
                for (int i = 0; i < scopes.length; i++) {
                    if (scopes[i] != null && scopes[i].length() > 0) {
                        if (scope == null)
                            scope = scopes[i];
                        else
                            scope += (" " + scopes[i]);
                    }
                }
            }
        }

        // compute buffer size
        int buffsize = 0;
        buffsize += 2 + (server_url != null ? server_url.length() : 0);
        buffsize += 2 + (client_id != null ? client_id.length() : 0);
        buffsize += 2; // redirect_uri not supported any more
        buffsize += 2 + (scope != null ? scope.length() : 0);

        byte[] buffer = new byte[buffsize + 2];

        // copy data
        int offset = 2;
        // update buffer size
        buffer[0] = (byte) ((buffsize & 0x00FF00) >> 8);
        buffer[1] = (byte) (buffsize & 0x00FF);
        // update data
        offset = copyStringToBuffer(buffer, offset, server_url);
        offset = copyStringToBuffer(buffer, offset, client_id);
        offset = copyStringToBuffer(buffer, offset, null); // redirect_uri not supported any more
        offset = copyStringToBuffer(buffer, offset, scope);
        Logd(TAG, "makeRequestBuffer");
        Logd(TAG, KryptoUtils.bytesToHex(buffer));
        return buffer;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}