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.autburst.picture.Utilities.java

public static Comparator<File> getImageNameComparator() {
    return new Comparator<File>() {
        @Override//from w  ww . ja v  a 2 s .c  o m
        public int compare(File arg0, File arg1) {
            String filename0 = arg0.getName();
            String filename1 = arg1.getName();
            return filename0.compareTo(filename1);
        }
    };
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.Utils.java

/**
 * Obtains a parameter with specified name from from query string. The query should be in format
 * param=value&param=value .../*  w  w w.ja v  a  2  s. c o  m*/
 *
 * @param query     Queery in "url" format.
 * @param paramName Parameter name.
 * @return Parameter value, or null.
 */
public static String getParameterValueFromQuery(String query, String paramName) {
    String[] components = query.split("&");

    for (String keyValuePair : components) {
        String[] pairComponents = keyValuePair.split("=");

        if (pairComponents.length == 2) {
            try {
                String key = URLDecoder.decode(pairComponents[0], "utf-8");
                if (key.compareTo(paramName) == 0) {
                    return URLDecoder.decode(pairComponents[1], "utf-8");
                }
            } catch (UnsupportedEncodingException e) {
                logger.error("getParameterValueFromQuery failed with exception: " + e.getLocalizedMessage(), e);
            }

        }
    }

    return null;
}

From source file:com.sfs.whichdoctor.formatter.GroupFormatter.java

public static Collection<Object> getCollection(final GroupBean group, final String section) {

    Collection<Object> collection = new ArrayList<Object>();

    if (section != null) {
        if (section.compareTo("Items") == 0) {
            if (group.getItems() != null) {
                for (String key : group.getItems().keySet()) {
                    ItemBean item = group.getItems().get(key);
                    collection.add(item);
                }/* ww  w  . j  av a 2s. c  o m*/
            }
        }

        if (section.compareTo("Memos") == 0) {
            if (group.getMemo() != null) {
                for (MemoBean memo : group.getMemo()) {
                    collection.add(memo);
                }
            }
        }
    }
    return collection;
}

From source file:com.clustercontrol.accesscontrol.factory.LoginUserModifier.java

/**
 * ????<BR>//from w w w. j a  v a 2 s .  c  o  m
 * 
 * @param userId ID
 * @param password ??
 * @throws UserNotFound
 * @throws HinemosUnknown
 */
public static void modifyUserPassword(String userId, String password) throws UserNotFound, HinemosUnknown {

    if (userId != null && userId.compareTo("") != 0 && password != null && password.compareTo("") != 0) {
        // ????
        UserInfo user;
        try {
            user = QueryUtil.getUserPK(userId);
            // ???
            user.setPassword(password);

        } catch (UserNotFound e) {
            throw e;
        } catch (Exception e) {
            m_log.warn("modifyUserPassword() failure to modify user's password. (userId = " + userId + ")", e);
            throw new HinemosUnknown(e.getMessage(), e);
        }

        m_log.info("successful in modifing a user's password. (userId = " + userId + ")");
    }
}

From source file:com.controller.CPMEndOfDay.java

public static void getEODData() throws InterruptedException, IOException, JSONException {
    System.out.println("EOD DATA THREAD RUNNING.");
    try {//from w ww.  jav  a  2  s.  c  o m
        String currUsername = CMAIN.reportUser().getUsername();
        HttpResponse<JsonNode> resp;

        ArrayList<SingleOrder> boughtOrders = new ArrayList<>();
        ArrayList<SingleOrder> soldOrders = new ArrayList<>();

        String currentTime = new SimpleDateFormat("HH:mm").format(new Date());
        String timeToCompare = "16:30";
        int x = currentTime.compareTo(timeToCompare);

        //INIT CLIENT
        CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
        client.start();

        //REQUEST
        HttpGet request;

        if (x >= 0) {
            request = new HttpGet("http://139.59.17.119:8080/api/pm/eod/" + currUsername + "/0");
        } else {
            request = new HttpGet("http://139.59.17.119:8080/api/pm/eod/" + currUsername + "/1");
        }

        //GET AND PARSE RESPONSE
        Future<org.apache.http.HttpResponse> future = client.execute(request, null);
        org.apache.http.HttpResponse response = future.get();
        String json_string = EntityUtils.toString(response.getEntity());
        JSONArray arrJson = new JSONArray(json_string);

        //GET ORDERS FROM ARRAY
        ArrayList<SingleOrder> arrayOrders = new ArrayList<>();

        for (int i = 0; i < arrJson.length(); i++) {
            JSONObject currentOrder = arrJson.getJSONObject(i);
            SingleOrder currentSingleOrder = JsonParsing.parseJsonToSingleOrderObject(currentOrder.toString());

            //DO THE DATE PART
            if (currentSingleOrder.getStatus().equals("Executed")) {
                // System.out.println("# executed by :" + currUsername);
                arrayOrders.add(currentSingleOrder);
            }
        }

        for (SingleOrder o : arrayOrders) {
            if (o.getAction().equals("Sell")) {
                soldOrders.add(o);
            } else if (o.getAction().equals("Buy")) {
                boughtOrders.add(o);
            }
        }

        setBought(boughtOrders);
        setSold(soldOrders);

        //DONT FORGET TO KILL CLIENT
        try {
            client.close();
        } catch (IOException ex) {
            Logger.getLogger(CPMOrderMANIAC.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (ExecutionException ex) {
        Logger.getLogger(CPMEndOfDay.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.ibm.iotf.connector.Connector.java

public static MessageHubEnvironment parseProducerProps() {
    MessageHubEnvironment env = parseEnv("messagehub", MessageHubEnvironment.class);

    if (env != null) {
        String topic = System.getenv("MH_EVENT_TOPIC");

        if (topic != null) {
            env.setTargetTopic(topic);/*from w  ww .j a v  a2  s. c  o m*/
            logger.log(Level.INFO, "Target Message Hub Topic: " + topic);

            String autoCreateTopic = System.getenv("MH_AUTO_CREATE_TOPIC");

            if (autoCreateTopic != null && autoCreateTopic.compareTo("1") == 0) {

                String partitionStr = System.getenv("MH_TOPIC_PARTITIONS");
                // default to 1 partition
                int partitionCount = 1;
                try {
                    partitionCount = partitionStr != null ? Integer.parseInt(partitionStr) : 1;
                } catch (NumberFormatException e) {
                    logger.log(Level.WARN, "MH_TOPIC_PARTITIONS not valid.  must be a number", e);
                }

                RESTRequest restApi = new RESTRequest(env.getCredentials().getKafkaRestUrl(),
                        env.getCredentials().getApiKey());

                String res = restApi.post("admin/topics",
                        new CreateTopicParameters(topic, partitionCount).toString(), new int[] { 422 });
                logger.log(Level.INFO, "Topic create POST cmd response: " + res);
            }
        } else {
            logger.log(Level.FATAL,
                    "No target Message Hub topic specified.  Please create a topic and set the 'MH_EVENT_TOPIC' app env var with the name.");
            return null;
        }
    }

    return env;
}

From source file:com.panet.imeta.core.vfs.KettleVFS.java

public static Comparator<FileObject> getComparator() {
    return new Comparator<FileObject>() {
        public int compare(FileObject o1, FileObject o2) {
            String filename1 = getFilename(o1);
            String filename2 = getFilename(o2);
            return filename1.compareTo(filename2);
        }/*from w  ww .  j  a  va2  s  .com*/
    };
}

From source file:com.thruzero.common.core.utils.StringUtilsExt.java

/** Compare two strings, where null string is treated as "". */
public static int compare(final String str1, final String str2) {
    String s1 = (str1 == null ? StringUtils.EMPTY : str1);
    String s2 = (str2 == null ? StringUtils.EMPTY : str2);

    return s1.compareTo(s2);
}

From source file:com.igormaznitsa.jute.Utils.java

public static List<TestContainer> sortDetectedClassMethodsForNameAndOrder(
        final List<TestContainer> testMethods) {
    Collections.sort(testMethods, new Comparator<TestContainer>() {
        @Override//from  w w  w  .  ja v a  2  s . c o  m
        public int compare(final TestContainer o1, final TestContainer o2) {
            final int order1 = o1.getOrder() < 0 ? -1 : o1.getOrder();
            final int order2 = o2.getOrder() < 0 ? -1 : o2.getOrder();

            final String name1 = o1.getMethodName();
            final String name2 = o2.getMethodName();

            final int result;
            if (order1 == order2) {
                result = name1.compareTo(name2);
            } else {
                result = Integer.compare(order1, order2);
            }
            return result;
        }
    });
    return testMethods;
}

From source file:com.hangum.tadpole.commons.util.IPUtil.java

/**
 * ip sort/*from  w  w w .  jav a2s  .  c  o m*/
 * 
 * @param ipList
 * @return
 */
public static List<String> ipSort(List<String> ipList) {

    Collections.sort(ipList, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            String[] ips1 = o1.split("\\.");
            String updatedIp1 = String.format("%3s.%3s.%3s.%3s", ips1[0], ips1[1], ips1[2], ips1[3]);
            String[] ips2 = o2.split("\\.");
            String updatedIp2 = String.format("%3s.%3s.%3s.%3s", ips2[0], ips2[1], ips2[2], ips2[3]);
            return updatedIp1.compareTo(updatedIp2);
        }
    });

    return ipList;
}