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:J2MESortExample.java

public int compare(byte[] record1, byte[] record2) {
    String string1 = new String(record1), string2 = new String(record2);
    int comparison = string1.compareTo(string2);
    if (comparison == 0)
        return RecordComparator.EQUIVALENT;
    else if (comparison < 0)
        return RecordComparator.PRECEDES;
    else/* www  .  ja v a 2  s.  c  o  m*/
        return RecordComparator.FOLLOWS;
}

From source file:com.medlog.webservice.rest.RES_ENUM.java

/**
 * Funtion requires login//from   ww  w .ja  v a 2 s  .  c  o  m
 *
 * @param fn
 * @return
 */
public boolean isLoginRequired(String fn) {
    boolean a = this.getCode().compareTo("p") + fn.compareTo(API_FUNCTION_INSERT) == 0;
    return !(a || StrUtl.matchOR(true, fn.equals(API_FUNCTION_LOGIN), fn.equals(API_FUNCTION_LOGOUT)));
}

From source file:com.newlandframework.avatarmq.consumer.ConsumerClusters.java

public void detachRemoteChannelData(String clientId) {
    channelMap.remove(clientId);//from   w ww.j  ava 2  s . c o m

    Predicate predicate = new Predicate() {
        public boolean evaluate(Object object) {
            String id = ((RemoteChannelData) object).getClientId();
            return id.compareTo(clientId) == 0;
        }
    };

    RemoteChannelData data = (RemoteChannelData) CollectionUtils.find(channelList, predicate);
    if (data != null) {
        channelList.remove(data);
    }
}

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

public static String iCaltoKWLDayDate(String idate) {
    try {//from  w ww . j  av a2  s  .c  o  m
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
        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:com.krawler.esp.servlets.importICSServlet.java

public static String iCaltoKWLEndDayDate(String idate) {
    try {/*from   w ww.  j ava2s  .  com*/
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
        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:SampleSortingTableModel.java

protected int compare(int i, int j) {
    String s1 = base.getValueAt(row[i], sortColumn).toString();
    String s2 = base.getValueAt(row[j], sortColumn).toString();
    return s1.compareTo(s2);
}

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

public static String getTimeHourDiff(String Estartts, String Eendts) {
    long hours = 0;
    long diffInMilleseconds = 0;
    try {//  w ww  .  j  a v  a2s .  c om
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:00:00.00");

        if (Estartts.compareTo("") != 0 && Eendts.compareTo("") != 0) {
            java.util.Date sdt = sdf.parse(Estartts);
            java.util.Date edt = sdf.parse(Eendts);

            diffInMilleseconds = edt.getTime() - sdt.getTime();
            hours = diffInMilleseconds / (60 * 60 * 1000);
            if (hours < 1) {
                if (edt.getHours() == 0) {
                    Eendts = getNextDay(Estartts);
                } else {
                    diffInMilleseconds = edt.getTime() + (60 * 60 * 1000);
                    edt.setTime(diffInMilleseconds);
                    Eendts = sdf.format(edt);
                }
            }
        }
    } catch (ParseException ex) {
        hours = 0;
    } finally {
        return Eendts;
    }
}

From source file:ComparatorExampleForUserDefinedClass.java

public int compare(Object o1, Object o2) {
    if (o1 instanceof String && o2 instanceof String) {
        String s1 = (String) o1;
        String s2 = (String) o2;
        s1 = s1.substring(0, s1.indexOf("-"));
        s2 = s2.substring(0, s2.indexOf("-"));
        return s1.compareTo(s2);
    }// w  w w. j  a va 2 s .  co m
    return 0;
}

From source file:com.simiacryptus.mindseye.models.Hdf5Archive.java

private static void printTree(@Nonnull Hdf5Archive hdf5, CharSequence prefix, boolean printData,
        @Nonnull Logger log, @Nonnull String... path) {
    for (CharSequence datasetName : hdf5.getDataSets(path)) {
        @Nullable/* w w  w . jav a  2 s.  c om*/
        Tensor tensor = hdf5.readDataSet(datasetName.toString(), path);
        log.info(String.format("%sDataset %s: %s", prefix, datasetName,
                Arrays.toString(tensor.getDimensions())));
        if (printData)
            log.info(String.format("%s%s", prefix, tensor.prettyPrint().replaceAll("\n", "\n" + prefix)));
        tensor.freeRef();
    }
    hdf5.getAttributes(path).forEach((k, v) -> {
        log.info((String.format("%sAttribute: %s => %s", prefix, k, v)));
    });
    for (String t : hdf5.getGroups(path).stream().map(CharSequence::toString).sorted(new Comparator<String>() {
        @Override
        public int compare(@Nonnull String o1, @Nonnull String o2) {
            @Nonnull
            String prefix = "layer_";
            @Nonnull
            Pattern digit = Pattern.compile("^\\d+$");
            if (digit.matcher(o1).matches() && digit.matcher(o2).matches())
                return Integer.compare(Integer.parseInt(o1), Integer.parseInt(o2));
            if (o1.startsWith(prefix) && o2.startsWith(prefix))
                return compare(o1.substring(prefix.length()), o2.substring(prefix.length()));
            else
                return o1.compareTo(o2);
        }
    }).collect(Collectors.toList())) {
        log.info(prefix + t);
        printTree(hdf5, prefix + "\t", printData, log, concat(path, t));
    }
}

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

public static String getNextDay(String iDate) {
    try {/*from w  w w.  j a  v a 2s  . co  m*/
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH");
        java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd 00:00:00");

        if (iDate.compareTo("") != 0) {
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.setTime(sdf.parse(iDate));

            cal.add(java.util.Calendar.DATE, 1);

            iDate = sdf1.format(cal.getTime());
        }
    } catch (ParseException ex) {
        iDate = "";
    } finally {
        return iDate;
    }
}