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:at.tuwien.minimee.util.TopParser.java

private void parseLine(String line) {

    StringTokenizer tokenizer = new StringTokenizer(line, " :");

    if (!tokenizer.hasMoreTokens()) {
        return;// w w  w.ja v  a 2s  .  c o m
    }

    String start = tokenizer.nextToken();

    if (start.compareTo("top") == 0) {

        if (currentExecutionFootprint != null) {
            cleanUp(currentExecutionFootprint);
            list.add(currentExecutionFootprint);
        }
        currentExecutionFootprint = new ExecutionFootprint();

        parseTopLine(tokenizer);

    } else if (start.compareTo("Tasks") == 0) {

        parseTasksLine(tokenizer);
    } else if (start.compareTo("Cpu(s)") == 0) {

        parseCpusLine(line);
    } else if (start.compareTo("Mem") == 0) {

        parseMemLine(tokenizer);
    } else if (start.compareTo("Swap") == 0) {

        parseSwapLine(tokenizer);
    } else if (start.compareTo("PID") == 0) { // Header line

        parseHeaderLine(tokenizer); // we read the header line

        // ExecutionFootprintList fp = tempReadPerformanceData();
    } else if (start.startsWith("monitored_pid=")) {
        // do nothing
    } else {
        try {
            Integer pid = new Integer(start.trim());

            // if (pid.equals(monitoredPid)) {
            // currentExecutionFootprint.setPid(pid);
            ProcessExecutionFootprint pfp = parseProcessLine(tokenizer);

            pfp.setPid(pid);

            currentExecutionFootprint.getProcesses().add(pfp);
            // }

        } catch (NumberFormatException e) {
            log.error(e);
        }
    }
}

From source file:com.commsen.apropos.web.PropertyTableModel.java

/**
 * @param o1//from  w w w. j  a v  a2 s . c  o  m
 * @param o2
 * @param currentCloumn
 */
private int compareFields(int sort, String f1, String f2) {
    if (f1 == null)
        f1 = " ";
    if (f2 == null)
        f2 = " ";
    switch (sort) {
    case SORT_ASCENDING:
        return f1.compareTo(f2);
    case SORT_DESCENDING:
        return f2.compareTo(f1);
    }
    return 0;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetStudyTreeListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setStudyTreeUI.displayMessage("Error: no subject to sample mapping file");
    }/*from w  w  w.j  a  v  a2  s  . com*/
    String category = "";
    TreeNode node = this.setStudyTreeUI.getRoot();
    if (!node.hasChildren()) {
        this.setStudyTreeUI.displayMessage("You have to set a category code");
        return;
    }
    node = node.getChildren().get(0);
    while (node != null) {
        if (category.compareTo("") == 0) {
            category += node.toString().replace(' ', '_');
        } else {
            category += "+" + node.toString().replace(' ', '_');
        }
        if (node.hasChildren()) {
            node = node.getChildren().get(0);
        } else {
            node = null;
        }
    }
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + fields[3] + "\t" + fields[4]
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + category + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setStudyTreeUI.displayMessage("File error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setStudyTreeUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setStudyTreeUI.displayMessage("Eerror: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setStudyTreeUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:com.krawler.esp.portalmsg.Mail.java

public static int GetMailMessagesCount(Connection conn, String folderid, String loginid)
        throws ServiceException {
    int tCount = 0;

    String query = null;//w  w w .  jav a  2s .  c  o  m
    Object[] params = { null };
    // try{
    if (folderid.compareTo("0") == 0) {
        query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.poster_id where "
                + "folder = '0' and to_id = ?";
        params[0] = loginid;
    } else if (folderid.compareTo("1") == 0) {
        query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.to_id where folder = '1' and "
                + "poster_id = ?";
        params[0] = loginid;
    } else if (folderid.compareTo("4") == 0)// Starred Items
    {
        query = "Select count(post_id) from mailmessages where post_id IN (Select post_id from mailmessages inner join users on "
                + "users.userid = mailmessages.poster_id where folder = '0' and to_id = ? and flag = true  union "
                + "Select post_id from mailmessages inner join users on users.userid = mailmessages.to_id where folder = '1' and "
                + "poster_id = ? and flag = true)";
        params[0] = loginid;
        params[1] = loginid;
    } else {
        query = "Select count(post_id) from mailmessages where post_id IN (Select post_id from mailmessages inner join users on "
                + "users.userid = mailmessages.poster_id where folder = ? and to_id = ? union Select post_id from mailmessages inner join "
                + "users on users.userid = mailmessages.to_id where folder = ? and poster_id = ?)";
        params[0] = folderid;
        params[1] = loginid;
        params[2] = folderid;
        params[3] = loginid;
    }

    DbResults rsc = DbUtil.executeQuery(conn, query, params);
    while (rsc.next()) {
        tCount = rsc.getInt(1);
    }

    return tCount;
}

From source file:com.krawler.esp.portalmsg.Mail.java

public static int fetchMailCount(Connection conn, String loginid, String i, int offset, int limit)
        throws ServiceException {
    int tCount = 0;
    String query = null;// w w  w .  j a  v a2s.  c  o  m
    DbResults rs = null;
    try {
        if (i.compareTo("0") == 0) {

            query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.poster_id where folder = '0' and to_id = ?";
            rs = DbUtil.executeQuery(conn, query, loginid);
        } else if (i.compareTo("1") == 0) {

            query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.to_id where folder = '1' and poster_id = ?";
            rs = DbUtil.executeQuery(conn, query, loginid);
        } else if (i.compareTo("4") == 0)// Starred Items
        {
            query = "Select count(*) from (Select post_id from mailmessages inner join users on users.userid = mailmessages.poster_id where to_id = ? and flag = true and (folder in ('0',?) or folder in (select folderid from mailuserfoldersmap where userid =?))  union Select post_id from mailmessages inner join users on users.userid = mailmessages.to_id where (folder in ('1','3',?) or folder in (select folderid from mailuserfoldersmap where userid =?)) and poster_id =? and flag = true) as tmp";
            rs = DbUtil.executeQuery(conn, query, new Object[] { loginid, getDelId(loginid, "0"), loginid,
                    getDelId(loginid, "1"), loginid, loginid });
            //            query = "Select count(post_id) from mailmessages where post_id IN (Select post_id from mailmessages inner join users on users.userid = mailmessages.poster_id where to_id = ? and flag = true and folder!=2  union Select post_id from mailmessages inner join users on users.userid = mailmessages.to_id where folder = '1' and poster_id = ? and flag = true)";
            //            rs = DbUtil.executeQuery(conn, query, new Object[] { loginid,
            //                  loginid });
        } else if (i.compareTo("3") == 0) {
            query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.to_id where folder = ? and poster_id = ?";
            rs = DbUtil.executeQuery(conn, query, new Object[] { "3", loginid });

        } else {
            //                                if(i.equals("3")){
            //                                    i=getDraftId(loginid);
            //                                }
            String i1 = i;
            if (i.equals("2")) {
                i = getDelId(loginid, "0");
                i1 = getDelId(loginid, "1");
            }
            query = "Select count(post_id) from mailmessages where post_id IN (Select post_id from mailmessages inner join users on users.userid = mailmessages.poster_id where folder = ? and to_id = ? union Select post_id from mailmessages inner join users on users.userid = mailmessages.to_id where folder = ? and poster_id =?)";
            rs = DbUtil.executeQuery(conn, query, new Object[] { i, loginid, i1, loginid });
        }

        while (rs.next()) {
            tCount = rs.getInt(1);
        }
    } catch (ServiceException e) {
    }
    return tCount;
}

From source file:edu.cmu.tetrad.search.TimeSeriesUtils.java

/**
 * Creates new time series dataset from the given one with index variable (e.g., time)
 *//*  ww  w .  j a v  a  2s .  c o m*/
public static DataSet createLagDataWithIndex(DataSet data, int numLags) {
    List<Node> variables = data.getVariables();
    int dataSize = variables.size();
    int laggedRows = data.getNumRows() - numLags;
    IKnowledge knowledge = new Knowledge2();
    Node[][] laggedNodes = new Node[numLags + 1][dataSize];
    List<Node> newVariables = new ArrayList<>((numLags + 1) * dataSize + 2); // added 1 to this

    for (int lag = 0; lag <= numLags; lag++) {
        for (int col = 0; col < dataSize; col++) {
            Node node = variables.get(col);
            String varName = node.getName();
            Node laggedNode;
            String name = varName;

            if (lag != 0) {
                name = name + ":" + lag;
            }

            if (node instanceof ContinuousVariable) {
                laggedNode = new ContinuousVariable(name);
            } else if (node instanceof DiscreteVariable) {
                DiscreteVariable var = (DiscreteVariable) node;
                laggedNode = new DiscreteVariable(var);
                laggedNode.setName(name);
            } else {
                throw new IllegalStateException("Node must be either continuous or discrete");
            }
            newVariables.add(laggedNode);
            laggedNode.setCenter(80 * col + 50, 80 * (numLags - lag) + 50);
            laggedNodes[lag][col] = laggedNode;
            //                knowledge.addToTier(numLags - lag + 1, laggedNode.getName());
        }
    }

    String name = "time";
    Node indexNode = new ContinuousVariable(name);
    indexNode.setName(name);
    newVariables.add(indexNode);
    indexNode.setCenter(50, 80 * (numLags - 1) + 50);
    knowledge.addToTier(0, indexNode.getName());

    //        System.out.println("Variable list before the sort = " + variables);
    Collections.sort(newVariables, new Comparator<Node>() {
        @Override
        public int compare(Node o1, Node o2) {
            String name1 = getNameNoLag(o1);
            String name2 = getNameNoLag(o2);

            //                System.out.println("name 1 = " + name1);
            //                System.out.println("name 2 = " + name2);

            String prefix1 = getPrefix(name1);
            String prefix2 = getPrefix(name2);

            //                System.out.println("prefix 1 = " + prefix1);
            //                System.out.println("prefix 2 = " + prefix2);

            int index1 = getIndex(name1);
            int index2 = getIndex(name2);

            //                System.out.println("index 1 = " + index1);
            //                System.out.println("index 2 = " + index2);

            if (getLag(o1.getName()) == getLag(o2.getName())) {
                if (prefix1.compareTo(prefix2) == 0) {
                    return Integer.compare(index1, index2);
                } else {
                    return prefix1.compareTo(prefix2);
                }

            } else {
                return getLag(o1.getName()) - getLag(o2.getName());
            }
        }
    });

    //        System.out.println("Variable list after the sort = " + variables);

    for (Node node : newVariables) {
        String varName = node.getName();
        if (varName.equals("time"))
            continue;
        String tmp;
        int lag;
        if (varName.indexOf(':') == -1) {
            lag = 0;
            //                laglist.add(lag);
        } else {
            tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
            lag = Integer.parseInt(tmp);
            //                laglist.add(lag);
        }
        knowledge.addToTier(numLags - lag + 1, node.getName());
    }

    DataSet laggedData = new ColtDataSet(laggedRows, newVariables);
    for (int lag = 0; lag <= numLags; lag++) {
        for (int col = 0; col < dataSize; col++) {
            for (int row = 0; row < laggedRows; row++) {
                Node laggedNode = laggedNodes[lag][col];
                if (laggedNode instanceof ContinuousVariable) {
                    double value = data.getDouble(row + numLags - lag, col);
                    laggedData.setDouble(row, col + lag * dataSize, value);
                } else {
                    int value = data.getInt(row + numLags - lag, col);
                    laggedData.setInt(row, col + lag * dataSize, value);
                }
            }
        }
    }

    // fill indexNode with for loop over rows
    for (int row = 0; row < laggedRows; row++) {
        laggedData.setDouble(row, dataSize + numLags * dataSize, row + 1);
    }

    knowledge.setDefaultToKnowledgeLayout(true);
    laggedData.setKnowledge(knowledge);
    System.out.println("Knowledge set to : " + knowledge);
    return laggedData;
}

From source file:net.gtaun.shoebill.object.Player.java

/**
 * Gets a Player or npc by a part of his name
 *
 * @param partOfName Part of the name/*w w w. j a v  a  2s.  co m*/
 * @return The found player, or else null
 */
static Player getByPartOfName(String partOfName) {
    partOfName = partOfName.trim();
    int highestHit = -25;
    Player highestHitPlayer = null;
    for (Player player : get()) {
        String playerName = player.getName();
        if (playerName.contains(partOfName)) {
            int result = Math.abs(playerName.compareTo(partOfName));
            if (highestHitPlayer == null || result < highestHit) {
                highestHit = result;
                highestHitPlayer = player;
            }
        }
    }
    return highestHitPlayer;
}

From source file:com.clevertrail.mobile.findtrail.Activity_FindTrail_ByLocation.java

public Point getLatLong(JSONObject jsonObject) {

    Double lon = new Double(0);
    Double lat = new Double(0);

    try {//from w ww .j av  a 2  s . c o  m
        String sStatus = ((String) jsonObject.get("status"));
        if (sStatus.compareTo("OK") != 0)
            return null;

        //look into the json for the lat/long
        lon = ((JSONArray) jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry")
                .getJSONObject("location").getDouble("lng");

        lat = ((JSONArray) jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry")
                .getJSONObject("location").getDouble("lat");

    } catch (Exception e) {
        e.printStackTrace();
        return null;

    }

    return new Point(lat, lon);
}

From source file:com.zlfun.framework.table.ItemComparator.java

@Override
public int compare(T o1, T o2) {

    Map<String, String> o1m = TableUtils.genItemFieldMap(o1);
    Map<String, String> o2m = TableUtils.genItemFieldMap(o2);

    String var1 = o1m.get(name);
    String var2 = o2m.get(name);
    if (isNumeric(var1) && isNumeric(var2)) {
        if (asc) {
            return Double.compare(Double.parseDouble(var1), Double.parseDouble(var2));

        } else {// w  w w.j a va 2  s .  c  o m
            return Double.compare(Double.parseDouble(var2), Double.parseDouble(var1));
        }
    } else {
        if (asc) {
            return var1.compareTo(var2);
        } else {
            return var2.compareTo(var1);
        }
    }

}

From source file:com.github.fengtan.sophie.tables.AbstractSortableTable.java

/**
 * Add a new column to the table./* w ww.  j a v a  2 s.  c  om*/
 * 
 * @param columnName
 *            Column name.
 * @return The newly created column.
 */
protected TableColumn addColumn(final String columnName) {
    // Add column name to our internal list.
    columnNames.add(columnName);

    // Instantiate column.
    final TableColumn column = new TableColumn(table, SWT.LEFT);
    column.setData("columnName", columnName);
    column.setText(columnName + "     ");
    column.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            // Clicking on the current sort field toggles the direction.
            // Clicking on a new field changes the sort field.
            if (StringUtils.equals(sortColumnName, columnName)) {
                sortAsc = !sortAsc;
            } else {
                sortColumnName = columnName;
            }
            Comparator<Map<String, String>> comparator = new Comparator<Map<String, String>>() {
                @Override
                public int compare(Map<String, String> rowValues1, Map<String, String> rowValues2) {
                    String value1 = rowValues1.get(columnName);
                    String value2 = rowValues2.get(columnName);
                    if (sortAsc) {
                        return (value1 == null) ? -1 : value1.compareTo(value2);
                    } else {
                        return (value2 == null) ? -1 : value2.compareTo(value1);
                    }
                }
            };
            Collections.sort(rowValues, comparator);
            table.removeAll();
            for (Map<String, String> values : rowValues) {
                createRow(values);
            }
            setSortSignifier();
        }
    });

    // Pack.
    column.pack();
    return column;
}