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.feedhenry.sync.model.ShoppingItem.java

private int compareStrings(String first, String second) {
    if (first == null) {
        if (second == null) {
            return 0;
        } else {//from w  ww.  j av  a2s  . c om
            return -1;
        }
    } else {
        return first.compareTo(second);
    }
}

From source file:ca.uqac.info.buffertannen.message.BitSequence.java

/**
 * Constructs a bit sequence from a string. All characters
 * other than 0 or 1 are silently ignored.
 * @param s The input string/*from   w w  w .  j  a v a 2 s.  co  m*/
 */
public BitSequence(String s) {
    this();
    for (int i = 0; i < s.length(); i++) {
        String c = s.substring(i, i + 1);
        if (c.compareTo("0") == 0) {
            this.add(false);
        } else if (c.compareTo("1") == 0) {
            this.add(true);
        }
    }
}

From source file:com.redhat.rhn.domain.kickstart.KickstartCommand.java

/**
 *
 * @param kc KickstartCommand to compare
 * @return how does it stack up!//from   w  ww.ja v  a  2s . co  m
 */
public int compareTo(Object kc) {
    if (kc == this) {
        return 0;
    }
    KickstartCommand k = (KickstartCommand) kc;
    int order = getCommandName().getOrder().compareTo(k.getCommandName().getOrder());

    if (order == 0) {
        String ourArgs = StringUtils.defaultString(getArguments(), "");
        String theirArgs = StringUtils.defaultString(k.getArguments(), "");
        order = ourArgs.compareTo(theirArgs);
    }

    return order;
}

From source file:net.sf.dynamicreports.report.builder.chart.SeriesOrderByNamesComparator.java

@Override
public int compare(String o1, String o2) {
    String row1;/*from ww  w.  j a v a 2s.c o  m*/
    String row2;
    if (StringUtils.countMatches(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY) == 1
            && StringUtils.countMatches(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY) == 1) {
        String group1 = StringUtils.substringBefore(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        String group2 = StringUtils.substringBefore(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        int compare = group1.compareTo(group2);
        if (compare != 0) {
            return compare;
        }
        row1 = StringUtils.substringAfter(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        row2 = StringUtils.substringAfter(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
    } else {
        row1 = o1;
        row2 = o2;
    }
    int index1 = seriesNames.indexOf(row1);
    int index2 = seriesNames.indexOf(row2);
    if (index1 < 0 && index2 < 0) {
        return row1.compareTo(row2);
    }
    if (index1 == index2) {
        return 0;
    }
    if (index1 < 0) {
        return index1 * -1;
    }
    if (index2 < 0) {
        return index2;
    }
    return index1 - index2;
}

From source file:com.sqewd.open.dal.core.persistence.query.ConditionMatcher.java

/**
 * Match the filter value with the Entity attribute of the specified entity
 * record.//from  w  ww.jav a2s.c  om
 * 
 * @param entity
 *            - Entity record to check.
 * @param column
 *            - Attribute Column name
 * @param operator
 *            - Condition Operator
 * @param value
 *            - Value to match.
 * @return
 * @throws Exception
 */
public boolean match(final AbstractEntity entity, final String column, final EnumOperator operator,
        final Object value) throws Exception {
    if (column.indexOf('.') < 0) {
        StructAttributeReflect attr = ReflectionUtils.get().getAttribute(entity.getClass(), column);
        Object src = PropertyUtils.getProperty(entity, attr.Field.getName());
        if (src != null)
            return ConditionMatchHelper.compare(src, value, operator, attr.Field.getType());
    } else {
        String[] vars = column.split("\\.");
        Object src = null;
        Class<?> type = null;
        StringBuffer coffset = new StringBuffer();
        StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(entity.getClass());
        for (String var : vars) {
            if (src != null) {
                coffset.append('.');
            }
            coffset.append(var);
            if (var.compareTo(enref.Entity) == 0) {
                coffset.append(".");
                continue;
            }
            if (src == null) {
                StructAttributeReflect attr = ReflectionUtils.get().getAttribute(entity.getClass(), var);
                src = PropertyUtils.getProperty(entity, attr.Field.getName());
                type = attr.Field.getType();
            } else {
                StructAttributeReflect attr = ReflectionUtils.get().getAttribute(src.getClass(), var);
                src = PropertyUtils.getProperty(src, attr.Field.getName());
                type = attr.Field.getType();
            }
            if (src.getClass().isArray()) {
                if (isArrayEntityType(src)) {
                    String cpart = column.replaceFirst("^" + coffset.toString() + ".", "");
                    return matchArray(src, cpart, operator, value);
                }
            } else if (src instanceof Iterable) {
                if (isListEntityType(src)) {
                    String cpart = column.replaceFirst("^" + coffset.toString() + ".", "");
                    return matchList(src, cpart, operator, value);
                }
            }
        }
        if (src != null)
            return ConditionMatchHelper.compare(src, value, operator, type);
    }
    return false;
}

From source file:org.hawkular.apm.api.model.config.instrumentation.jvm.JVM.java

/**
 * This method determines if the rule is valid for the
 * supplied version. If the supplied version is null, then
 * it is assumed to represent 'latest version' and therefore
 * any rule with a 'toVersion' set will not be valid.
 *
 * @param version The version/* ww  w  . j av  a  2s  .c  o m*/
 * @return Whether the rule is valid for the supplied version
 */
public boolean isVersionValid(String version) {
    if (fromVersion != null && version != null) {
        if (version.compareTo(fromVersion) < 0) {
            return false;
        }
    }
    if (toVersion != null) {
        if (version == null || version.compareTo(toVersion) >= 0) {
            return false;
        }
    }
    return true;
}

From source file:fr.sanofi.fcl4transmart.model.classes.dataType.ClinicalData.java

public void setSubFolder(String name) throws IOException {
    File folder = null;/*from w  w w  . j av a  2 s . c om*/
    if (name.compareTo("") == 0) {
        folder = rootPath;
    } else {
        for (File f : this.subFolders) {
            if (f.getName().compareTo(name) == 0) {
                folder = f;
            }
        }
        if (folder == null) {
            folder = new File(this.rootPath + File.separator + name);
            FileUtils.forceMkdir(folder);
            this.subFolders.add(folder);
        }
    }
    this.setFiles(folder);
}

From source file:org.openmrs.module.pmtct.web.view.chart.InfantPCRPieChartView.java

/**
 * @see org.openmrs.module.pmtct.web.view.chart.AbstractChartView#createChart(java.util.Map,
 *      javax.servlet.http.HttpServletRequest)
 *//*from w ww .  ja v a  2s  . co  m*/
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    UserContext userContext = Context.getUserContext();
    ApplicationContext appContext = ContextProvider.getApplicationContext();
    PMTCTModuleTag tag = new PMTCTModuleTag();

    List<Object> res = new ArrayList<Object>();

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    String title = "", descriptionTitle = "", dateInterval = "";
    Concept concept = null;
    SimpleDateFormat df = Context.getDateFormat();

    //            Date myDate1 = new Date("1/1/" + ((new Date()).getYear() + 1900));
    //            String startDate1 = df.format(myDate1);

    Date today = new Date();
    Date oneYearFromNow = new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS);

    String endDate1 = df.format(today);
    String startDate1 = df.format(oneYearFromNow);

    dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - "
            + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")";

    try {

        PmtctService pmtct;
        pmtct = Context.getService(PmtctService.class);
        try {
            res = pmtct.getGeneralStatForInfantTests_Charting_PCR(startDate1, endDate1);
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

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

        List<Integer> pcr_hivTestResultValues = new ArrayList<Integer>();

        Collection<ConceptAnswer> answers = Context.getConceptService()
                .getConcept(PMTCTConstants.RESULT_OF_HIV_TEST).getAnswers();
        for (ConceptAnswer str : answers) {
            hivTestResultOptions.add(str.getAnswerConcept().getName().getName());

            pcr_hivTestResultValues.add(0);
        }
        hivTestResultOptions.add("Others");
        pcr_hivTestResultValues.add(0);

        for (Object ob : res) {
            int val = 0;
            String temp = "", pcr_hivTestResult = "";

            temp = "" + ((Object[]) ob)[2];
            val = (temp.compareTo("") == 0) ? 0 : Integer.parseInt(temp);
            if (val > 0)
                pcr_hivTestResult = tag.getConceptNameById(temp);

            int i = 0;
            boolean pcr_found = false;
            for (String s : hivTestResultOptions) {
                if ((s.compareToIgnoreCase(pcr_hivTestResult)) == 0) {
                    pcr_hivTestResultValues.set(i, pcr_hivTestResultValues.get(i) + 1);
                    pcr_found = true;
                }
                i++;
            }

            if (!pcr_found) {
                pcr_hivTestResultValues.set(pcr_hivTestResultValues.size() - 1,
                        pcr_hivTestResultValues.get(pcr_hivTestResultValues.size() - 1) + 1);
            }
        }

        int i = 0;
        for (String s : hivTestResultOptions) {
            if (pcr_hivTestResultValues.get(i) > 0) {
                Float percentage = new Float(100 * pcr_hivTestResultValues.get(i) / res.size());
                pieDataset.setValue(s + " (" + pcr_hivTestResultValues.get(i) + " , " + percentage + "%)",
                        percentage);
            }
            i++;
        }

        title = appContext.getMessage("pmtct.menu.infantTest", null, userContext.getLocale());
        concept = null;
        descriptionTitle = Context.getEncounterService()
                .getEncounterType(PMTCTConfigurationUtils.getPCRTestEncounterTypeId()).getName();
        descriptionTitle += dateInterval;
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    JFreeChart chart = ChartFactory.createPieChart(title + " : "
            + ((null != concept) ? concept.getPreferredName(userContext.getLocale()) : descriptionTitle),
            pieDataset, true, true, false);

    return chart;
}

From source file:fitnesse.wiki.WikiPagePath.java

@Override
public int compareTo(Object o) {
    if (o instanceof WikiPagePath) {
        WikiPagePath p = (WikiPagePath) o;
        String compressedName = StringUtils.join(names, "");
        String compressedArgumentName = StringUtils.join(p.names, "");
        return compressedName.compareTo(compressedArgumentName);
    }//from  ww  w . j av  a 2  s . co m
    return 1; // we are greater because we are the right type.
}

From source file:com.echosource.ada.rules.xml.RuleNode.java

/**
 * Compare to.//from   w  ww . ja v  a  2  s.  c om
 * 
 * @param o
 *          the o
 * 
 * @return the int
 * 
 * @see java.lang.Comparable#compareTo(java.lang.Object)
 */
public int compareTo(String o) {
    return o.compareTo(name);
}