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.optimusinfo.elasticpath.cortex.checkout.AsyncTaskGetCheckout.java

@Override
protected void onPostExecute(String responseCheckOut) {
    super.onPostExecute(responseCheckOut);
    try {//from w  ww .  j ava  2s . c  o m
        if (responseCheckOut != null && responseCheckOut.length() != 0) {
            if (0 == responseCheckOut
                    .compareTo(Integer.toString(Constants.ApiResponseCode.UNAUTHORIZED_ACCESS))) {
                mListener.onAuthenticationFailed();
            } else {
                mListener.onTaskSuccessful(new Gson().fromJson(responseCheckOut, CheckoutModel.class));
            }
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
        mListener.onTaskFailed(Constants.ErrorCodes.ERROR_SERVER);
    }
}

From source file:geogebra.kernel.AlgoClasses.java

protected final void compute() {

    // Validate input arguments
    //=======================================================

    if (!dataList.isDefined() || dataList.size() == 0) {
        classList.setUndefined();//from  w  w  w. j a  v a2 s  .c o  m
        return;
    }

    if (!(dataList.getElementType() == GeoElement.GEO_CLASS_TEXT
            || dataList.getElementType() == GeoElement.GEO_CLASS_NUMERIC)) {
        classList.setUndefined();
        return;
    }

    classList.setDefined(true);
    classList.clear();

    // Get data max and min 
    //=======================================================

    double minGeoValue = 0;
    double maxGeoValue = 0;
    String minGeoString;
    String maxGeoString;

    if (dataList.getElementType() == GeoElement.GEO_CLASS_NUMERIC) {
        minGeoValue = ((GeoNumeric) dataList.get(0)).getDouble();
        maxGeoValue = ((GeoNumeric) dataList.get(0)).getDouble();
        for (int i = 1; i < dataList.size(); i++) {
            double geoValue = ((GeoNumeric) dataList.get(i)).getDouble();
            minGeoValue = Math.min(geoValue, minGeoValue);
            maxGeoValue = Math.max(geoValue, maxGeoValue);
        }

    } else {
        minGeoString = ((GeoText) dataList.get(0)).toValueString();
        maxGeoString = ((GeoText) dataList.get(0)).toValueString();
        for (int i = 1; i < dataList.size(); i++) {
            String geoString = ((GeoText) dataList.get(i)).toValueString();
            if (geoString.compareTo(minGeoString) < 0)
                minGeoString = geoString;
            if (geoString.compareTo(maxGeoString) < 0)
                maxGeoString = geoString;
        }
    }

    // Create class list using number of classes   
    //=======================================================

    if (input.length == 2) {

        int n = (int) numClasses.getDouble();
        if (n < 1)
            classList.setUndefined();

        double width = (maxGeoValue - minGeoValue) / n;
        for (int i = 0; i < n; i++) {
            classList.add(new GeoNumeric(cons, minGeoValue + i * width));
        }
        classList.add(new GeoNumeric(cons, maxGeoValue));

    }

    // Create class list using start and width    
    //=======================================================
    if (input.length == 3) {
        double value = start.getDouble();
        classList.add(new GeoNumeric(cons, value));
        while (value < maxGeoValue) {
            value = value + width.getDouble();
            //System.out.println("value: " + value + "max: " + maxGeoValue);
            classList.add(new GeoNumeric(cons, value));
        }
        if (classList.size() < 2)
            classList.setUndefined();
    }
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectCMFListener.java

public boolean checkFormat(File file) {
    boolean isSubjectIdSet = false;
    try {/*  www .jav  a 2s  .co m*/
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
            if (line.compareTo("") != 0) {
                String[] fields = line.split("\t", -1);
                //check columns number
                if (fields.length != 6) {
                    this.selectCMFUI.displayMessage("Error:\nLines have not the right number of columns");
                    br.close();
                    return false;
                }
                //check raw file names
                if (!((ClinicalData) this.dataType).getRawFilesNames().contains(fields[0])) {
                    this.selectCMFUI.displayMessage("Error:\nData file '" + fields[0] + "' does not exist");
                    br.close();
                    return false;
                }
                //check that subject identifier is set
                if (fields[3].compareTo("SUBJ_ID") == 0) {
                    isSubjectIdSet = true;
                }
                //check that column number is set and is a number
                if (fields[2].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nColumns numbers have to be set");
                    br.close();
                    return false;
                }
                try {
                    Integer.parseInt(fields[2]);
                } catch (NumberFormatException e) {
                    this.selectCMFUI.displayMessage("Error:\nColumns numbers have to be numbers");
                    br.close();
                    return false;
                }
                //check that datalabel is set
                if (fields[3].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nData labels have to be set");
                    br.close();
                    return false;
                }
                //check that category code is set, except for reserved words
                if (!(fields[3].compareTo("SUBJ_ID") == 0 || fields[3].compareTo("OMIT") == 0
                        || fields[3].compareTo("SITE_ID") == 0 || fields[3].compareTo("VISIT_NAME") == 0)
                        && fields[1].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nCategory codes have to be set");
                    br.close();
                    return false;
                }
                //check that data label source is set if the data label is '\'
                if (fields[3].compareTo("\\") == 0 && fields[4].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nData label sources have to be set");
                    br.close();
                    return false;
                }
            }
        }
        br.close();
    } catch (Exception e) {
        this.selectCMFUI.displayMessage("File error: " + e.getLocalizedMessage());
        e.printStackTrace();
        return false;
    }
    if (!isSubjectIdSet) {
        this.selectCMFUI.displayMessage("Error:\nSubject identifiers have to be set");
        return false;
    }
    return true;
}

From source file:com.sfs.beans.UserPreferencesBean.java

/**
 * Sets the option.//from  www . ja  v a  2 s .  c om
 *
 * @param index the index
 * @param value the value
 */
public final void setOption(final String index, final String value) {
    if (this.options == null) {
        this.options = new HashMap<String, String>();
    }
    if (index != null && index.compareTo("") != 0 && value != null) {
        this.options.put(index, value);
    }
}

From source file:com.groupon.odo.tests.HttpTests.java

@Test
public void testRedirectCustomOverride() throws Exception {
    String overrideResponse = "overridden";
    testServer.setLastExchange(null);/*ww  w.  ja  v a 2  s .  co  m*/

    Client client = new Client("Consumer API", false);
    client.toggleProfile(true);
    client.addServerMapping("localhost", "127.0.0.1:8080", null);
    client.setCustomResponse("Global", overrideResponse);
    client.toggleResponseOverride("Global", true);

    String response = HttpUtils.doProxyGet("http://localhost/", null);
    System.out.println(response);
    HttpExchangeInfo info = testServer.getLastExchange();
    assertNull(info);
    assertTrue(response.compareTo(overrideResponse) == 0);
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9DimensionRepo.java

private List<String> filterDimensionValues(Set<String> matchingValues, int limit, String offset) {
    Boolean haveOffset = !Strings.isNullOrEmpty(offset);
    List<String> filteredValues = new ArrayList<String>();
    int remaining_limit = limit + 1;

    for (String dimVal : matchingValues) {
        if (remaining_limit <= 0) {
            break;
        }/* www . ja  v  a  2s . c o m*/
        if (haveOffset && dimVal.compareTo(offset) <= 0) {
            continue;
        }
        filteredValues.add(dimVal);
        remaining_limit--;
    }

    return filteredValues;
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9DimensionRepo.java

private List<String> filterDimensionNames(Set<String> matchingNames, int limit, String offset) {
    Boolean haveOffset = !Strings.isNullOrEmpty(offset);
    List<String> filteredNames = new ArrayList<String>();
    int remaining_limit = limit + 1;

    for (String dimName : matchingNames) {
        if (remaining_limit <= 0) {
            break;
        }// w  w  w.  j a v a  2 s.  com
        if (haveOffset && dimName.compareTo(offset) <= 0) {
            continue;
        }
        filteredNames.add(dimName);
        remaining_limit--;
    }

    return filteredNames;
}

From source file:de.thischwa.pmcms.tool.file.FileComparator.java

@Override
public int compare(final File f1, final File f2) {
    if (f1.getAbsolutePath().equals(f2.getAbsolutePath()))
        return 0;

    String path1 = FilenameUtils.getFullPath(f1.getAbsolutePath());
    String path2 = FilenameUtils.getFullPath(f2.getAbsolutePath());
    String name1 = FilenameUtils.getName(f1.getAbsolutePath());
    String name2 = FilenameUtils.getName(f2.getAbsolutePath());
    if (path1.equals(path2) || (StringUtils.isBlank(path1) && StringUtils.isBlank(path2)))
        return name1.compareTo(name2);
    String[] pathParts1 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path1), File.separatorChar);
    String[] pathParts2 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path2), File.separatorChar);

    if (pathParts1.length < pathParts2.length)
        return -1;
    if (pathParts1.length > pathParts2.length)
        return +1;

    int i = 0;//ww  w. j  a  v a  2s .co  m
    while (i < pathParts1.length && i < pathParts2.length) {
        if (!pathParts1[i].equals(pathParts2[i]))
            return pathParts1[i].compareTo(pathParts2[i]);
        i++;
    }
    return 0;
}

From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java

private void pruneCache() {
    String expireTime = LocalDateTime.now().minusHours(ttl).format(Util.timeFormatter);
    log.info("{expireTime:{}}", expireTime);

    for (String rowKey : table.keySet()) {
        ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> rowMap = table.get(rowKey);
        for (String columnKey : rowMap.keySet()) {
            ConcurrentSkipListMap<String, ConcurrentSet<T>> columnMap = rowMap.get(columnKey);

            Iterator<String> iterator = columnMap.keySet().iterator();
            while (iterator.hasNext()) {
                String timesplices = iterator.next();
                if (timesplices.compareTo(expireTime) < 0) {
                    columnMap.get(timesplices).clear();
                    iterator.remove();//from www. j a  va  2  s .  c o m
                } else {
                    break;
                }
            }
        }
    }

}

From source file:com.linkedin.pinot.core.data.readers.MultiplePinotSegmentRecordReaderTest.java

@Test
public void testMultiplePinotSegmentRecordReaderSortedColumn() throws Exception {
    List<String> sortOrder = new ArrayList<>();
    sortOrder.add(D_SV_1);/*from   w ww .j av  a  2  s.c  o  m*/
    sortOrder.add(D_SV_2);

    List<GenericRow> outputRows = new ArrayList<>();
    try (MultiplePinotSegmentRecordReader pinotSegmentRecordReader = new MultiplePinotSegmentRecordReader(
            _segmentIndexDirList, null, sortOrder)) {
        while (pinotSegmentRecordReader.hasNext()) {
            outputRows.add(pinotSegmentRecordReader.next());
        }
    }

    Assert.assertEquals(outputRows.size(), NUM_SEGMENTS * NUM_ROWS,
            "Number of rows returned by PinotSegmentRecordReader is incorrect");
    GenericRow prev = outputRows.get(0);
    for (int i = 1; i < outputRows.size(); i++) {
        GenericRow current = outputRows.get(i);
        String prevValue = (String) prev.getValue(D_SV_1);
        String currentValue = (String) current.getValue(D_SV_1);
        Assert.assertTrue(prevValue.compareTo(currentValue) <= 0);

        // Check secondary order
        if (prevValue.equals(currentValue)) {
            Integer prevSecondValue = (Integer) prev.getValue(D_SV_2);
            Integer currentSecondValue = (Integer) current.getValue(D_SV_2);
            Assert.assertTrue(prevSecondValue.compareTo(currentSecondValue) <= 0);
        }

        prev = current;
    }
}