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.krawler.esp.servlets.importICSServlet.java

public static String iCaltoKWLDate(String idate) {
    try {//from  www  .ja  v  a 2s  .c o m
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
        java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:00:00.00");

        if (idate.compareTo("") != 0) {
            java.util.Date dt = sdf.parse(idate);
            idate = sdf1.format(dt);
        }
    } catch (ParseException ex) {
        idate = "";
    } finally {
        return idate;
    }
}

From source file:com.krawler.esp.servlets.importICSServlet.java

public static String iCaltoStartDate(String idate) {
    try {/*from  ww  w . j a v a 2 s  .co m*/
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
        java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd 00:00:00.00");

        if (idate.compareTo("") != 0) {
            java.util.Date dt = sdf.parse(idate);
            idate = sdf1.format(dt);
        }
    } catch (ParseException ex) {
        idate = "";
    } finally {
        return idate;
    }
}

From source file:de.nrw.hbz.regal.sync.MyConfiguration.java

/**
 * /*from  w w w .ja  va2s .c  o  m*/
 * generates the configuration in terms of arguments and options
 * 
 * @param args
 *            Command line arguments
 * @param options
 *            Command line options
 * @throws ParseException
 *             When the configuration cannot be parsed
 */
MyConfiguration(String[] args, Options options) {
    try {
        CommandLineParser parser = new BasicParser();
        CommandLine commandLine = parser.parse(options, args);
        for (Option option : commandLine.getOptions()) {
            String key = option.getLongOpt();
            // System.out.println(key);
            if (key.compareTo("set") == 0) {
                String[] vals = option.getValues();
                if (vals == null || vals.length == 0) {
                    this.addProperty(key, "N/A");
                } else {
                    StringBuffer val = new StringBuffer();
                    for (int i = 0; i < vals.length; i++) {
                        val.append(vals[i]);
                        val.append(",");
                    }
                    val.delete(val.length(), val.length());
                    this.addProperty(key, val.toString());
                }
            } else {
                String val = option.getValue();
                if (val == null) {
                    this.addProperty(key, "N/A");
                } else {

                    this.addProperty(key, val);
                }
            }
        }
    } catch (ParseException e) {
        throw new ConfigurationParseException(e);
    }
}

From source file:com.mightypocket.ashot.UpdateChecker.java

@Override
protected void succeeded(String newVersion) {
    if (newVersion == null) {
        mediator.setStatus("status.error.updates");
        return;// w  w w .  ja  va2s .c om
    }
    String oldVersion = mediator.getApplication().getContext().getResourceMap()
            .getString("Application.version");
    if (oldVersion.compareTo(newVersion) < 0) {
        mediator.getApplication().showMessage("info.newVersion", newVersion);
    } else {
        mediator.setStatus("status.noupdates");
    }
}

From source file:es.alrocar.jpe.parser.GeoJSONParser.java

/**
 * Parses a single feature with a Point/*from   w w  w.  ja  v a2  s  .  c o m*/
 * 
 * @param feature
 *            The feature {@link JSONObject}
 * @return A {@link JTSFeature}
 * @throws JSONException
 */
public JTSFeature parseFeature(JSONObject feature) throws JSONException {
    JTSFeature feat = new JTSFeature(null);

    JSONObject geometry = (JSONObject) feature.get("geometry");

    String geomType = geometry.get("type").toString();
    if (geomType.compareTo("Point") == 0) {
        JSONArray coords = geometry.getJSONArray("coordinates");
        double x = coords.getDouble(0);
        double y = coords.getDouble(1);

        GeometryFactory factory = new GeometryFactory();
        Coordinate c = new Coordinate();
        c.x = x;
        c.y = y;
        Point p = factory.createPoint(c);
        feat.setGeometry(new JTSGeometry(p));
    } // TODO process other geometry types

    JSONObject props = feature.getJSONObject("properties");
    Iterator it = props.keys();

    String key;

    while (it.hasNext()) {
        key = it.next().toString();
        feat.addField(key, props.getString(key), 0);
    }

    return feat;
}

From source file:mml.DocidComparator.java

public int compare(JSONObject obj1, JSONObject obj2) {
    String docid1 = (String) obj1.get(JSONKeys.DOCID);
    String docid2 = (String) obj2.get(JSONKeys.DOCID);
    if (docid1 != null && docid2 != null)
        return docid1.compareTo(docid2);
    else//w ww.ja  v  a2s .c  o  m
        return 0;
}

From source file:de.lgohlke.sonar.maven.lint.LintSensorTest.java

@Test
public void testConfiguredAllRulesInAnnotation() {

    class StringComparator implements Comparator<String> {
        @Override//from  w w  w  . j a v  a2s  .c o  m
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    }

    Reflections reflections = new Reflections("de.lgohlke.sonar.maven.lint.rules");
    Set<Class<? extends MavenRule>> rulesImplemented = reflections.getSubTypesOf(MavenRule.class);

    Rules rules = LintSensor.class.getAnnotation(Rules.class);

    TreeSet<String> configuredRules = new TreeSet<String>(new StringComparator());
    for (Class clazz : rules.values()) {
        configuredRules.add(clazz.getCanonicalName());
    }
    TreeSet<String> implementedRules = new TreeSet<String>(new StringComparator());
    for (Class clazz : rulesImplemented) {
        implementedRules.add(clazz.getCanonicalName());
    }

    assertThat(configuredRules).isEqualTo(implementedRules);
}

From source file:de.tuttas.websockets.ChatServer.java

@OnMessage
public String onMessage(String jsonMessage) {
    Log.d("ChatServer receive:" + jsonMessage);
    JSONParser parser = new JSONParser();
    JSONObject jo;//  w ww  .j ava 2s  . c o  m
    try {
        jo = (JSONObject) parser.parse(jsonMessage);
        String from = (String) jo.get("from");
        String msg = (String) jo.get("msg");
        if (from.compareTo("System") == 0) {
            users.put(mySession.getId(), msg);
            Log.d("Session " + mySession.getId() + " user " + msg + " zugeordnet");
            jo.put("from", msg);
            jo.put("msg", "beigetreten!");
            jo.put("notoast", true);
        }
        ChatServer.send(jo, mySession);
    } catch (ParseException ex) {
        Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

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

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setSubjectsIdUI.getValues();
    Vector<String> samples = this.setSubjectsIdUI.getSamples();
    for (String v : values) {
        if (v.compareTo("") == 0) {
            this.setSubjectsIdUI.displayMessage("All identifiers have to be set");
            return;
        }//from ww w . j a  v a2  s.c om
    }

    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    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");

        File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
        if (stsmf == null) {
            for (int i = 0; i < samples.size(); i++) {
                out.write(this.dataType.getStudy().toString() + "\t" + "\t" + values.elementAt(i) + "\t"
                        + samples.elementAt(i) + "\t" + "\t" + "\t" + "\t" + "\t" + "\n");
            }
        } else {
            try {
                BufferedReader br = new BufferedReader(new FileReader(stsmf));
                String line = br.readLine();
                while ((line = br.readLine()) != null) {
                    String[] fields = line.split("\t", -1);
                    String sample = fields[3];
                    String subject;
                    if (samples.contains(sample)) {
                        subject = values.get(samples.indexOf(sample));
                    } else {
                        br.close();
                        return;
                    }
                    out.write(fields[0] + "\t" + fields[1] + "\t" + subject + "\t" + sample + "\t" + fields[4]
                            + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
                }
                br.close();
            } catch (Exception e) {
                this.setSubjectsIdUI.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.setSubjectsIdUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setSubjectsIdUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setSubjectsIdUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
    UsedFilesPart.sendFilesChanged(dataType);
}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) {
    boolean es = true;
    //      EnumTipoDatoParametro tipo;
    if (objeto == null) {
        return false;
    } else if (objeto instanceof String) {
        //          tipo = EnumTipoDatoParametro.ALFANUMERICO;
        String val1 = (String) objeto;
        String min1 = (String) minimo;
        String max1 = (String) maximo;
        if (min1 != null && val1.compareTo(min1) < 0) {
            es = false;//from w w  w.  j ava 2s  . c o  m
        }
        if (max1 != null && val1.compareTo(max1) > 0) {
            es = false;
        }
    } else if (objeto instanceof Integer) {
        //          tipo = EnumTipoDatoParametro.ENTERO;
        Integer val4 = (Integer) objeto;
        Integer min4 = (Integer) minimo;
        Integer max4 = (Integer) maximo;
        if (min4 != null && val4.compareTo(min4) < 0) {
            es = false;
        }
        if (max4 != null && val4.compareTo(max4) > 0) {
            es = false;
        }
    } else if (objeto instanceof Long || objeto instanceof BigInteger) {
        //          tipo = EnumTipoDatoParametro.ENTERO_GRANDE;
        Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto;
        Long min5 = (Long) minimo;
        Long max5 = (Long) maximo;
        if (min5 != null && val5.compareTo(min5) < 0) {
            es = false;
        }
        if (max5 != null && val5.compareTo(max5) > 0) {
            es = false;
        }
    } else if (objeto instanceof BigDecimal) {
        //          tipo = EnumTipoDatoParametro.NUMERICO;
        BigDecimal val2 = (BigDecimal) objeto;
        BigDecimal min2 = (BigDecimal) minimo;
        BigDecimal max2 = (BigDecimal) maximo;
        if (min2 != null && val2.compareTo(min2) < 0) {
            es = false;
        }
        if (max2 != null && val2.compareTo(max2) > 0) {
            es = false;
        }
    } else if (objeto instanceof Timestamp) {
        //          tipo = EnumTipoDatoParametro.FECHA_HORA;
        Timestamp val3 = (Timestamp) objeto;
        Timestamp min3 = (Timestamp) minimo;
        Timestamp max3 = (Timestamp) maximo;
        if (min3 != null && val3.compareTo(min3) < 0) {
            es = false;
        }
        if (max3 != null && val3.compareTo(max3) > 0) {
            es = false;
        }
    } else {
        return false;
    }
    return es;
}