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.xorcode.andtweet.net.Connection.java

/**
 * Set User's password if the Connection object needs it
 *//*from   w  ww .  j ava  2  s . co m*/
public void setPassword(SharedPreferences sp, String password) {
    if (password == null) {
        password = "";
    }
    if (password.compareTo(mPassword) != 0) {
        mPassword = password;
        sp.edit().putString(MyPreferences.KEY_TWITTER_PASSWORD, mPassword).commit();
    }
}

From source file:org.andstatus.app.net.HttpConnectionBasic.java

/**
 * Set User's password if the Connection object needs it
 *///from   w w w .j  a v  a2 s . com
@Override
public void setPassword(String passwordIn) {
    String password = passwordIn;
    if (password == null) {
        password = "";
    }
    if (password.compareTo(mPassword) != 0) {
        mPassword = password;
    }
}

From source file:com.trellmor.berrytube.BerryTubeIOCallback.java

/**
 * @see io.socket.IOCallback#on(java.lang.String, io.socket.IOAcknowledge,
 *      java.lang.Object[])//  w ww.j av  a2  s.c  o  m
 */
public void on(String event, IOAcknowledge ack, Object... args) {
    if (event.compareTo("chatMsg") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject jsonMsg = (JSONObject) args[0];

            try {
                berryTube.getHandler()
                        .post(berryTube.new ChatMsgTask(new ChatMessage(jsonMsg.getJSONObject("msg"))));
            } catch (JSONException e) {
                Log.e(TAG, "chatMsg", e);
            }
        } else
            Log.w(TAG, "chatMsg message is not a JSONObject");
    } else if (event.compareTo("setNick") == 0) {
        if (args.length >= 1 && args[0] instanceof String) {
            berryTube.getHandler().post(berryTube.new SetNickTask((String) args[0]));
        } else
            Log.w(TAG, "setNick message is not a String");
    } else if (event.compareTo("loginError") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject error = (JSONObject) args[0];
            berryTube.getHandler()
                    .post(berryTube.new LoginErrorTask(error.optString("message", "Login failed")));
        }
    } else if (event.compareTo("userJoin") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject user = (JSONObject) args[0];
            try {
                berryTube.getHandler().post(berryTube.new UserJoinPartTask(new ChatUser(user),
                        BerryTube.UserJoinPartTask.ACTION_JOIN));
            } catch (JSONException e) {
                Log.e(TAG, "userJoin", e);
            }
        } else
            Log.w(TAG, "userJoin message is not a JSONObject");
    } else if (event.compareTo("newChatList") == 0) {
        berryTube.getHandler().post(berryTube.new UserResetTask());
        if (args.length >= 1 && args[0] instanceof JSONArray) {
            JSONArray users = (JSONArray) args[0];
            for (int i = 0; i < users.length(); i++) {
                JSONObject user = users.optJSONObject(i);
                if (user != null) {
                    try {
                        berryTube.getHandler().post(berryTube.new UserJoinPartTask(new ChatUser(user),
                                BerryTube.UserJoinPartTask.ACTION_JOIN));
                    } catch (JSONException e) {
                        Log.e(TAG, "newChatList", e);
                    }
                }
            }
        } else
            Log.w(TAG, "newChatList message is not a JSONArray");
    } else if (event.compareTo("userPart") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject user = (JSONObject) args[0];
            try {
                berryTube.getHandler().post(berryTube.new UserJoinPartTask(new ChatUser(user),
                        BerryTube.UserJoinPartTask.ACTION_PART));
            } catch (JSONException e) {
                Log.e(TAG, "userPart", e);
            }
        } else
            Log.w(TAG, "userPart message is not a JSONObject");
    } else if (event.compareTo("drinkCount") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject drinks = (JSONObject) args[0];
            berryTube.getHandler().post(berryTube.new DrinkCountTask(drinks.optInt("drinks")));
        }
    } else if (event.compareTo("kicked") == 0) {
        berryTube.getHandler().post(berryTube.new KickedTask());
    } else if (event.compareTo("newPoll") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject poll = (JSONObject) args[0];
            ChatMessage msg;

            // Send chat message for new poll
            try {
                msg = new ChatMessage(poll.getString("creator"), poll.getString("title"),
                        ChatMessage.EMOTE_POLL, 0, 0, false, 1);
                berryTube.getHandler().post(berryTube.new ChatMsgTask(msg));
            } catch (JSONException e) {
                Log.e(TAG, "newPoll", e);
            }

            // Create new poll
            try {
                berryTube.getHandler().post(berryTube.new NewPollTask(new Poll(poll)));
            } catch (JSONException e) {
                Log.e(TAG, "newPoll", e);
            }
        }
    } else if (event.compareTo("updatePoll") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject poll = (JSONObject) args[0];
            try {
                JSONArray votes = poll.getJSONArray("votes");
                int[] voteArray = new int[votes.length()];
                for (int i = 0; i < votes.length(); i++) {
                    voteArray[i] = votes.optInt(i, -1);
                }
                berryTube.getHandler().post(berryTube.new UpdatePollTask(voteArray));
            } catch (JSONException e) {
                Log.e(TAG, "updatePoll", e);
            }
        }
    } else if (event.compareTo("clearPoll") == 0) {
        berryTube.getHandler().post(berryTube.new ClearPollTask());
    } else if (event.compareTo("forceVideoChange") == 0 || event.compareTo("hbVideoDetail") == 0) {
        if (args.length >= 1 && args[0] instanceof JSONObject) {
            JSONObject videoMsg = (JSONObject) args[0];
            try {
                JSONObject video = videoMsg.getJSONObject("video");
                String name = URLDecoder.decode(video.getString("videotitle"), "UTF-8");
                String id = video.getString("videoid");
                String type = video.getString("videotype");
                berryTube.getHandler().post(berryTube.new NewVideoTask(name, id, type));
            } catch (JSONException | UnsupportedEncodingException e) {
                Log.w(TAG, e);
            }
        }
    }
}

From source file:com.sfs.dao.GadgetPreferencesDAOImplTest.java

/**
 * Test of reorderGadgets method, of class GadgetPreferencesDAOImpl.
 *
 * @throws Exception the exception//from  www .  ja v  a2s .  c om
 */
@Test
public final void testReorderGadgets() throws Exception {
    System.out.println("reorderGadgets");

    GadgetsPreferencesBean gadgetsPreferences = this.gadgetPreferencesDAO.load(testUser.getDN());

    List<Integer> gadgetIdList = (List<Integer>) gadgetsPreferences.getOrderedGadgetIds();

    // Reverse the order of the Gadget IDs
    Collections.reverse(gadgetIdList);

    // Build the orderString
    String expResult = "";
    for (int gadgetId : gadgetIdList) {
        if (expResult.compareTo("") != 0) {
            expResult += ",";
        }
        expResult += String.valueOf(gadgetId);
    }

    GadgetsPreferencesBean reorderedGadgetsPreferences = this.gadgetPreferencesDAO
            .reorderGadgets(gadgetsPreferences, expResult);

    String result = "";

    Collection<Integer> reorderedGadgets = reorderedGadgetsPreferences.getOrderedGadgetIds();
    for (int gadgetId : reorderedGadgets) {
        if (result.compareTo("") != 0) {
            result += ",";
        }
        result += String.valueOf(gadgetId);
    }

    assertEquals(expResult, result);
}

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

public boolean checkTabFormat(File rawFile) {
    try {// w w w  .j a v a2 s . c  o  m
        BufferedReader br = new BufferedReader(new FileReader(rawFile));
        String line = br.readLine();
        int columnsNbr = line.split("\t", -1).length;
        while ((line = br.readLine()) != null) {
            if (line.compareTo("") != 0) {
                if (line.split("\t", -1).length != columnsNbr) {
                    selectRawFilesUI.setMessage("Wrong file format:\nLines have no the same number of columns");
                    selectRawFilesUI.setIsLoading(false);
                    br.close();
                    return false;
                }
            }
        }
        br.close();
    } catch (Exception e) {
        selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage());
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.groupon.odo.controllers.ClientController.java

/**
 * Deletes a specific client id for a profile
 *
 * @param model/*from   w ww . j av  a  2  s.  c o m*/
 * @param profileIdentifier
 * @param clientUUID
 * @return returns the table of the remaining clients or an exception if deletion failed for some reason
 * @throws Exception
 */
@RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.DELETE)
public @ResponseBody HashMap<String, Object> deleteClient(Model model,
        @PathVariable("profileIdentifier") String profileIdentifier,
        @PathVariable("clientUUID") String clientUUID) throws Exception {
    logger.info("Attempting to remove the following client: {}", clientUUID);
    if (clientUUID.compareTo(Constants.PROFILE_CLIENT_DEFAULT_ID) == 0)
        throw new Exception("Default client cannot be deleted");

    Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
    clientService.remove(profileId, clientUUID);

    HashMap<String, Object> valueHash = new HashMap<String, Object>();
    valueHash.put("clients", clientService.findAllClients(profileId));
    return valueHash;
}

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

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

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

    return filteredNames;
}

From source file:io.microprofile.showcase.speaker.persistence.SpeakerDAO.java

/**
 * Get all known Speakers/*from   w  ww  . j a  va 2 s .  com*/
 *
 * @return Set of Speakers
 */
public Collection<Speaker> getSpeakers() {

    final List<Speaker> values = new ArrayList<>(this.speakers.values());

    Collections.sort(values, (s1, s2) -> {

        final String name1 = s1.getNameFirst() + s1.getNameLast();
        final String name2 = s2.getNameFirst() + s2.getNameLast();

        return name1.compareTo(name2);
    });

    return values;
}

From source file:com.iisigroup.cap.base.handler.CheckTimeoutHandler.java

@SuppressWarnings({ "unchecked", "unused" })
public Result checkTO(Request request) throws CapException {
    AjaxFormResult result = new AjaxFormResult();
    HttpServletRequest sreq = (HttpServletRequest) request.getServletRequest();

    String refPath = sreq.getHeader("referer");
    refPath = StringEscapeUtils.unescapeHtml(refPath);
    String path = sreq.getPathInfo();
    boolean isNewSes = sreq.getSession(false).isNew();
    String isFresh = request.get("REFSH_TO", "");

    HttpSession session = sreq.getSession(false);
    Map<String, String> map = (Map<String, String>) session.getAttribute(TOCM);

    String curPage = request.get(CCPAGE_NO);

    if (curPage.lastIndexOf("ap") >= 0) {
        if (map != null && map.containsKey(curPage)) {
            // DO NOT THING
        } else {//from   w w  w  .  jav  a  2  s  .  c  om
            map = new HashMap<String, String>();
            session.setAttribute(TOCM, map);
        }
    }
    if (map == null) {
        map = new HashMap<String, String>();
    }
    if (!CapString.isEmpty(curPage)) {
        if (map.containsKey(curPage) && !"Y".equals(isFresh)) {
            String openTime = map.get(curPage);

            // ??db??
            sysProp.remove(TIME_OUT);
            String stout = sysProp.get(TIME_OUT);
            if (CapString.isEmpty(stout)) {
                stout = "10"; // default 10mins
            }

            // ??
            String lastPageNo = getLastRcordTOMC(map);
            if (lastPageNo.compareTo(curPage) != 0) {
                /*
                 * ??timeout? ???
                 */
                if (map.get(lastPageNo) != null) {
                    long lastOpenTime = Long.parseLong(map.get(lastPageNo));
                    // Calculate difference in milliseconds
                    long curTime = CapDate.getCurrentTimestamp().getTime();
                    long diff = curTime - lastOpenTime;
                    // Difference in seconds
                    long diffSec = diff / 1000;
                    long propTimeout = (Long.parseLong(stout) + 1) * 60;
                    if (diffSec > propTimeout) {
                        map.remove(lastPageNo);
                        session.setAttribute(TOCM, map);
                    }
                }
                // ??????
                return result;
            }

            long time = Long.parseLong(openTime);
            Timestamp ts1 = new Timestamp(time);
            String d12str = CapDate.convertTimestampToString(ts1, "HH:mm:ss.sss");
            long curTime = CapDate.getCurrentTimestamp().getTime();
            long propTimeOut = sreq.getSession(false).getMaxInactiveInterval();
            if (!CapString.isEmpty(stout)) {
                propTimeOut = Long.parseLong(stout);
                long remindTime = (propTimeOut - 1) * 60;
                propTimeOut = propTimeOut * 60;
                // Calculate difference in milliseconds
                long diff = curTime - time;
                // Difference in seconds
                long diffSec = diff / 1000;
                String isContinues = request.get("isCntnu");
                if ("true".equals(isContinues)) {
                    map.put(curPage, String.valueOf(curTime));
                    session.setAttribute(TOCM, map);
                } else if (CapString.isEmpty(isContinues) && diffSec >= remindTime) {
                    result.set("SHOW_REMIND", "true");
                }
                // ?falsetimeout(user??,1??)
                else if ("false".equals(isContinues) || diffSec > propTimeOut) {
                    String webApUrl = sysProp.get("WEB_AP_URL");
                    String st1 = sreq.getScheme();
                    String st2 = sreq.getServerName();
                    int port = sreq.getServerPort();
                    String st4 = sreq.getContextPath();
                    webApUrl = st1 + "://" + st2 + ":" + port + st4;
                    result.set("errorPage", st4 + "/page/timeout");
                    map.remove(curPage);
                    session.setAttribute(TOCM, map);
                }
            }
        } else {
            long curTime = CapDate.getCurrentTimestamp().getTime();
            map.put(curPage, String.valueOf(curTime));
            session.setAttribute(TOCM, map);
        }
    }
    return result;
}

From source file:com.swordlord.common.prefs.UserPrefs.java

public int getLanguageCodeAsInt() {
    String strLang = getLanguageCode();

    if (strLang.compareTo("en") == 0) {
        return 0;
    } else if (strLang.compareTo("de") == 0) {
        return 1;
    }//  ww  w  .j  a va 2s  . c om

    return -1;
}