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.qingstor.sdk.utils.QSJSONUtil.java

public static void sortJSONArrayAscending(List array, final String key) {

    Collections.sort((List<JSONObject>) array, new Comparator<JSONObject>() {
        @Override/*from www  .  ja v a  2  s .c  om*/
        public int compare(JSONObject o1, JSONObject o2) {
            String v1 = QSJSONUtil.toString(o1, key);
            String v2 = QSJSONUtil.toString(o2, key);
            return v1.compareToIgnoreCase(v2);
        }
    });
}

From source file:com.sldeditor.test.SLDTestRunner.java

/**
 * Writes an InputStream to a temporary file.
 *
 * @param in the in//from  w w w. j  a  v a  2s . c om
 * @return the file
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static File stream2file(InputStream in) throws IOException {
    final File tempFile = File.createTempFile(PREFIX, SUFFIX);
    tempFile.deleteOnExit();
    try (FileOutputStream out = new FileOutputStream(tempFile)) {
        IOUtils.copy(in, out);
    }

    // Update the font for the operating system
    String newFont = getFontForOS();
    if (newFont.compareToIgnoreCase(DEFAULT_FONT) != 0) {
        BufferedReader br = new BufferedReader(new FileReader(tempFile));
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line.replace(DEFAULT_FONT, newFont));
                sb.append("\n");
                line = br.readLine();
            }
            try {
                FileWriter fileWriter = new FileWriter(tempFile);
                fileWriter.write(sb.toString());
                fileWriter.flush();
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        } finally {
            br.close();
        }
    }
    return tempFile;
}

From source file:Main.java

/**
 * Compares two external TNF records/*from   w w w . ja v  a 2s. c o m*/
 *
 * @param[in] pString1 The string corresponding to the first TNF record
 * @param[in] pString2 The string corresponding to the second TNF record
 * @return true if the TNF records are equal
 */
/* package protected */static boolean compareExternalURI(String pString1, String pString2) {

    if (pString1 == null) {
        if (pString2 == null) {
            return (true);
        }
        return (false);
    }

    /* Before performing the comparison, the prefix urn:nfc:ext: is removed from the type names, if present */
    if (pString1.startsWith("urn:nfc:ext:")) {
        pString1 = pString1.substring(12);
    }
    if (pString2.startsWith("urn:nfc:ext:")) {
        pString2 = pString2.substring(12);
    }

    /* Then perform the comparison (case sensitive) */
    return (pString1.compareToIgnoreCase(pString2) == 0) ? true : false;
}

From source file:org.opendatakit.utils.WebUtils.java

/**
 * Parse a string into a boolean value. Any of:
 * <ul>//from   w  w w  .ja  va2  s.c o m
 * <li>ok</li>
 * <li>yes</li>
 * <li>true</li>
 * <li>t</li>
 * <li>y</li>
 * </ul>
 * are interpretted as boolean true.
 *
 * @param value
 * @return
 */
public static final Boolean parseBoolean(String value) {
    Boolean b = null;
    if (value != null && value.length() != 0) {
        b = Boolean.FALSE;
        if (value.compareToIgnoreCase("ok") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("yes") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("true") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("T") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("Y") == 0) {
            b = Boolean.TRUE;
        }
    }
    return b;
}

From source file:at.gv.egiz.pdfas.lib.impl.pdfbox.placeholder.SignaturePlaceholderExtractor.java

private static SignaturePlaceholderData matchPlaceholderDocument(List<SignaturePlaceholderData> placeholders,
        String placeholderId, int matchMode) throws PlaceholderExtractionException {

    if (matchMode == PLACEHOLDER_MATCH_MODE_STRICT)
        throw new PlaceholderExtractionException("error.pdf.stamp.09");

    if (placeholders.size() == 0)
        return null;

    if (matchMode == PLACEHOLDER_MATCH_MODE_SORTED) {
        // sort all placeholders by the id string if all ids are null do nothing
        SignaturePlaceholderData currentFirstSpd = null;
        for (int i = 0; i < placeholders.size(); i++) {
            SignaturePlaceholderData spd = placeholders.get(i);
            if (spd.getId() != null) {
                if (currentFirstSpd == null) {
                    currentFirstSpd = spd;
                    logger.debug("Setting new current ID: {}", currentFirstSpd.getId());
                } else {
                    String currentID = currentFirstSpd.getId();
                    String testID = spd.getId();
                    logger.debug("Testing placeholder current: {} compare to {}", currentID, testID);
                    if (testID.compareToIgnoreCase(currentID) < 0) {
                        currentFirstSpd = spd;
                        logger.debug("Setting new current ID: {}", testID);
                    }// www  .  java2  s.  c  o  m
                }
            }
        }

        for (int i = 0; i < placeholders.size(); i++) {
            SignaturePlaceholderData spd = placeholders.get(i);
            if (spd.getId() == null)
                return spd;
        }

        if (matchMode == PLACEHOLDER_MATCH_MODE_LENIENT)
            return placeholders.get(0);
    }
    return null;
}

From source file:org.opendatakit.common.utils.WebUtils.java

/**
 * Parse a string into a boolean value. Any of:
 * <ul>/*www  .j  av  a2 s  .  c o  m*/
 * <li>ok</li>
 * <li>yes</li>
 * <li>true</li>
 * <li>t</li>
 * <li>y</li>
 * </ul>
 * are interpretted as boolean true.
 *
 * @param value
 * @return
 */
public static final Boolean parseBoolean(String value) {
    Boolean b = null;
    if (value != null && value.length() != 0) {
        b = Boolean.parseBoolean(value);
        if (value.compareToIgnoreCase("ok") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("yes") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("true") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("T") == 0) {
            b = Boolean.TRUE;
        } else if (value.compareToIgnoreCase("Y") == 0) {
            b = Boolean.TRUE;
        }
    }
    return b;
}

From source file:com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.java

/**
 * Compares two strings.//w  ww.j a  v  a2 s .c o  m
 *
 * @param string1
 *            the first string.
 * @param string2
 *            the second string.
 * @param caseSensitive
 *            whether the comparison is case sensitive.
 * @return the value {@code 0} if string1 is equal to string2; a value
 *         less than {@code 0} if string1 is lexicographically less
 *         than the string2; and a value greater than {@code 0} if
 *         string1 is lexicographically greater than string2.
 */
private static int compare(String string1, String string2, boolean caseSensitive) {
    int result;
    if (caseSensitive) {
        result = string1.compareTo(string2);
    } else {
        result = string1.compareToIgnoreCase(string2);
    }

    return result;
}

From source file:org.solenopsis.checkstyle.checks.imports.ImportOrderCheck.java

/**
 * Compares two strings./*from   ww w . j a v  a 2 s  .  co  m*/
 *
 * @param string1
 *            the first string.
 * @param string2
 *            the second string.
 * @param caseSensitive
 *            whether the comparison is case sensitive.
 * @return the value {@code 0} if string1 is equal to string2; a value
 *         less than {@code 0} if string1 is lexicographically less
 *         than the string2; and a value greater than {@code 0} if
 *         string1 is lexicographically greater than string2.
 */
private static int compare(String string1, String string2, boolean caseSensitive) {
    final int result;
    if (caseSensitive) {
        result = string1.compareTo(string2);
    } else {
        result = string1.compareToIgnoreCase(string2);
    }

    return result;
}

From source file:at.gv.egovernment.moa.id.auth.parser.StartAuthentificationParameterParser.java

public static void parse(AuthenticationSession moasession, String target, String oaURL, String bkuURL,
        String templateURL, String useMandate, String ccc, String module, String action, HttpServletRequest req)
        throws WrongParametersException, MOAIDException {

    String targetFriendlyName = null;

    //       String sso = req.getParameter(PARAM_SSO);

    // escape parameter strings
    target = StringEscapeUtils.escapeHtml(target);
    //oaURL = StringEscapeUtils.escapeHtml(oaURL);
    bkuURL = StringEscapeUtils.escapeHtml(bkuURL);
    templateURL = StringEscapeUtils.escapeHtml(templateURL);
    useMandate = StringEscapeUtils.escapeHtml(useMandate);
    ccc = StringEscapeUtils.escapeHtml(ccc);
    //       sso = StringEscapeUtils.escapeHtml(sso);

    // check parameter

    //pvp2.x can use general identifier (equals oaURL in SAML1)
    //      if (!ParamValidatorUtils.isValidOA(oaURL))
    //           throw new WrongParametersException("StartAuthentication", PARAM_OA, "auth.12");

    if (!ParamValidatorUtils.isValidUseMandate(useMandate))
        throw new WrongParametersException("StartAuthentication", PARAM_USEMANDATE, "auth.12");
    if (!ParamValidatorUtils.isValidCCC(ccc))
        throw new WrongParametersException("StartAuthentication", PARAM_CCC, "auth.12");
    //       if (!ParamValidatorUtils.isValidUseMandate(sso))
    //            throw new WrongParametersException("StartAuthentication", PARAM_SSO, "auth.12");

    //check UseMandate flag
    String useMandateString = null;
    boolean useMandateBoolean = false;
    if ((useMandate != null) && (useMandate.compareTo("") != 0)) {
        useMandateString = useMandate;//w w  w.j a  v  a 2  s .c  o  m
    } else {
        useMandateString = "false";
    }

    if (useMandateString.compareToIgnoreCase("true") == 0)
        useMandateBoolean = true;
    else
        useMandateBoolean = false;

    moasession.setUseMandate(useMandateString);

    //load OnlineApplication configuration
    OAAuthParameter oaParam;
    if (moasession.getPublicOAURLPrefix() != null) {
        Logger.debug("Loading OA parameters for PublicURLPrefix: " + moasession.getPublicOAURLPrefix());
        oaParam = AuthConfigurationProvider.getInstance()
                .getOnlineApplicationParameter(moasession.getPublicOAURLPrefix());

        if (oaParam == null)
            throw new AuthenticationException("auth.00", new Object[] { moasession.getPublicOAURLPrefix() });

    } else {
        oaParam = AuthConfigurationProvider.getInstance().getOnlineApplicationParameter(oaURL);

        if (oaParam == null)
            throw new AuthenticationException("auth.00", new Object[] { oaURL });

        // get target and target friendly name from config
        String targetConfig = oaParam.getTarget();
        String targetFriendlyNameConfig = oaParam.getTargetFriendlyName();

        if (StringUtils.isEmpty(targetConfig)
                || (module.equals(SAML1Protocol.PATH) && !StringUtils.isEmpty(target))) {
            //INFO: ONLY SAML1 legacy mode
            // if SAML1 is used and target attribute is given in request
            // use requested target
            // check target parameter
            if (!ParamValidatorUtils.isValidTarget(target)) {
                Logger.error("Selected target is invalid. Using target: " + target);
                throw new WrongParametersException("StartAuthentication", PARAM_TARGET, "auth.12");
            }

        } else {
            // use target from config                
            target = targetConfig;
            targetFriendlyName = targetFriendlyNameConfig;
        }

        //         //check useSSO flag
        //         String useSSOString = null;
        //         boolean useSSOBoolean = false;
        //         if ((sso != null) && (sso.compareTo("") != 0)) {
        //            useSSOString = sso;
        //         } else {
        //            useSSOString = "false";
        //         }
        //
        //         if (useSSOString.compareToIgnoreCase("true") == 0)
        //            useSSOBoolean = true;
        //         else
        //            useSSOBoolean = false;

        //moasession.setSsoRequested(useSSOBoolean);
        moasession.setSsoRequested(true && oaParam.useSSO()); //make always SSO if OA requested it!!!!

        //Validate BKU URI
        List<String> allowedbkus = oaParam.getBKUURL();
        allowedbkus.addAll(AuthConfigurationProvider.getInstance().getDefaultBKUURLs());
        if (!ParamValidatorUtils.isValidBKUURI(bkuURL, allowedbkus))
            throw new WrongParametersException("StartAuthentication", PARAM_BKU, "auth.12");

        moasession.setBkuURL(bkuURL);

        if ((!oaParam.getBusinessService())) {
            if (isEmpty(target))
                throw new WrongParametersException("StartAuthentication", PARAM_TARGET, "auth.05");

        } else {
            if (useMandateBoolean) {
                Logger.error("Online-Mandate Mode for business application not supported.");
                throw new AuthenticationException("auth.17", null);
            }
            target = null;
            targetFriendlyName = null;
        }

        moasession.setPublicOAURLPrefix(oaParam.getPublicURLPrefix());

        moasession.setTarget(target);
        moasession.setBusinessService(oaParam.getBusinessService());
        //moasession.setStorkService(oaParam.getStorkService());
        Logger.debug(
                "Business: " + moasession.getBusinessService() + " stork: " + moasession.getStorkService());
        moasession.setTargetFriendlyName(targetFriendlyName);
        moasession.setDomainIdentifier(oaParam.getIdentityLinkDomainIdentifier());
    }

    //check OnlineApplicationURL
    if (isEmpty(oaURL))
        throw new WrongParametersException("StartAuthentication", PARAM_OA, "auth.05");
    moasession.setOAURLRequested(oaURL);

    //check AuthURL
    String authURL = req.getScheme() + "://" + req.getServerName();
    if ((req.getScheme().equalsIgnoreCase("https") && req.getServerPort() != 443)
            || (req.getScheme().equalsIgnoreCase("http") && req.getServerPort() != 80)) {
        authURL = authURL.concat(":" + req.getServerPort());
    }
    authURL = authURL.concat(req.getContextPath() + "/");

    if (!authURL.startsWith("https:"))
        throw new AuthenticationException("auth.07", new Object[] { authURL + "*" });

    //set Auth URL from configuration
    moasession.setAuthURL(AuthConfigurationProvider.getInstance().getPublicURLPrefix() + "/");

    //check and set SourceID
    if (oaParam.getSAML1Parameter() != null) {
        String sourceID = oaParam.getSAML1Parameter().getSourceID();
        if (MiscUtil.isNotEmpty(sourceID))
            moasession.setSourceID(sourceID);
    }

    if (MiscUtil.isEmpty(templateURL)) {

        List<TemplateType> templateURLList = oaParam.getTemplateURL();
        List<String> defaulTemplateURLList = AuthConfigurationProvider.getInstance().getSLRequestTemplates();

        if (templateURLList != null && templateURLList.size() > 0
                && MiscUtil.isNotEmpty(templateURLList.get(0).getURL())) {
            templateURL = FileUtils.makeAbsoluteURL(oaParam.getTemplateURL().get(0).getURL(),
                    AuthConfigurationProvider.getInstance().getRootConfigFileDir());
            Logger.info("No SL-Template in request, load SL-Template from OA configuration (URL: " + templateURL
                    + ")");

        } else if ((defaulTemplateURLList.size() > 0) && MiscUtil.isNotEmpty(defaulTemplateURLList.get(0))) {
            templateURL = FileUtils.makeAbsoluteURL(defaulTemplateURLList.get(0),
                    AuthConfigurationProvider.getInstance().getRootConfigFileDir());
            Logger.info("No SL-Template in request, load SL-Template from general configuration (URL: "
                    + templateURL + ")");

        } else {
            Logger.error("NO SL-Tempalte found in OA config");
            throw new WrongParametersException("StartAuthentication", PARAM_TEMPLATE, "auth.12");

        }

    }

    if (!ParamValidatorUtils.isValidTemplate(req, templateURL, oaParam.getTemplateURL()))
        throw new WrongParametersException("StartAuthentication", PARAM_TEMPLATE, "auth.12");
    moasession.setTemplateURL(templateURL);

    moasession.setCcc(ccc);

}

From source file:com.stratio.explorer.notebook.Note.java

public static Note importFromFile(Note n, String filename, String path) throws IOException {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();/*from  ww w.  j a  v  a  2s .  c  o m*/
    Gson gson = gsonBuilder.create();
    File file = new File(path);
    logger.info("Load note {} from {}", filename, file.getAbsolutePath());

    if (!file.isFile()) {
        logger.info("##### Note-> !file found");
        return null;
    }

    String[] filenameWithExtension = filename.split("\\.");
    for (String aFilenameWithExtension : filenameWithExtension) {
        logger.info("##### Note-> " + aFilenameWithExtension);
    }
    String ext = filenameWithExtension[filenameWithExtension.length - 1];
    FileInputStream ins = new FileInputStream(file);
    String fileString = IOUtils.toString(ins, ConfVars.EXPLORER_ENCODING.getStringValue());
    if (ext.compareToIgnoreCase("json") == 0) {
        Note note = gson.fromJson(fileString, Note.class);
        n.addParagraphs(note.getParagraphs());
        n.setName(note.getName() + " - copy");
        for (Paragraph p : n.paragraphs) {
            if (p.getStatus() == Job.Status.PENDING || p.getStatus() == Job.Status.REFRESH_RESULT
                    || p.getStatus() == Job.Status.RUNNING) {
                p.setStatus(Job.Status.ABORT);
            }
        }
    } else {
        String[] lines = fileString.split("\\r?\\n");
        for (String line : lines) {
            Paragraph p = n.addParagraph();
            p.setText(line);
        }
    }

    return n;
}