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:com.mycompany.trafficimportfileconverter2.Main2Controller.java

private void autoSearch() {
    new Thread(() -> {
        File[] files = filechooser.getInitialDirectory().listFiles(new FileFilter() {
            @Override//from   ww  w . j a  v  a 2s.  c  om
            public boolean accept(File pathname) {
                String x = FilenameUtils.getExtension(pathname.getAbsolutePath());
                return x.compareToIgnoreCase("tsv") == 0;
            }
        });

        File mostRecent = Arrays.stream(files).max((x, y) -> Long.compare(x.lastModified(), y.lastModified()))
                .orElse(null);
        if (mostRecent == null) {
            return;
        }
        Platform.runLater(() -> {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setContentText("We found the following TSV file in your default location:\n\""
                    + mostRecent.getName() + "\"\n" + "Modified: " + new Date(mostRecent.lastModified())
                    + "\n\n" + "Would you like load this file?");
            Optional<ButtonType> answer = alert.showAndWait();
            if (answer.isPresent() && answer.get().getButtonData().equals(ButtonData.OK_DONE)) {
                System.out.println(answer.get());
                setInputFile(mostRecent);

                //setting the input file is enough to trigger the load!
                //     loadInInfo(mostRecent);
                //not safe, just load the file in for you.
                //                    onBtnGo(null);
            } else {
            }
        });

    }).start();
}

From source file:org.talend.librariesmanager.ui.dialogs.ConfigModuleDialog.java

private void createPlatformGroup(Composite composite) {
    platfromRadioBtn = new Button(composite, SWT.RADIO);
    platfromRadioBtn.setText(Messages.getString("ConfigModuleDialog.platfromBtn"));

    platformCombo = new Combo(composite, SWT.READ_ONLY);
    platformCombo.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL));
    platfromRadioBtn.addSelectionListener(new SelectionAdapter() {

        @Override//w ww  .  ja v a 2  s.c  o m
        public void widgetSelected(SelectionEvent e) {
            setPlatformGroupEnabled(true);
            setRepositoryGroupEnabled(false);
            setupMavenURIByModuleName(platformCombo.getText());
        }
    });

    jarsAvailable = new HashSet<String>();
    Set<ModuleNeeded> unUsedModules = ModulesNeededProvider.getAllManagedModules();
    for (ModuleNeeded module : unUsedModules) {
        if (module.getStatus() == ELibraryInstallStatus.INSTALLED) {
            jarsAvailable.add(module.getModuleName());
        }
    }
    String[] moduleValueArray = jarsAvailable.toArray(new String[jarsAvailable.size()]);
    Comparator<String> comprarator = new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
        }
    };
    Arrays.sort(moduleValueArray, comprarator);
    platformCombo.setItems(moduleValueArray);
    if (!StringUtils.isEmpty(moduleName) && jarsAvailable.contains(moduleName)) {
        platformCombo.setText(moduleName);
    } else {
        platformCombo.setText(moduleValueArray[0]);
    }
    platformCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            moduleName = platformCombo.getText();
            setupMavenURIByModuleName(platformCombo.getText());
        }
    });
}

From source file:org.andstatus.app.net.social.pumpio.ConnectionPumpio.java

private ConnectionAndUrl getConnectionAndUrlForUsername(ApiRoutineEnum apiRoutine, String username)
        throws ConnectionException {
    ConnectionAndUrl conu = new ConnectionAndUrl();
    conu.url = this.getApiPath(apiRoutine);
    if (TextUtils.isEmpty(conu.url)) {
        throw new ConnectionException(StatusCode.UNSUPPORTED_API,
                "The API is not supported yet: " + apiRoutine);
    }// w  ww.  j av a2s.c  om
    if (TextUtils.isEmpty(username)) {
        throw new ConnectionException(StatusCode.BAD_REQUEST, apiRoutine + ": userName is required");
    }
    String nickname = usernameToNickname(username);
    if (TextUtils.isEmpty(nickname)) {
        throw new ConnectionException(StatusCode.BAD_REQUEST,
                apiRoutine + ": wrong userName='" + username + "'");
    }
    String host = usernameToHost(username);
    conu.httpConnection = http;
    if (TextUtils.isEmpty(host)) {
        throw new ConnectionException(StatusCode.BAD_REQUEST,
                apiRoutine + ": host is empty for the userName='" + username + "'");
    } else if (http.data.originUrl == null || host.compareToIgnoreCase(http.data.originUrl.getHost()) != 0) {
        MyLog.v(this, "Requesting data from the host: " + host);
        HttpConnectionData connectionData1 = http.data.copy();
        connectionData1.oauthClientKeys = null;
        connectionData1.originUrl = UrlUtils.buildUrl(host, connectionData1.isSsl());
        conu.httpConnection = http.getNewInstance();
        conu.httpConnection.setConnectionData(connectionData1);
    }
    if (!conu.httpConnection.data.areOAuthClientKeysPresent()) {
        conu.httpConnection.registerClient(getApiPath(ApiRoutineEnum.REGISTER_CLIENT));
        if (!conu.httpConnection.getCredentialsPresent()) {
            throw ConnectionException.fromStatusCodeAndHost(StatusCode.NO_CREDENTIALS_FOR_HOST,
                    "No credentials", conu.httpConnection.data.originUrl);
        }
    }
    conu.url = conu.url.replace("%nickname%", nickname);
    return conu;
}

From source file:com.sfs.whichdoctor.dao.WhichDoctorDAOImpl.java

/**
 * Load.//from  w w w .  ja v a  2s . co  m
 *
 * @param guid the guid
 * @param type the type
 *
 * @return the collection< which doctor bean>
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<WhichDoctorBean> load(final int guid, final String type)
        throws WhichDoctorDaoException {
    if (type == null) {
        throw new NullPointerException("The type parameter cannot be null");
    }

    dataLogger.info("History of GUID: " + guid + " requested");

    String loadSQL = getSQL().getValue("whichdoctor/load/person");

    if (type.compareToIgnoreCase("organisation") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/organisation");
    }
    if (type.compareToIgnoreCase("debit") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/debit");
    }
    if (type.compareToIgnoreCase("credit") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/credit");
    }
    if (type.compareToIgnoreCase("receipt") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/receipt");
    }
    if (type.compareToIgnoreCase("reimbursement") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/reimbursement");
    }
    if (type.compareToIgnoreCase("rotation") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/rotation");
    }
    if (type.compareToIgnoreCase("group") == 0) {
        loadSQL = getSQL().getValue("whichdoctor/load/group");
    }

    Collection<WhichDoctorBean> history = new ArrayList<WhichDoctorBean>();

    try {
        history = this.getJdbcTemplateReader().query(loadSQL, new Object[] { guid }, new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                WhichDoctorBean loadedHistory = loadHistory(rs);
                loadedHistory.setObjectType(type);

                return loadedHistory;
            }
        });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search: " + ie.getMessage());
    }
    return history;
}

From source file:edu.ucuenca.authorsdisambiguation.Distance.java

private double NGD(String a, String b) throws IOException, SQLException {

    a = a.trim();//from w w  w . j  a  v  a2  s  . c o m
    b = b.trim();

    if (a.compareToIgnoreCase(b) == 0) {
        return 0;
    }

    //double n0 = getResultsCount(""+a+"");
    //double n1 = getResultsCount(""+b+"");
    //String c = ""+a+" "+b+"";
    double n0 = getResultsCount("\"" + a + "\"~10");
    double n1 = getResultsCount("\"" + b + "\"~10");
    String c = "\"" + a + " " + b + "\"~50";

    double n2 = getResultsCount(c);
    //double m = 5026040.0 * 590;

    double m = 5029469;

    double distance = 0;

    int Measure = 0;

    double l1 = Math.max(Math.log10(n0), Math.log10(n1)) - Math.log10(n2);
    double l2 = Math.log10(m) - Math.min(Math.log10(n0), Math.log10(n1));

    if (Measure == 0) {
        distance = l1 / l2;
    }

    if (Measure == 1) {
        distance = 1 - (Math.log10(n2) / Math.log10(n0 + n1 - n2));
    }

    if (n0 == 0 || n1 == 0 || n2 == 0) {
        distance = 1;
    }

    //System.out.println("n0="+n0);
    //System.out.println("n1="+n1);
    //System.out.println("n2="+n2);
    //System.out.println(a + "," + b + "=" + distance2);
    return distance;
}

From source file:org.iavante.sling.gad.hospies.impl.HospiesImpl.java

/**
 * check if the profile exists in the system
 * //from  www .ja va 2  s.c om
 * @param profile
 *          profile to check
 * @return true if exists or false in other case
 */
private boolean checkProfileExist(String profile) {

    for (int i = 0; i < profiles.length; i++)
        if (profile.compareToIgnoreCase(profiles[i]) == 0)
            return true;
    return false;
}

From source file:com.krawler.esp.servlets.ExportImportContactsServlet.java

/**
 * Processes requests for both HTTP// ww w  . j a v  a  2s.c om
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html;charset=UTF-8");
    String doAction = request.getParameter("do");
    Connection conn = null;
    String result = KWLErrorMsgs.rsSuccessFalse;
    String res = "";
    try {
        conn = DbPool.getConnection();
        if (doAction.compareToIgnoreCase("export") == 0) {
            doExport(conn, request, response);
        } else if (doAction.compareToIgnoreCase("import") == 0) {
            res = doImport(request, conn);
        } else if (doAction.compareToIgnoreCase("getheaders") == 0) {
            res = getFileHeaders(request);
        }

        if (doAction.compareToIgnoreCase("export") == 0) {
            result = KWLErrorMsgs.rsSuccessTrue;
        } else if (doAction.compareToIgnoreCase("import") == 0
                || doAction.compareToIgnoreCase("getheaders") == 0) {
            result = res;
        }
        conn.commit();
    } catch (IOException ex) {
        DbPool.quietRollback(conn);
        Logger.getLogger(ExportImportContactsServlet.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    } catch (ServiceException ex) {
        DbPool.quietRollback(conn);
        Logger.getLogger(ExportImportContactsServlet.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    } catch (SessionExpiredException ex) {
        DbPool.quietRollback(conn);
        Logger.getLogger(ExportImportContactsServlet.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    } catch (Exception ex) {
        DbPool.quietRollback(conn);
        Logger.getLogger(ExportImportContactsServlet.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    } finally {
        DbPool.quietClose(conn);
        response.getWriter().write(result);
        response.getWriter().close();
    }
}

From source file:org.openecomp.sdnc.sli.provider.SvcLogicExpressionResolver.java

private static String evalCompareExpression(SvcLogicBinaryExpression expr, SvcLogicNode node,
        SvcLogicContext ctx) throws SvcLogicException {

    List<OperatorType> operators = expr.getOperators();
    List<SvcLogicExpression> operands = expr.getOperands();

    if ((operators.size() != 1) || (operands.size() != 2)) {
        throw new SvcLogicException("Invalid comparison expression : " + expr);
    }/*from w  w  w  . j a  va 2 s  .c o m*/

    OperatorType operator = operators.get(0);
    String op1Value = evaluate(operands.get(0), node, ctx);
    String op2Value = evaluate(operands.get(1), node, ctx);

    if ((StringUtils.isNotEmpty(op1Value) && StringUtils.isNumeric(op1Value) && StringUtils.isNotEmpty(op2Value)
            && StringUtils.isNumeric(op2Value))) {
        try {
            double op1dbl = Double.parseDouble(op1Value);
            double op2dbl = Double.parseDouble(op2Value);

            switch (operator) {
            case equalOp:
                return (Boolean.toString(op1dbl == op2dbl));
            case neOp:
                return (Boolean.toString(op1dbl != op2dbl));
            case ltOp:
                return (Boolean.toString(op1dbl < op2dbl));
            case leOp:
                return (Boolean.toString(op1dbl <= op2dbl));
            case gtOp:
                return (Boolean.toString(op1dbl > op2dbl));
            case geOp:
                return (Boolean.toString(op1dbl >= op2dbl));
            default:
                return (null);
            }
        } catch (NumberFormatException e) {
            throw new SvcLogicException("Caught exception trying to compare numeric values", e);
        }
    } else {

        int compResult = 0;

        if (op1Value == null) {
            compResult = -1;
        } else if (op2Value == null) {
            compResult = 1;
        } else {
            compResult = op1Value.compareToIgnoreCase(op2Value);
        }

        switch (operator) {
        case equalOp:
            return (Boolean.toString(compResult == 0));
        case neOp:
            return (Boolean.toString(compResult != 0));
        case ltOp:
            return (Boolean.toString(compResult < 0));
        case leOp:
            return (Boolean.toString(compResult <= 0));
        case gtOp:
            return (Boolean.toString(compResult > 0));
        case geOp:
            return (Boolean.toString(compResult >= 0));
        default:
            return (null);
        }
    }

}

From source file:emea.summit.architects.HackathlonAPIResource.java

private boolean inOrder(Iterator<RequestPayload> reindeersIt, String reindeer) {
    String nextReindeer = null;/*from www . ja v a  2s  .  c o  m*/
    if (reindeersIt == null || !reindeersIt.hasNext()) {
        return true;
    }
    if (reindeersIt.hasNext()) {
        nextReindeer = reindeersIt.next().getReindeerName();
        System.out.println(" Compare " + reindeer + " vs " + nextReindeer);
        if (reindeer != null && reindeer.compareToIgnoreCase(nextReindeer) > ZERO) {
            return false;
        }
        return inOrder(reindeersIt, nextReindeer);
    }
    return true;
}

From source file:org.wso2.carbon.sequences.services.SequenceAdmin.java

public String getEntryNamesString() throws SequenceEditorException {
    final Lock lock = getLock();
    try {//from   w w w  .ja  v  a2  s  .c o m
        lock.lock();
        SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
        Map globalEntriesMap = 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 : globalEntriesMap.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 local 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("[Endpoint]-").append(name).append(" ");
                }
            }
        }
        return endpointSb.toString() + entrySb.toString() + sequenceSb.toString();
    } catch (Exception axisFault) {
        handleException("Error during retrieving local registry", axisFault);
    } finally {
        lock.unlock();
    }
    return "";
}