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.moha.demo.utils.Hashsalt.java

public boolean equals(String password, AsUser user) {
    String encryptPassword = encrypt(password + user.getSalt());
    if (encryptPassword.compareTo(user.getUserPassword()) == 0) {
        return true;
    }/*from  w w w  . ja  v a2 s . c  o  m*/

    return false;
}

From source file:SubstringComparator.java

public int compare(Object o1, Object o2) {
    String s1 = o1.toString().substring(1);
    String s2 = o2.toString().substring(1);
    return s1.compareTo(s2);
    // or, more concisely:
    // return o1.toString().substring(1).equals(o2.toString().substring(1));
}

From source file:de.kp.ames.web.core.json.StringCollector.java

public StringCollector() {

    collector = new TreeMap<String, ArrayList<JSONObject>>(new Comparator<String>() {
        public int compare(String name1, String name2) {
            return name1.compareTo(name2);
        }/*from   w ww  .  j  a va2  s .co m*/
    });

}

From source file:jsentvar.RDFReaderTest.java

/**
 * Test of reader method, of class RDFReader.
 * Realy, it doesn't work (I mean, test)
 * @throws java.io.IOException//from w  w  w.j  av  a  2s  .c  o  m
 */
@Test
public void testReader() throws IOException {
    //miniReasoner.owl
    System.out.println("Testing RDFReader.reader");
    String inputFileName = "resources/test/miniReasoner.owl";
    RDFReader instance = new RDFReader();

    String expResult = FileUtils.readFileToString(new File("resources/test/mini_model.txt"), "utf8").trim();
    Model model = instance.reader(inputFileName);

    //FileUtils.writeStringToFile(new File("resources/test/mini_model2.txt"),model.toString());

    //String result = FileUtils.readFileToString(new File("resources/test/mini_model2.txt")).trim();
    String result = model.toString().trim();
    int diff = result.compareTo(expResult);
    System.out.println(expResult);
    System.out.println(result);
    System.out.println(diff);
    assertEquals(expResult, result);
    // TODO review the generated test code and remove the default call to fail.
    //fail("This is not the expected result");
}

From source file:TestDB.java

public int compare(byte[] rec1, byte[] rec2) {
    String r1 = new String(rec1);
    String r2 = new String(rec2);
    if (r1.compareTo(r2) > 0)
        return (RecordComparator.FOLLOWS);
    else if (r1.compareTo(r2) < 0)
        return (RecordComparator.PRECEDES);
    else//w w  w.  java2s.  c om
        return (RecordComparator.EQUIVALENT);
}

From source file:kr.co.aim.nanoframe.orm.SQLLogUtil.java

public int compare(String o1, String o2) {
    int result = o1.compareTo(o2);
    return sortOrderAscending ? result : -result;
}

From source file:org.yroffin.neo4b.services.BoardMapper.java

public void map() throws IOException, URISyntaxException {

    // GET//from w ww  .  ja v  a  2  s .co  m
    spark.Spark.get("/api/boardManagement/v1/boards", (request, response) -> {
        response.type("application/json");
        response.body(boardResource.getBoards(request.body(), BoardRest.class));
        return response.body();
    });

    // POST
    spark.Spark.post("/api/boardManagement/v1/boards", (request, response) -> {
        response.type("application/json");
        response.body(boardResource.createBoard(request.body(), BoardRest.class));
        return response.body();
    });

    // DELETE
    spark.Spark.delete("/api/boardManagement/v1/boards/:id", (request, response) -> {
        response.type("application/json");
        try {
            response.body(boardResource.deleteBoard(request.params(":id"), BoardRest.class));
        } catch (org.yroffin.neo4b.exception.NotFoundException e) {
            response.body("{}");
            response.status(404);
        }
        return response.body();
    });

    // Static
    // Spark.staticFileLocation("public");

    spark.Spark.get("*", (request, response) -> {
        String path = request.pathInfo();
        if (path.compareTo("/") == 0) {
            path = "/index.html";
        }
        String content = new String(Files.readAllBytes(Paths.get("src/main/resources/public" + path)));
        if (path.endsWith(".css")) {
            response.type("text/css");
        }
        return content;
    });
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.variants.impl.DefaultVariantComparator.java

@Override
public int compare(final Object variant1, final Object variant2) {
    if (variant1 instanceof Number) {
        final double number1 = ((Number) variant1).doubleValue();
        final double number2 = ((Number) variant2).doubleValue();
        return NumberUtils.compare(number1, number2);
    } else if (variant1 instanceof String) {
        final String string1 = (String) variant1;
        final String string2 = (String) variant2;
        return string1.compareTo(string2);
    } else {//from  w ww. j av a 2s . c  o m
        return getResult(variant1, variant2);
    }
}

From source file:com.epam.cme.storefront.variants.impl.DefaultVariantComparator.java

@Override
public int compare(final Object variant1, final Object variant2) {
    if (variant1 instanceof Number) {
        final double number1 = ((Number) variant1).doubleValue();
        final double number2 = ((Number) variant2).doubleValue();
        return NumberUtils.compare(number1, number2);
    } else if (variant1 instanceof String) {
        final String string1 = (String) variant1;
        final String string2 = (String) variant2;
        return string1.compareTo(string2);
    } else {/*from  w w w  .  jav  a2s . co  m*/
        if (variant1 == null && variant2 == null) {
            return 0;
        } else if (variant1 == null) {
            return -1;
        } else if (variant2 == null) {
            return 1;
        }
        return variant1.toString().compareTo(variant2.toString());
    }
}

From source file:ByteString.java

public int compareTo(ByteString o) {
    /*//from  w ww  .j  av  a2 s  . co  m
     * FIXME: This is inefficient 
     */
    String s1 = new String(bytes);
    String s2 = new String(o.bytes);
    return s1.compareTo(s2);
}