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:gov.nih.nci.ncicb.cadsr.evs.LexEVSQueryServiceImpl.java

public static CodedNodeSet restrictToSource(CodedNodeSet cns, String source) {
    if (cns == null)
        return cns;
    if (source == null || source.compareTo("*") == 0 || source.compareTo("") == 0
            || source.compareTo("ALL") == 0)
        return cns;

    LocalNameList contextList = null;// ww  w  . ja  v a 2  s  . c om
    LocalNameList sourceLnL = null;
    NameAndValueList qualifierList = null;

    Vector<String> w2 = new Vector<String>();
    w2.add(source);
    sourceLnL = vector2LocalNameList(w2);
    LocalNameList propertyLnL = null;
    CodedNodeSet.PropertyType[] types = new CodedNodeSet.PropertyType[] {
            CodedNodeSet.PropertyType.PRESENTATION };
    try {
        cns = cns.restrictToProperties(propertyLnL, types, sourceLnL, contextList, qualifierList);
    } catch (Exception ex) {
        System.out.println("restrictToSource throws exceptions.");
        return null;
    }
    return cns;
}

From source file:com.laudandjolynn.mytv.Main.java

/**
 * ?/*from ww w.  j a  v  a  2s  .com*/
 * 
 * @param data
 */
private static void runCrawlTask(final MyTvData data, final TvService tvService) {
    CrawlEventListener listener = null;
    final String today = DateUtils.today();
    final ExecutorService executorService = Executors.newFixedThreadPool(Constant.CPU_PROCESSOR_NUM,
            new BasicThreadFactory.Builder().namingPattern("Mytv_Crawl_Program_Table_%d").build());
    if (!data.isProgramCrawlerInited()) {
        listener = new CrawlEventListenerAdapter() {
            @Override
            public void itemFound(CrawlEvent event) {
                if (event instanceof TvStationFoundEvent) {
                    final TvStation item = (TvStation) ((TvStationFoundEvent) event).getItem();
                    if (!tvService.isInMyTv(item) || CrawlAction.getIntance().isInQuerying(item, today)) {
                        return;
                    }
                    executorService.execute(new Runnable() {

                        @Override
                        public void run() {
                            CrawlAction.getIntance().queryProgramTable(item, today);
                        }
                    });
                }
            }
        };
    }

    // ???
    logger.info("It is trying to find some proxyies.");
    MyTvProxyManager.getInstance().prepareProxies(new ConfigProxy());
    logger.info("found " + MyTvProxyManager.getInstance().getProxySize() + " proxies.");

    if (!data.isStationCrawlerInited()) {
        // ?
        tvService.crawlAllTvStation(listener);

        // ??
        String[] weeks = DateUtils.getWeek(new Date(), "yyyy-MM-dd");
        List<TvStation> stationList = tvService.getDisplayedTvStation();
        for (String date : weeks) {
            if (date.compareTo(today) >= 1) {
                crawlAllProgramTable(stationList, executorService, date, tvService);
            }
        }
        executorService.shutdown();
        data.writeData(null, Constant.XML_TAG_STATION, "true");
        data.writeData(null, Constant.XML_TAG_PROGRAM, "true");
    }
}

From source file:io.fabric8.maven.core.util.VersionUtil.java

/**
 * Compares two version strings such that "1.10.1" > "1.4" etc
 *///from www. j  av  a  2s . c o  m
public static int compareVersions(String v1, String v2) {
    String[] components1 = split(v1);
    String[] components2 = split(v2);
    int diff;
    int length = Math.min(components1.length, components2.length);
    for (int i = 0; i < length; i++) {
        String s1 = components1[i];
        String s2 = components2[i];
        Integer i1 = tryParseInteger(s1);
        Integer i2 = tryParseInteger(s2);
        if (i1 != null && i2 != null) {
            diff = i1.compareTo(i2);
        } else {
            // lets assume strings instead
            diff = s1.compareTo(s2);
        }
        if (diff != 0) {
            return diff;
        }
    }
    diff = Integer.compare(components1.length, components2.length);
    if (diff == 0) {
        if (v1 == v2) {
            return 0;
        }
        /* if v1 == null then v2 can't be null here (see 'if' above).
           So for v1 == null its always smaller than v2 */;
        return v1 != null ? v1.compareTo(v2) : -1;
    }
    return diff;
}

From source file:com.sfs.whichdoctor.formatter.GroupFormatter.java

public static String getField(final GroupBean group, final Object object, final String section,
        final String field, final String format) {

    String value = "";
    if (section == null) {
        return value;
    }//from  www  .  j ava  2 s  . com
    if (field == null) {
        return value;
    }
    if (field.compareTo("GUID") == 0) {
        value = String.valueOf(group.getGUID());
    }
    if (field.compareTo("Group Name") == 0) {
        value = group.getName();
    }
    if (field.compareTo("Group Type") == 0) {
        value = group.getType();
    }
    if (section.compareTo("Items") == 0) {
        ItemBean item = (ItemBean) object;

        if (field.compareTo("Item Name") == 0) {
            value = item.getName();
        }
        if (field.compareTo("Item Title") == 0) {
            value = item.getTitle();
        }
        if (field.compareTo("Item Comment") == 0) {
            value = StringUtils.replace(item.getComment(), "\n", "<br />");
        }
        if (field.compareTo("Item Weighting") == 0) {
            value = String.valueOf(item.getWeighting());
        }
        if (field.compareTo("Item Start") == 0) {
            value = Formatter.conventionalDate(item.getStartDate());
        }
        if (field.compareTo("Item End") == 0) {
            value = Formatter.conventionalDate(item.getEndDate());
        }
    }

    if (section.compareTo("Memos") == 0) {
        MemoBean memo = (MemoBean) object;

        if (field.compareTo("Type") == 0) {
            value = memo.getType();
        }
        if (field.compareTo("Date Created") == 0) {
            value = Formatter.conventionalDate(memo.getCreatedDate());
        }
        if (field.compareTo("Date Expires") == 0) {
            value = Formatter.conventionalDate(memo.getExpires());
        }
        if (field.compareTo("Message") == 0) {
            value = memo.getMessage();
        }
    }

    if (value == null) {
        value = "";
    }
    return value;
}

From source file:com.reactive.hzdfs.dll.JarClassLoader.java

private static TreeSet<String> scanForPackages(String path) throws IOException {
    try (JarFile file = new JarFile(path)) {
        TreeSet<String> packages = new TreeSet<>(new Comparator<String>() {

            @Override// ww w . j a  v a  2 s .c  o  m
            public int compare(String o1, String o2) {
                if (o2.length() > o1.length() && o2.contains(o1))
                    return -1;
                else if (o2.length() < o1.length() && o1.contains(o2))
                    return 1;
                else
                    return o1.compareTo(o2);
            }
        });
        for (Enumeration<JarEntry> entries = file.entries(); entries.hasMoreElements();) {
            JarEntry entry = entries.nextElement();
            String name = entry.getName();

            if (name.endsWith(".class")) {
                String fqcn = ClassUtils.convertResourcePathToClassName(name);
                fqcn = StringUtils.delete(fqcn, ".class");
                packages.add(ClassUtils.getPackageName(fqcn));
            }
        }

        return packages;
    }
}

From source file:com.alibaba.cobar.manager.util.CobarStringUtil.java

/**
 * e.g. {"mysql_1","mysql_2","mysql_3","mysql_5"} will return
 * {"mysql_$1-3","mysql_5"}<br/>// ww w .  j ava 2s .co m
 * only merge last number
 */
public static List<String> mergeListedString(String[] input) {
    if (input == null || input.length < 1)
        return Collections.emptyList();
    if (input.length == 1) {
        List<String> rst = new ArrayList<String>(1);
        rst.add(input[0]);
        return rst;
    }
    List<String> list = new ArrayList<String>(input.length);
    for (String str : input)
        list.add(str);
    Collections.sort(list, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            if (StringUtils.equals(o1, o2))
                return 0;
            if (o1.length() == o2.length())
                return o1.compareTo(o2);
            return o1.length() < o2.length() ? -1 : 1;
        }
    });

    List<String> rst = new ArrayList<String>();

    String prefix = null;
    Integer from = null;
    Integer to = null;
    String last = list.get(0);
    for (int i = 1; i < list.size(); ++i) {
        String cur = list.get(i);
        if (StringUtils.equals(last, cur))
            continue;
        int commonInd = indexOfLastEqualCharacter(last, cur);

        boolean isCon = false;

        if (commonInd >= 0) {
            String suffixLast = last.substring(1 + commonInd);
            String suffixCur = cur.substring(1 + commonInd);
            try {
                int il = Integer.parseInt(suffixLast);
                int ic = Integer.parseInt(suffixCur);
                if (ic - il == 1)
                    isCon = true;
            } catch (Exception e) {
            }
        }

        if (isCon) {
            if (prefix == null)
                prefix = last.substring(0, commonInd + 1);
            if (from == null)
                from = Integer.parseInt(last.substring(commonInd + 1));
            to = Integer.parseInt(cur.substring(commonInd + 1));
        } else if (prefix != null) {
            rst.add(new StringBuilder(prefix).append('$').append(from).append('-').append(to).toString());
            prefix = null;
            from = to = null;
        } else {
            rst.add(last);
        }
        last = cur;
    }

    if (prefix != null) {
        rst.add(new StringBuilder(prefix).append('$').append(from).append('-').append(to).toString());
        prefix = null;
        from = to = null;
    } else {
        rst.add(last);
    }

    return rst;
}

From source file:com.sfs.whichdoctor.formatter.RevenueAnalysisFormatter.java

/**
 * Gets the field./*from   www . j a v a  2s.c  o m*/
 *
 * @param revenue the revenue
 * @param field the field
 * @param format the format
 * @return the field
 */
public static String getField(final RevenueBean revenue, final String field, final String format) {

    String value = "";

    if (revenue == null || field == null) {
        return value;
    }
    if (field.compareTo("Revenue Stream") == 0) {
        value = revenue.getRevenueType();
    }
    if (field.compareTo("Batch Number") == 0) {
        value = revenue.getBatchNo();
    }
    if (field.compareTo("Total Revenue Value") == 0) {
        value = Formatter.toCurrency(revenue.getNetValue(), "$");
        if (format.compareTo("html") == 0) {
            value = "<div style=\"text-align: right\">" + value + "</div>";
        }
    }

    if (field.compareTo("Total GST Value") == 0) {
        value = Formatter.toCurrency(revenue.getGSTValue(), "$");
        if (format.compareTo("html") == 0) {
            value = "<div style=\"text-align: right\">" + value + "</div>";
        }
    }

    if (field.compareTo("Total Revenue") == 0) {
        value = Formatter.toCurrency(revenue.getValue(), "$");
        if (format.compareTo("html") == 0) {
            value = "<div style=\"text-align: right\">" + value + "</div>";
        }
    }

    if (value == null) {
        value = "";
    }
    return value;
}

From source file:com.streak.logging.analysis.AnalysisUtility.java

public static List<String> fetchCloudStorageUris(String bucketName, String startKey, String endKey,
        HttpRequestFactory requestFactory) throws IOException {
    List<String> result = new ArrayList<String>();

    String bucketUri = "http://commondatastorage.googleapis.com/" + bucketName;
    HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(bucketUri + "?marker=" + startKey));
    HttpResponse response = request.execute();

    try {/*from  ww w . j  av a 2  s  .c  o m*/
        Document responseDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(response.getContent());
        XPath xPath = XPathFactory.newInstance().newXPath();
        NodeList nodes = (NodeList) xPath.evaluate("//Contents/Key/text()", responseDoc,
                XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            String key = nodes.item(i).getNodeValue();
            if (key.compareTo(endKey) >= 0) {
                break;
            }
            if (key.endsWith(".schema.json")) {
                continue;
            }
            result.add("gs://" + bucketName + "/" + key);
        }
    } catch (SAXException e) {
        throw new IOException("Error parsing cloud storage response", e);
    } catch (ParserConfigurationException e) {
        throw new IOException("Error configuring cloud storage parser", e);
    } catch (XPathExpressionException e) {
        throw new IOException("Error finding keys", e);
    }

    return result;
}

From source file:at.gv.egovernment.moa.id.util.legacy.LegacyHelper.java

public static boolean isUseMandateRequested(HttpServletRequest req) throws WrongParametersException {

    String useMandate = req.getParameter(PARAM_USEMANDATE);
    useMandate = StringEscapeUtils.escapeHtml(useMandate);
    if (!ParamValidatorUtils.isValidUseMandate(useMandate))
        throw new WrongParametersException("StartAuthentication", PARAM_USEMANDATE, "auth.12");

    //check UseMandate flag
    String useMandateString = null;
    if ((useMandate != null) && (useMandate.compareTo("") != 0)) {
        useMandateString = useMandate;//ww w. j  ava 2 s. com
    } else {
        useMandateString = "false";
    }

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

From source file:DOMTreeFull.java

/** Returns a sorted list of attributes. */
static protected Attr[] sortAttributes(NamedNodeMap attrs) {

    int len = (attrs != null) ? attrs.getLength() : 0;
    Attr array[] = new Attr[len];
    for (int i = 0; i < len; i++) {
        array[i] = (Attr) attrs.item(i);
    }/*from www. j a  v a 2s.c  o m*/
    for (int i = 0; i < len - 1; i++) {
        String name = array[i].getNodeName();
        int index = i;
        for (int j = i + 1; j < len; j++) {
            String curName = array[j].getNodeName();
            if (curName.compareTo(name) < 0) {
                name = curName;
                index = j;
            }
        }
        if (index != i) {
            Attr temp = array[i];
            array[i] = array[index];
            array[index] = temp;
        }
    }

    return array;

}