Example usage for java.lang String compareTo

List of usage examples for java.lang String compareTo

Introduction

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

Prototype

public int compareTo(String anotherString) 

Source Link

Document

Compares two strings lexicographically.

Usage

From source file:com.webpagebytes.cms.controllers.LanguagesController.java

public void getSupportedLanguages(HttpServletRequest request, HttpServletResponse response, String requestUri)
        throws WPBException {
    WPBProject project = getProject();//  ww w .ja  va2 s.  c o  m
    Set<String> projectLanguages = project.getSupportedLanguagesSet();
    Set<String> supportedlanguages = new HashSet<String>();
    for (String language : projectLanguages) {
        if (allLocales.containsKey(language)) {
            supportedlanguages.add(language);
        }
    }

    JSONArray result = new JSONArray();
    try {
        for (String str : sortedLanguages) {
            if (supportedlanguages.contains(str)) {
                JSONObject item = new JSONObject();
                item.put("lcid", str);
                item.put("name", allLocales.get(str).getDisplayName());
                if (str.compareTo(project.getDefaultLanguage()) == 0) {
                    item.put("default", "true");
                } else {
                    item.put("default", "false");
                }
                result.put(item);
            }
        }

        org.json.JSONObject returnJson = new org.json.JSONObject();
        returnJson.put(DATA, result);
        httpServletToolbox.writeBodyResponseAsJson(response, returnJson, null);
    } catch (Exception e) {
        Map<String, String> errors = new HashMap<String, String>();
        errors.put("WBErrors.WB_CANT_GET_RECORDS", WPBErrors.WB_CANT_GET_RECORDS);
        httpServletToolbox.writeBodyResponseAsJson(response, jsonObjectConverter.JSONObjectFromMap(null),
                errors);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.web1t.util.Web1TConverter.java

public void createIndex() throws IOException {

    closeWriters(ngramWriters.values());

    Comparator<String> comparator = new Comparator<String>() {
        @Override// w  w w.  ja v a 2s  . com
        public int compare(String r1, String r2) {
            return r1.compareTo(r2);
        }
    };

    // read the file with the counts per file and create the final
    // aggregated counts
    for (int level = minNgramLength; level <= maxNgramLength; level++) {
        Integer nextFreeFileNumber = processInputFileForLevel(level, comparator);

        processCreatedMiscFileAgain(level, comparator, nextFreeFileNumber);
    }

    if (writeIndexes) {
        JWeb1TIndexer indexer = new JWeb1TIndexer(outputPath, maxNgramLength);
        indexer.create();
    }
}

From source file:de.tudarmstadt.ukp.csniper.webapp.statistics.page.export.ExportCsvTask.java

@Override
protected void run() {
    CSVWriter writer = null;/*from   w w w  .j  a va 2 s  .  com*/

    contextProvider.setOutputPos(exportModel.includePos);

    outputFile = null;
    try {
        outputFile = File.createTempFile("date", ".csv");

        writer = new CSVWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));

        List<AdditionalColumn> ac = exportModel.additionalColumns;
        String[] row = new String[COLUMN_COUNT + ac.size()];

        List<AggregatedEvaluationResult> results = repository.listAggregatedResults(formModel.getCollections(),
                formModel.getTypes(), formModel.getUsers(), formModel.getUserThreshold(),
                formModel.getConfidenceThreshold());

        Collections.sort(results, new Comparator<AggregatedEvaluationResult>() {
            @Override
            public int compare(AggregatedEvaluationResult aO1, AggregatedEvaluationResult aO2) {
                String id1 = aO1.getItem().getCollectionId() + "|" + aO1.getItem().getDocumentId();
                String id2 = aO2.getItem().getCollectionId() + "|" + aO2.getItem().getDocumentId();
                return id1.compareTo(id2);
            }
        });

        // Write header row
        row[0] = "User";
        row[1] = "Collection";
        row[2] = "Document";
        row[3] = "Begin";
        row[4] = "End";
        row[5] = "Left";
        row[6] = "Unit";
        row[7] = "Right";
        row[8] = "Type";
        row[9] = "Class";
        row[10] = "Confidence";
        row[11] = "Correct";
        row[12] = "Wrong";
        for (int i = 0; i < ac.size(); i++) {
            row[COLUMN_COUNT + i] = ac.get(i).getName();
        }
        writer.writeNext(row);

        // Write rest
        setTotal(results.size());
        for (AggregatedEvaluationResult aer : results) {
            ResultFilter classification = aer.getClassification();
            if (formModel.getFilters().contains(classification)) {
                ItemContext context = contextProvider.getContext(aer.getItem(), exportModel.contextSize,
                        exportModel.contextSize);

                // only differentiate between users if additional columns are being exported
                Set<String> users;
                if (ac.isEmpty()) {
                    users = new HashSet<String>(Arrays.asList(""));
                } else {
                    users = aer.getUsers(false);
                }

                // output the AggregatedEvaluationResult for every user (because the additional
                // columns entries might differ)
                for (String user : users) {
                    row[0] = user;
                    row[1] = aer.getItem().getCollectionId();
                    row[2] = aer.getItem().getDocumentId();
                    row[3] = Long.toString(aer.getItem().getBeginOffset());
                    row[4] = Long.toString(aer.getItem().getEndOffset());
                    row[5] = context.getLeft();
                    row[6] = context.getUnit();
                    row[7] = context.getRight();
                    row[8] = aer.getItem().getType();
                    row[9] = classification.toString();
                    row[10] = Double.toString(aer.getConfidence());
                    row[11] = Integer.toString(aer.getCorrect());
                    row[12] = Integer.toString(aer.getWrong());
                    for (int i = 0; i < ac.size(); i++) {
                        row[COLUMN_COUNT + i] = repository.getEvaluationResult(aer.getItem().getId(), user)
                                .getAdditionalColumns().get(ac.get(i));
                        if (row[COLUMN_COUNT + i] == null) {
                            row[COLUMN_COUNT + i] = "";
                        }
                    }
                    writer.writeNext(row);
                }
            }

            // Make sure we do not get to 100% before we did the classification, because
            // otherwise ProgressBar.onFinish() will trigger!!!
            increment();
            if (isCancelled()) {
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        error("Export failed: " + ExceptionUtils.getRootCauseMessage(e));
        cancel();
    } finally {
        IOUtils.closeQuietly(writer);
        if (isCancelled()) {
            clean();
        }
    }
}

From source file:ch.rgw.tools.StringTool.java

/**
 * Zwei Strings verleichen. Bercksichtigen, dass einer oder beide auch Null sein knnten.
 * /*  w  ww.java  2s  .c  om*/
 * @param a
 *            erster String
 * @param b
 *            zweiter String
 * @return -1,0 oder 1
 */
public static int compareWithNull(String a, String b) {
    if (a == null) {
        if (b == null) {
            return 0;
        } else {
            return -1;
        }
    } else if (b == null) {
        return 1;
    } else {
        return a.compareTo(b);
    }
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ??/*from  www .j  a  v a 2s . c o m*/
 * 
 * @param startTime
 * @return boolean
 */
public static boolean isInBetweenTimes(String startTime, String endTime) {
    Date nowTime = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    String time = sdf.format(nowTime);
    if (time.compareTo(startTime) >= 0 && time.compareTo(endTime) <= 0) {
        return true;
    } else {
        return false;
    }
}

From source file:com.xiaomi.linden.core.search.HotSwapLindenCoreImpl.java

public synchronized LindenCore getLindenCore(String indexName) throws IOException {
    LindenCore lindenCore = lindenCoreMap.get(indexName);
    if (lindenCore == null) {
        lindenCore = new LindenCoreImpl(lindenConfig, indexName);
        lindenCoreMap.put(indexName, lindenCore);
        LOGGER.info("Create new Linden core: " + indexName);
        // current linden core is also in lindenCoreMap
        if (lindenCoreMap.size() > MAX_NEXT_INDEX_NUM + 1) {
            List<String> keys = new ArrayList<>(lindenCoreMap.keySet());
            String oldestCoreName = null;
            for (int i = 0; i < keys.size(); ++i) {
                if (keys.get(i).startsWith(NEXT_INDEX_NAME_PREFIX)) {
                    if (oldestCoreName == null || oldestCoreName.compareTo(keys.get(i)) > 0) {
                        oldestCoreName = keys.get(i);
                    }/*from www.ja  v  a 2  s .  co m*/
                }
            }
            if (oldestCoreName == null) {
                throw new IOException("There is no next linden core in the map.");
            }
            LindenCore core = lindenCoreMap.remove(oldestCoreName);
            core.close();
            if (lindenConfig.getIndexType() != LindenConfig.IndexType.RAM) {
                String dir = FilenameUtils.concat(baseIndexDir, oldestCoreName);
                FileUtils.deleteQuietly(new File(dir));
                LOGGER.info("Abandon and delete index: " + oldestCoreName);
            }
        }
    }
    return lindenCore;
}

From source file:com.sfs.dao.GadgetDAOImpl.java

/**
 * Load a GadgetBean based on its url./*  ww  w  .  ja  v  a2s . co m*/
 *
 * @param url the url
 *
 * @return the gadget bean
 *
 * @throws SFSDaoException the SFS dao exception
 */
public final GadgetBean load(final String url) throws SFSDaoException {

    GadgetBean gadgetBean = null;

    if (url == null) {
        throw new SFSDaoException("Error: URL cannot be null");
    }
    if (url.compareTo("") == 0) {
        throw new SFSDaoException("Error: URL cannot be an empty string");
    }

    dataLogger.debug("Load gadget for: " + url);

    try {
        gadgetBean = (GadgetBean) this.getJdbcTemplateReader()
                .queryForObject(this.getSQL().getValue("gadget/load"), new Object[] { url }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadGadget(rs);
                    }
                });

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

    return gadgetBean;
}

From source file:com.sfs.dao.LdapAuthenticationDAOImpl.java

/**
 * Load the UserBean.//from w  ww.ja  va 2s.c o m
 *
 * @param userNameVal the user name
 * @param request the servlet request
 *
 * @return the user bean
 *
 * @throws SFSDaoException the SFS dao exception
 */
@SuppressWarnings("unchecked")
public final UserBean load(final String userNameVal, final HttpServletRequest request) throws SFSDaoException {
    // Loads user details into bean using a supplied username
    if (userNameVal == null) {
        throw new SFSDaoException("Username cannot be null");
    }
    if (userNameVal.compareTo("") == 0) {
        throw new SFSDaoException("Username cannot be an empty string");
    }

    UserBean user = null;

    final String base = this.searchBase;
    final String filter = StringUtils.replace(this.searchFilter, "%u", userNameVal);

    final LdapTemplate ldapTemplate = new LdapTemplate(contextSource);

    Collection<UserBean> users = ldapTemplate.search(base, filter, new ContextMapper() {
        public Object mapFromContext(final Object ctx) {
            DirContextAdapter adapter = (DirContextAdapter) ctx;
            return loadDetails(adapter);
        }
    });

    for (UserBean loadedUser : users) {
        user = loadedUser;
    }

    if (user == null) {
        throw new SFSDaoException("A user object for this username " + "was not found");
    }
    return user;
}

From source file:de.tudarmstadt.ukp.csniper.webapp.statistics.page.export.ExportHtmlTask.java

@Override
protected void run() {
    HtmlWriter writer = null;/* w w w .  jav  a 2s. c o m*/

    contextProvider.setOutputPos(exportModel.includePos);

    outputFile = null;
    try {
        outputFile = File.createTempFile("date", ".html");

        writer = new HtmlWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));

        List<AdditionalColumn> ac = exportModel.additionalColumns;
        String[] row = new String[COLUMN_COUNT];

        List<AggregatedEvaluationResult> results = repository.listAggregatedResults(formModel.getCollections(),
                formModel.getTypes(), formModel.getUsers(), formModel.getUserThreshold(),
                formModel.getConfidenceThreshold());

        Collections.sort(results, new Comparator<AggregatedEvaluationResult>() {
            @Override
            public int compare(AggregatedEvaluationResult aO1, AggregatedEvaluationResult aO2) {
                String id1 = aO1.getItem().getCollectionId() + "|" + aO1.getItem().getDocumentId();
                String id2 = aO2.getItem().getCollectionId() + "|" + aO2.getItem().getDocumentId();
                return id1.compareTo(id2);
            }
        });

        // Write rest
        setTotal(results.size());
        for (AggregatedEvaluationResult aer : results) {
            ResultFilter classification = aer.getClassification();
            if (formModel.getFilters().contains(classification)) {
                ItemContext context = contextProvider.getContext(aer.getItem(), exportModel.contextSize,
                        exportModel.contextSize);

                row[0] = aer.getItem().getCollectionId();
                row[1] = aer.getItem().getDocumentId();
                row[2] = Long.toString(aer.getItem().getBeginOffset());
                row[3] = Long.toString(aer.getItem().getEndOffset());
                row[4] = context.getLeft();
                row[5] = context.getUnit();
                row[6] = context.getRight();
                row[7] = aer.getItem().getType();
                row[8] = classification.toString();
                row[9] = Double.toString(aer.getConfidence());
                row[10] = Integer.toString(aer.getCorrect());
                row[11] = Integer.toString(aer.getWrong());
                writer.writeHtml(row, aer.getItem().getId(), ac, aer.getUsers(false));
            }

            // Make sure we do not get to 100% before we did the classification, because
            // otherwise ProgressBar.onFinish() will trigger!!!
            increment();
            if (isCancelled()) {
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        error("Export failed: " + ExceptionUtils.getRootCauseMessage(e));
        cancel();
    } finally {
        writer.close();
        if (isCancelled()) {
            clean();
        }
    }
}

From source file:de.unihannover.l3s.mws.bean.Search.java

private boolean chechAny(List<String> lista, String word) {
    boolean check = false;
    for (String s : lista) {
        if (s.compareTo(word) == 0) {
            return true;
        }/*from  ww w . j  a v  a  2 s.co m*/
    }
    return check;
}