List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:msuresh.raftdistdb.TestAtomix.java
public static void createCluster(String test, int nodesInCluster) throws InterruptedException, ExecutionException { InitPortNumber();//from w ww . ja va 2s .co m try { List<Address> members = new ArrayList<>(); for (int i = 0; i < nodesInCluster; i++) { Address addr = new Address("localhost", portId++); members.add(addr); } CompletableFuture<Integer> future = new CompletableFuture<>(); Map atomixList; atomixList = new HashMap(); for (Address a : members) { ServerSetup s = new ServerSetup(members, a, atomixList, future); s.start(); } future.get(); UpdatePortNumber(); if (test.compareTo("leaderFailure") == 0) { for (Object s : atomixList.keySet()) { LeaderReelection l = new LeaderReelection((Address) s, (CopycatServer) atomixList.get(s), true); l.start(); } Thread.sleep(20000); // for(Object s : atomixList.keySet()){ // CopycatServer cs = (CopycatServer)atomixList.get(s); // while(cs.isOpen()) // Thread.sleep(1000); // System.out.println("printing" + cs.toString()); // } System.out.println( "Leader Reelection test is done. Program might not close properly due to a bug in Atomix. Follow manual instructions to close the process and sockets."); } else if (test.compareTo("replicationTest") == 0) { CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build(); client.open().join(); System.out.println("Adding a testkey with testval to the cluster .."); client.submit(new PutCommand("testkey1", "testval")).get(); List<LeaderReelection> reelectionList = new ArrayList<>(); System.out.println("Crashing leader to trigger a reelection .. "); for (Object s : atomixList.keySet()) { LeaderReelection l = new LeaderReelection((Address) s, (CopycatServer) atomixList.get(s), false); l.start(); reelectionList.add(l); } // for(LeaderReelection l : reelectionList){ // l.future.get(); // // } // client = CopycatClient.builder(members) // .withTransport(new NettyTransport()) // .build(); // client.open().join(); System.out.println(" Polling the cluster for testkey .."); Object str = client.submit(new GetQuery("testkey1")).get(); System.out.println("The cluster returned (which should be 'testval'):" + (String) str); System.out.println("closing open servers.."); for (Object s : atomixList.keySet()) { CopycatServer cs = (CopycatServer) atomixList.get(s); if (cs.isOpen()) cs.close(); } } } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:org.opendatakit.common.android.data.ColumnDefinition.java
/** * Binary search using elementKey. The ColumnDefinition list returned by * ColumnDefinition.buildColumnDefinitions() is ordered. This function makes * use of that property to quickly retrieve the definition for an elementKey. * // www . j av a 2 s . com * @param orderedDefns * @param elementKey * @return * @throws IllegalArgumentException - if elementKey not found */ static ColumnDefinition find(ArrayList<ColumnDefinition> orderedDefns, String elementKey) throws IllegalArgumentException { if (elementKey == null) { throw new NullPointerException("elementKey cannot be null in ColumnDefinition::find()"); } int iLow = 0; int iHigh = orderedDefns.size(); int iGuess = (iLow + iHigh) / 2; while (iLow != iHigh) { ColumnDefinition cd = orderedDefns.get(iGuess); int cmp = elementKey.compareTo(cd.getElementKey()); if (cmp == 0) { return cd; } if (cmp < 0) { iHigh = iGuess; } else { iLow = iGuess + 1; } iGuess = (iLow + iHigh) / 2; } if (iLow >= orderedDefns.size()) { throw new IllegalArgumentException("could not find elementKey in columns list: " + elementKey); } ColumnDefinition cd = orderedDefns.get(iGuess); if (cd.getElementKey().equals(elementKey)) { return cd; } throw new IllegalArgumentException("could not find elementKey in columns list: " + elementKey); }
From source file:Main.java
public int compare(String first, String second) { return second.compareTo(first); }
From source file:com.jsfsample.util.StringUtil.java
/** * Convert current academic year. ex. 0910 => 2009-2010 * //from ww w. java 2 s .c om * @param academicYr * @return */ public static String formatAcademicYear(String academicYr) { String rtnValue = null; String century1 = null; String century2 = null; if (!StringUtil.isEmpty(academicYr) && academicYr.trim().length() == 4) { if (academicYr.compareTo("9091") >= 0) { century1 = "19"; if ("9900".equals(academicYr)) { century2 = "19"; } else { century2 = "19"; } } else { century1 = "20"; century2 = "20"; } rtnValue = century1 + academicYr.substring(0, 2) + "-" + century2 + academicYr.substring(2); } return rtnValue; }
From source file:com.example.android.cardreader.MainActivity.java
public static void refreshLists() { System.out.println("newPend. refreshing lists..."); try {//from w w w .ja va 2 s.c o m for (PersonListFrag f : frags) { f.mAdapter.notifyDataSetChanged(); } Collections.sort(Globals.pending, new Comparator<User>() { @Override public int compare(User lhs, User rhs) { String a = lhs.name; String b = rhs.name; return a.compareTo(b); } }); Collections.sort(Globals.checkedIn, new Comparator<User>() { @Override public int compare(User lhs, User rhs) { String a = lhs.name; String b = rhs.name; return a.compareTo(b); } }); Collections.sort(Globals.allUsers, new Comparator<User>() { @Override public int compare(User lhs, User rhs) { String a = lhs.name; String b = rhs.name; return a.compareTo(b); } }); System.out.println("newPend. finished refreshing"); } catch (Exception e) { e.printStackTrace(); } }
From source file:asterix.parser.classad.test.ClassAdUnitTester.java
/********************************************************************* * Function: test_classad/* w ww. ja v a 2s.co m*/ * Purpose: Test the ClassAd class. * * @throws IOException *********************************************************************/ public static void testClassad(Parameters parameters, Results results) throws IOException { ClassAdParser parser = new ClassAdParser(); boolean haveAttribute; boolean success; System.out.println("Testing the ClassAd class..."); String input_basic = "[ A = 3; B = 4.0; C = \"babyzilla\"; D = true; E = {1}; F = [ AA = 3; ]; G =\"deleteme\";]"; ClassAd basic = new ClassAd(); AMutableInt64 i = new AMutableInt64(0); MutableBoolean b = new MutableBoolean(); AMutableDouble r = new AMutableDouble(0); AMutableCharArrayString s = new AMutableCharArrayString(); ClassAd c = new ClassAd(); //ExprList *l; basic = parser.parseClassAd(input_basic); /* ----- Test EvaluateAttr* ----- */ haveAttribute = basic.evaluateAttrInt("A", i); test("Have attribute A", (haveAttribute == true), "test_classad 1", results); test("A is 3", (i.getLongValue() == 3), "test_classad 2", results); haveAttribute = basic.evaluateAttrReal("B", r); test("Have attribute B", (haveAttribute == true), "test_classad 3", results); test("B is 4.0", (r.getDoubleValue() == 4.0), "test_classad 4", results); haveAttribute = basic.evaluateAttrString("C", s); test("Have attribute C", (haveAttribute == true), "test_classad 5", results); test("C is 'babyzilla'", (s.compareTo("babyzilla") == 0), "test_classad 6", results); haveAttribute = basic.evaluateAttrBool("D", b); test("Have attribute D", (haveAttribute == true), "test_classad 7", results); test("D is true", (b.booleanValue() == true), "test_classad 8", results); /* ----- Test basic insert and delete ----- */ success = basic.insertAttr("new", 4); test("InsertAttr claims to have worked", (success == true), "test_classad 9", results); haveAttribute = basic.evaluateAttrInt("new", i); test("Have new attribute", (haveAttribute == true), "test_classad 10", results); test("new attribute is 4", i.getLongValue() == 4, "test_classad 11", results); success = basic.delete("new"); test("Delete claims to have worked", (success == true), "test_classad 12", results); haveAttribute = basic.evaluateAttrInt("new", i); test("New attribute was deleted", (haveAttribute == false), "test_classad 13", results); success = basic.delete("G"); test("DELETE claims to have worked", (success == true), "test_classad 14", results); haveAttribute = basic.evaluateAttrString("G", s); test("Attribute G was deleted", (haveAttribute == false), "test_classad 15", results); basic = null; /* ----- Test GetExternalReferences ----- */ String inputRef = "[ Rank=Member(\"LCG-2_1_0\",other.Environment) ? other.Time/seconds : other.Time/minutes; minutes=60; ]"; TreeSet<String> refs = new TreeSet<String>(); ExprTree rank; c = parser.parseClassAd(inputRef); test("Made classad_ref", (c != null), "Test GetExternalReferences 1", results); if (c != null) { rank = c.lookup("Rank"); test("Rank exists", (rank != null), "Test GetExternalReferences 2", results); if (rank != null) { boolean haveReferences; if ((haveReferences = c.getExternalReferences(rank, refs, true))) { test("have_references", (haveReferences == true), "Test GetExternalReferences 3", results); if (haveReferences) { boolean haveEnvironment; boolean haveTime; boolean haveSeconds; boolean haveOther; haveEnvironment = false; haveTime = false; haveSeconds = false; haveOther = false; for (String entry : refs) { System.out.println(entry); if (entry.compareTo("other.Environment") == 0) { haveEnvironment = true; } else if (entry.compareTo("other.Time") == 0) { haveTime = true; } else if (entry.compareTo("seconds") == 0) { haveSeconds = true; } else { haveOther = true; } } test("Have external reference to Environment", (haveEnvironment == true), "Test GetExternalReferences 4", results); test("Have external reference to Time", (haveTime == true), "Test GetExternalReferences 5", results); test("Have external reference to seconds", (haveSeconds == true), "Test GetExternalReferences 6", results); test("Have no other external references", (haveOther != true), "Test GetExternalReferences 7", results); } } } c = null; } // This ClassAd may cause problems. Perhaps a memory leak. // This test is only useful when run under valgrind. String memoryProblemClassad = "[ Updates = [status = \"request_completed\"; timestamp = absTime(\"2004-12-16T18:10:59-0600]\")] ]"; c = parser.parseClassAd(memoryProblemClassad); /* ----- Test Parsing multiple ClassAds ----- */ String twoClassads = "[ a = 3; ][ b = 4; ]"; ClassAd classad1 = new ClassAd(); ClassAd classad2 = new ClassAd(); AMutableInt32 offset = new AMutableInt32(0); parser.parseClassAd(twoClassads, classad1, offset); test("Have good offset #1", offset.getIntegerValue().intValue() == 10, "Test Parsing multiple ClassAds 1", results); parser.parseClassAd(twoClassads, classad2, offset); test("Have good offset #2", offset.getIntegerValue().intValue() == 20, "Test Parsing multiple ClassAds 2", results); /* ----- Test chained ClassAds ----- */ //classad1 and classad2 from above test are used. ClassAd classad3 = new ClassAd(); classad1.chainToAd(classad2); test("classad1's parent is classad2", classad1.getChainedParentAd().equals(classad2), "Test chained ClassAds 1", results); haveAttribute = classad1.evaluateAttrInt("b", i); test("chain has attribute b from parent", (haveAttribute == true), "Test chained ClassAds 2", results); test("chain attribute b from parent is 4", (i.getLongValue() == 4), "Test chained ClassAds 3", results); haveAttribute = classad1.evaluateAttrInt("a", i); test("chain has attribute a from self", (haveAttribute == true), "Test chained ClassAds 4", results); test("chain attribute a is 3", (i.getLongValue() == 3), "Test chained ClassAds 5", results); // Now we modify classad2 (parent) to contain "a". success = classad2.insertAttr("a", 7); test("insert a into parent", (success == true), "Test chained ClassAds 6", results); haveAttribute = classad1.evaluateAttrInt("a", i); test("chain has attribute a from self (overriding parent)", (haveAttribute == true), "Test chained ClassAds 7", results); test("chain attribute a is 3 (overriding parent)", (i.getLongValue() == 3), "Test chained ClassAds 8", results); haveAttribute = classad2.evaluateAttrInt("a", i); test("chain parent has attribute a", (haveAttribute == true), "Test chained ClassAds 9", results); test("chain parent attribute a is 7", (i.getLongValue() == 7), "Test chained ClassAds 10", results); success = classad3.copyFromChain(classad1); test("copy from chain succeeded", (success == true), "Test chained ClassAds 11", results); haveAttribute = classad3.evaluateAttrInt("b", i); test("copy of chain has attribute b", (haveAttribute == true), "Test chained ClassAds 12", results); test("copy of chain has attribute b==4", (i.getLongValue() == 4), "Test chained ClassAds 13", results); success = classad3.insertAttr("c", 6); test("insert into copy of chain succeeded", (success == true), "Test chained ClassAds 14", results); classad3.copyFromChain(classad1); haveAttribute = classad3.evaluateAttrInt("c", i); test("copy of chain is clean", (haveAttribute == false), "Test chained ClassAds 15", results); classad3.insertAttr("c", 6); success = classad3.updateFromChain(classad1); test("update from chain succeeded", (success == true), "Test chained ClassAds 16", results); haveAttribute = classad3.evaluateAttrInt("c", i); test("update from chain is merged", (haveAttribute == true), "Test chained ClassAds 17", results); test("update from chain has attribute c==6", (i.getLongValue() == 6), "Test chained ClassAds 18", results); }
From source file:davmail.DavGateway.java
/** * Start DavMail listeners.//from w ww .ja v a2 s . co m */ public static void start() { // register custom SSL Socket factory DavGatewaySSLProtocolSocketFactory.register(); // prepare HTTP connection pool DavGatewayHttpClientFacade.start(); SERVER_LIST.clear(); int smtpPort = Settings.getIntProperty("davmail.smtpPort"); if (smtpPort != 0) { SERVER_LIST.add(new SmtpServer(smtpPort)); } int popPort = Settings.getIntProperty("davmail.popPort"); if (popPort != 0) { SERVER_LIST.add(new PopServer(popPort)); } int imapPort = Settings.getIntProperty("davmail.imapPort"); if (imapPort != 0) { SERVER_LIST.add(new ImapServer(imapPort)); } int caldavPort = Settings.getIntProperty("davmail.caldavPort"); if (caldavPort != 0) { SERVER_LIST.add(new CaldavServer(caldavPort)); } int ldapPort = Settings.getIntProperty("davmail.ldapPort"); if (ldapPort != 0) { SERVER_LIST.add(new LdapServer(ldapPort)); } BundleMessage.BundleMessageList messages = new BundleMessage.BundleMessageList(); BundleMessage.BundleMessageList errorMessages = new BundleMessage.BundleMessageList(); for (AbstractServer server : SERVER_LIST) { try { server.bind(); server.start(); messages.add(new BundleMessage("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort())); } catch (DavMailException e) { errorMessages.add(e.getBundleMessage()); } catch (IOException e) { errorMessages.add( new BundleMessage("LOG_SOCKET_BIND_FAILED", server.getProtocolName(), server.getPort())); } } final String currentVersion = getCurrentVersion(); boolean showStartupBanner = Settings.getBooleanProperty("davmail.showStartupBanner", true); if (showStartupBanner) { DavGatewayTray.info(new BundleMessage("LOG_DAVMAIL_GATEWAY_LISTENING", currentVersion == null ? "" : currentVersion, messages)); } if (!errorMessages.isEmpty()) { DavGatewayTray.error(new BundleMessage("LOG_MESSAGE", errorMessages)); } // check for new version in a separate thread new Thread("CheckRelease") { @Override public void run() { String releasedVersion = getReleasedVersion(); if (currentVersion != null && currentVersion.length() > 0 && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) { DavGatewayTray.info(new BundleMessage("LOG_NEW_VERSION_AVAILABLE", releasedVersion)); } } }.start(); }
From source file:com.albert.util.StringUtilCommon.java
/** * i.e //w w w .j a va 2 s . com * academicYr = 1112, offsetYears = 1 => return 1213 * academicYr = 1112, offsetYears = -4 => return 0708 * academicYr = "", offsetYears = 1 => return "" * academicYr = null, offsetYears = 1 => return "" * * @param academicYr * @param offsetYears * @return */ public static String calcAcademicYear(String academicYr, int offsetYears) { String rtnValue = null; String century1 = null; String century2 = null; if (StringUtilCommon.isEmpty(academicYr)) return ""; if (!StringUtilCommon.isEmpty(academicYr) && academicYr.trim().length() == 4) { if (academicYr.compareTo("9091") >= 0) { century1 = "19"; if ("9900".equals(academicYr)) { century2 = "19"; } else { century2 = "19"; } } else { century1 = "20"; century2 = "20"; } String year1 = century1 + academicYr.substring(0, 2); String year2 = century2 + academicYr.substring(2); SimpleDateFormat df1 = new SimpleDateFormat("yyyy"); SimpleDateFormat df2 = new SimpleDateFormat("yy"); try { rtnValue = df2.format(DateUtilCommon.addYear(df1.parse(year1), offsetYears)) + df2.format(DateUtilCommon.addYear(df1.parse(year2), offsetYears)); return rtnValue; } catch (ParseException e) { //should never happen throw new RuntimeException(e); } } return ""; }
From source file:Main.java
public int compare(String path1, String path2) { String[] dirs1 = path1.split("/"); String[] dirs2 = path2.split("/"); if (dirs1.length < dirs2.length) { return -1; } else if (dirs1.length > dirs2.length) { return 1; } else {//from w w w.j a v a 2s .c o m String lastDir1 = dirs1[dirs1.length - 1]; String lastDir2 = dirs2[dirs2.length - 1]; return lastDir1.compareTo(lastDir2); } }
From source file:MainClass.java
protected int sortedIndexOf(TableColumn tc) { int stop = getColumnCount(); String name = tc.getHeaderValue().toString(); for (int i = 0; i < stop; i++) { if (name.compareTo(getColumn(i).getHeaderValue().toString()) <= 0) { return i; }/*from w ww . j a v a 2s .c om*/ } return stop; }