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.sfs.whichdoctor.formatter.RotationFormatter.java

public static Collection<Object> getCollection(final RotationBean rotation, final String section) {

    Collection<Object> collection = new ArrayList<Object>();

    if (section != null) {
        if (section.compareTo("Accreditations") == 0) {
            if (rotation.getAccreditation() != null) {
                for (AccreditationBean accreditation : rotation.getAccreditation()) {
                    collection.add(accreditation);
                }/*w  ww  .  ja  va 2s.c  o  m*/
            }
        }
        if (section.compareTo("Reports") == 0) {
            if (rotation.getReports() != null) {
                for (ReportBean report : rotation.getReports()) {
                    collection.add(report);
                }
            }
        }
        if (section.compareTo("Memos") == 0) {
            if (rotation.getMemo() != null) {
                for (MemoBean memo : rotation.getMemo()) {
                    collection.add(memo);
                }
            }
        }
    }
    return collection;
}

From source file:model.SongMeaningsScraper.java

public static String getLyrics(String artist, String title) throws Exception {
    // Check if user has a correction saved
    String artistMatch = DataManager.getArtistCorrections().get(artist);

    // If no correction saved, we must try and find the artist on site
    if (artistMatch == null)
        artistMatch = validateArtist(artist);

    // If finding artist didn't get an exact match, we must prompt user later
    if (artistMatch.compareTo("") == 0) {
        Logger.LogToStatusBar("No artist match, we'll have to prompt later...");
        return "";
    }/*from   w  w  w  . j a v  a2 s.  co  m*/

    HashMap<String, String> songList = DataManager.getSongMap().get(artistMatch);
    // If we don't have songs for this artist, get them
    if (songList == null) {
        Logger.LogToStatusBar("No track present, have to parse them...");
        if (SMDataParser.parseSongsPage(artistMatch, DataManager.getArtistMap().get(artistMatch)) == 0) {
            return "";
        }
    }

    songList = DataManager.getSongMap().get(artistMatch);

    if (songList == null) {
        Logger.LogToStatusBar("Artist has no tracks to get lyrics from, returning");
        return "";
    }

    Logger.LogToStatusBar("Tracks for artist " + artistMatch + " are present, trying to find the right one");
    //System.out.println(songList);
    Logger.LogToStatusBar("Checking that artist has song " + title);
    String songTitle = validateSong(artistMatch, title);

    // Try removing the parentheses
    if (songTitle.compareTo("") == 0) {
        Pattern p = Pattern.compile(" \\(.*\\)");
        Matcher m = p.matcher(title);
        if (m.find()) {
            Logger.LogToStatusBar("Song title has brackets, we'll try searching without them.");
            title = title.replaceAll(" \\(.*\\)", "");
            songTitle = validateSong(artistMatch, title);
        }
    }

    // If finding song didn't get an exact match, we must prompt user later
    if (songTitle.compareTo("") == 0) {
        Logger.LogToStatusBar("No song match, we'll have to prompt later...");
        return "";
    }

    Logger.LogToStatusBar("The closest match we found for " + title + " was " + songTitle);
    String songURL = songList.get(songTitle);
    songURL = "http://songmeanings.net" + songURL;
    Logger.LogToStatusBar(songURL);

    String lyrics = scrapeLyricsPage(songURL);
    //System.out.println(lyrics);
    return lyrics;
}

From source file:fr.inria.oak.paxquery.xparser.client.XClient.java

private static String pactJSONtoDOT(String pact_json) {

    int colorIndex = 0;
    String[] color = new String[] { "#ffcfbf", "#99ff99", "#ff99cc" };
    String[] fillColor = new String[] { "#ff9999", "#cfffbf", "#ffbfef" };

    StringBuilder output = new StringBuilder();
    String newline = System.getProperty("line.separator");
    try {/* w  ww .  jav a 2 s.c  om*/
        output.append("digraph PACT {");
        output.append(newline);
        //output.append("size =\"4,4\"");
        //output.append(newline);

        JSONParser parser = new JSONParser();
        JSONObject mainobject = (JSONObject) parser.parse(pact_json);
        JSONArray array = (JSONArray) mainobject.get("nodes");
        for (Object object : array) {
            JSONObject jsonobject = (JSONObject) object;
            // print node
            Number id = (Number) jsonobject.get("id");
            String pact = (String) jsonobject.get("pact");
            String contents = (String) jsonobject.get("contents");
            output.append("N" + id + " [label=\"");
            output.append(pact);
            if (pact.compareTo("Data Source") == 0) {
                output.append("\" color=\"" + color[colorIndex] + "\" style=\"filled\" fillcolor=\""
                        + fillColor[colorIndex] + "\" shape=box];");
                colorIndex = (colorIndex + 1) % color.length;
            } else if (pact.compareTo("Data Sink") == 0)
                output.append("\" shape=box];");
            else
                output.append(" (" + contents + ")\" shape=box];");
            output.append(newline);
            // print edges
            JSONArray preds_array = (JSONArray) jsonobject.get("predecessors");
            if (preds_array != null) {
                for (Object preds_object : preds_array) {
                    Number pred_id = (Number) ((JSONObject) preds_object).get("id");
                    output.append("N" + id + " -> N" + pred_id + " [dir=back];");
                    output.append(newline);
                }
            }
        }
        output.append("}");

    } catch (ParseException je) {
        return "";
    }

    return output.toString();
}

From source file:gr.scify.newsum.Utils.java

/**
 * /* w  w  w  . ja  v  a 2 s .com*/
 * @param lhs First Calendar date
 * @param rhs Second Calendar date
 * @return The difference in days between two Calendar dates
 */
@SuppressLint("SimpleDateFormat")
public static int getDiffInDays(Calendar lhs, Calendar rhs) {
    // Compare using formatted date
    SimpleDateFormat df = new SimpleDateFormat();
    df.applyPattern("yyyy-MM-dd");
    String sLhs = df.format(lhs.getTime());

    String sRhs = df.format(rhs.getTime());
    // debug line //
    // System.out.println(sLhs + " : " + sRhs + " := " + sLhs.compareTo(sRhs));
    // debug line //
    return sLhs.compareTo(sRhs);
}

From source file:com.highcharts.export.controller.ExportController.java

private static String sanitize(String parameter) {
    if (parameter == null || parameter.trim().isEmpty() || parameter.compareToIgnoreCase("undefined") == 0
            || parameter.compareTo("null") == 0 || parameter.compareTo("{}") == 0) {
        return null;
    }/* w ww.j  a va2 s.  c o m*/
    return parameter.trim();
}

From source file:gdt.data.grain.Support.java

private static boolean itemExists(String name, Vector<String> vec) {
    if (name == null)
        return false;
    if (vec == null)
        return false;
    int cnt = vec.size();
    for (int i = 0; i < cnt; i++) {
        if (name.compareTo((String) vec.get(i)) == 0)
            return true;
    }/*from  w w w . j  av a 2 s. c  om*/
    return false;
}

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

/**
 * Gets the field./*from  w w w  .j  a v a 2 s  . com*/
 *
 * @param receipt the receipt
 * @param object the object
 * @param section the section
 * @param field the field
 * @param format the format
 * @return the field
 */
public static String getField(final ReceiptBean receipt, final Object object, final String section,
        final String field, final String format) {

    String value = "";

    if (section == null) {
        return value;
    }
    if (field == null) {
        return value;
    }
    if (field.compareTo("GUID") == 0) {
        value = String.valueOf(receipt.getGUID());
    }
    if (field.compareTo("Prefix") == 0) {
        value = String.valueOf(receipt.getAbbreviation());
    }
    if (field.compareTo("Receipt Number") == 0) {
        value = String.valueOf(receipt.getNumber());
    }
    if (field.compareTo("Type") == 0) {
        value = receipt.getTypeName();
    }
    if (field.compareTo("Description") == 0) {
        value = receipt.getDescription();
    }
    if (field.compareTo("Batch Number") == 0) {
        value = receipt.getProcessAbbreviation() + ":" + receipt.getBatchReference();
    }
    if (field.compareTo("Bank") == 0) {
        value = receipt.getBank();
    }
    if (field.compareTo("Branch") == 0) {
        value = receipt.getBranch();
    }
    if (field.compareTo("MIN") == 0) {
        if (receipt.getPerson() != null) {
            value = String.valueOf(receipt.getPerson().getPersonIdentifier());
        }
    }

    if (field.compareTo("Person Issued To") == 0) {
        if (receipt.getPerson() != null) {
            PersonBean person = receipt.getPerson();
            value = OutputFormatter.toCasualName(person);
        }
    }

    if (field.compareTo("Organisation Issued To") == 0) {
        if (receipt.getOrganisation() != null) {
            OrganisationBean organisation = receipt.getOrganisation();
            value = organisation.getName();
        }
    }

    if (field.compareTo("Issued Date") == 0) {
        if (receipt.getIssued() != null) {
            value = Formatter.conventionalDate(receipt.getIssued());
        }
    }
    if (field.compareTo("Cancelled") == 0) {
        value = Formatter.convertBoolean(receipt.getCancelled());
    }
    if (section.compareTo("Payments") == 0) {
        PaymentBean payment = (PaymentBean) object;

        if (payment.getDebit() != null) {
            if (field.compareTo("Debit Prefix") == 0) {
                value = payment.getDebit().getAbbreviation();
            }
            if (field.compareTo("Debit Number") == 0) {
                value = payment.getDebit().getNumber();
            }
            if (field.compareTo("Debit Description") == 0) {
                value = payment.getDebit().getDescription();
            }
            if (field.compareTo("Debit Issued") == 0) {
                value = Formatter.conventionalDate(payment.getDebit().getIssued());
            }
            if (field.compareTo("Debit Value") == 0) {
                value = Formatter.toCurrency(payment.getDebit().getValue(), "$");
                if (format.compareTo("html") == 0) {
                    value = "<div style=\"text-align: right\">" + value + "</div>";
                }
            }
            if (field.compareTo("Debit GST Value") == 0) {
                value = Formatter.toCurrency(payment.getDebit().getGSTValue(), "$");
                if (format.compareTo("html") == 0) {
                    value = "<div style=\"text-align: right\">" + value + "</div>";
                }
            }
            if (field.compareTo("Debit Total Value") == 0) {
                value = Formatter.toCurrency(payment.getDebit().getTotalValue(), "$");
                if (format.compareTo("html") == 0) {
                    value = "<div style=\"text-align: right\">" + value + "</div>";
                }
            }
            if (field.compareTo("Debit GST Rate") == 0) {
                value = Formatter.toPercentage(payment.getDebit().getGSTRate(), "%");
            }
            if (field.compareTo("Debit Cancelled") == 0) {
                value = Formatter.convertBoolean(payment.getDebit().getCancelled());
            }
        }

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

        if (field.compareTo("Negative Payment") == 0) {
            value = Formatter.convertBoolean(payment.getNegativePayment());
        }
    }

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

From source file:de.fraunhofer.iosb.ivct.IVCTcommander.java

private static ConfigParameters parseConfig(Document dom) {
    ConfigParameters configParameters = new ConfigParameters();

    Element elem = dom.getDocumentElement();
    for (Node child = elem.getFirstChild(); child != null; child = child.getNextSibling()) {
        String s = child.getNodeName();
        if (s.compareTo("pathNames") == 0) {
            for (Node child0 = child.getFirstChild(); child0 != null; child0 = child0.getNextSibling()) {
                if (child0.getNodeName().compareTo("sutDir") == 0) {
                    if (child0.getNodeType() == Node.ELEMENT_NODE) {
                        configParameters.pathSutDir = child0.getFirstChild().getNodeValue();
                    }/*from  w  w w  .j a  va2s.c  om*/
                }
                if (child0.getNodeName().compareTo("testSuites") == 0) {
                    if (child0.getNodeType() == Node.ELEMENT_NODE) {
                        configParameters.pathTestsuite = child0.getFirstChild().getNodeValue();
                    }
                }
            }
        }
    }

    return configParameters;
}

From source file:net.sourceforge.doddle_owl.data.JpnWordNetDic.java

public static String getConceptData(String id) {
    long low = 0;
    long conceptIndexFileSize = getConceptIndexFileSize();
    long high = conceptIndexFileSize;
    while (low <= high) {
        long mid = (low + high) / 2;
        if (conceptIndexFileSize - 1 < mid) {
            return null;
        } // <= ---> <
        long conceptDataFP = getConceptDataFp(mid * 10);
        if (conceptDataFP == -1) {
            return null;
        }//ww  w .j  av  a  2 s.c  o m
        // System.out.println("mid: " + mid);
        String conceptData = getConceptData(conceptDataFP);
        if (conceptData == null) {
            return null;
        }
        String[] lines = conceptData.split("\t");
        String searchedID = lines[0];
        // System.out.println(searchedID.compareTo(id));
        if (searchedID.compareTo(id) == 0) {
            // System.out.println(conceptData);
            return conceptData;
        } else if (0 < searchedID.compareTo(id)) {
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    return null;
}

From source file:net.sourceforge.doddle_owl.data.JpnWordNetDic.java

public static String getTreeData(String id) {
    long low = 0;
    long treeIndexFileSize = getTreeIndexFileSize();
    long high = treeIndexFileSize;
    while (low <= high) {
        long mid = (low + high) / 2;
        // System.out.println("mid: " + mid);
        if (treeIndexFileSize - 1 <= mid) {
            return null;
        }//from   www.  j a  v a  2s.  c  om
        long treeDataFP = getTreeDataFp(mid * 10);
        if (treeDataFP == -1) {
            return null;
        }
        String treeData = getTreeData(treeDataFP);
        if (treeData == null) {
            return null;
        }
        String[] lines = treeData.split("\t");
        String searchedID = lines[0];
        // System.out.println(searchedID.compareTo(id));
        if (searchedID.compareTo(id) == 0) {
            // System.out.println(conceptData);
            return treeData;
        } else if (0 < searchedID.compareTo(id)) {
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    return null;
}