List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:net.sourceforge.doddle_owl.data.JpnWordNetDic.java
public static String getRelationData(String id) { long low = 0; long relationIndexFileSize = getRelationIndexFileSize(); long high = relationIndexFileSize; while (low <= high) { long mid = (low + high) / 2; if (relationIndexFileSize - 1 <= mid) { return null; }/*from w w w . j ava 2 s . c o m*/ long relationDataFP = getRelationDataFp(mid * 10); if (relationDataFP == -1) { return null; } String relationData = getRelationData(relationDataFP); if (relationData == null) { return null; } String[] lines = relationData.split("\t"); String searchedID = lines[0]; // System.out.println(searchedID.compareTo(id)); if (searchedID.compareTo(id) == 0) { // System.out.println(conceptData); return relationData; } else if (0 < searchedID.compareTo(id)) { high = mid - 1; } else { low = mid + 1; } } return null; }
From source file:net.sourceforge.doddle_owl.data.JpnWordNetDic.java
private static Set<Long> getdataFpSet(long high, String term) { long low = 0; Set<Long> dataFpSet = new HashSet<Long>(); while (low <= high) { long mid = (low + high) / 2; // System.out.println("mid: " + mid); long indexFP = getIndexFp(mid * 10); if (indexFP == -1) { return dataFpSet; }//w w w . j a v a 2 s. com String line = getTermAndIndexFpSet(indexFP); String[] lines = line.split("\t"); String searchedTerm = lines[0]; // System.out.println(searchedTerm.compareTo(term)); if (searchedTerm.compareTo(term) == 0) { for (int i = 1; i < lines.length; i++) { dataFpSet.add(Long.valueOf(lines[i])); } // System.out.println(searchedTerm); return dataFpSet; } else if (0 < searchedTerm.compareTo(term)) { high = mid - 1; } else { low = mid + 1; } } return dataFpSet; }
From source file:com.google.dart.engine.services.correction.MembersSorter.java
private static List<MemberInfo> getSortedMembers(List<MemberInfo> members) { List<MemberInfo> membersSorted = Lists.newArrayList(members); Collections.sort(membersSorted, new Comparator<MemberInfo>() { @Override/* www. j a v a2s . c o m*/ public int compare(MemberInfo o1, MemberInfo o2) { int priority1 = getPriority(o1.item); int priority2 = getPriority(o2.item); if (priority1 == priority2) { // don't reorder class fields if (o1.item.kind == MemberKind.CLASS_FIELD) { return 0; } // sort all other members by name String name1 = o1.name.toLowerCase(); String name2 = o2.name.toLowerCase(); return name1.compareTo(name2); } return priority1 - priority2; } }); return membersSorted; }
From source file:org.apache.falcon.regression.core.util.Util.java
/** * Finds first folder within a date range. * @param startTime start date/* w w w. j a v a2 s . c o m*/ * @param endTime end date * @param folderList list of folders which are under analysis * @return first matching folder or null if not present in a list */ public static String findFolderBetweenGivenTimeStamps(DateTime startTime, DateTime endTime, List<String> folderList) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd/HH/mm"); for (String folder : folderList) { if (folder.compareTo(formatter.print(startTime)) >= 0 && folder.compareTo(formatter.print(endTime)) <= 0) { return folder; } } return null; }
From source file:knowledgeMiner.mining.SentenceParserHeuristic.java
/** * Locates the anchors in a string and forms a replacement map for them. * /*w ww.ja v a2 s . co m*/ * @param sentence * The sentence to search for anchors. * @param anchorWeights * An optional map to record any weight information for the * anchors. If no weights in the text, all weights are assumed to * be 1.0. * @return A SortedMap of anchors, ordered in largest text size to smallest. */ public static SortedMap<String, String> locateAnchors(String sentence, Map<String, Double> anchorWeights) { SortedMap<String, String> anchorMap = new TreeMap<>(new Comparator<String>() { @Override public int compare(String o1, String o2) { int result = Double.compare(o1.length(), o2.length()); if (result != 0) return -result; return o1.compareTo(o2); } }); Matcher m = WikiParser.ANCHOR_PARSER.matcher(sentence); while (m.find()) { String replString = (m.group(2) != null) ? m.group(2) : m.group(1); anchorMap.put(replString, m.group()); } return anchorMap; }
From source file:com.sldeditor.test.unit.tool.ysld.YSLDToolTest.java
/** * Gets the SLD/YSLD file.//from w w w. j a va2s . co m * * @param testfile the testfile * @return the SLD data file */ private static SLDData getSLDDataFile(String testfile) { SLDData sldData = null; InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile); if (inputStream == null) { Assert.assertNotNull("Failed to find test file : " + testfile, inputStream); } else { File f = null; try { String fileExtension = ExternalFilenames.getFileExtension(testfile); f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension)); String sldContents = readFile(f.getAbsolutePath()); if (fileExtension.compareTo("ysld") == 0) { StyledLayerDescriptor sld = Ysld.parse(sldContents); // Convert YSLD to SLD string SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD); sldContents = sldWriter.encodeSLD(sld); } sldData = new SLDData(new StyleWrapper(f.getName()), sldContents); sldData.setSLDFile(f); SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData)); f.deleteOnExit(); } catch (IOException e1) { e1.printStackTrace(); } } return sldData; }
From source file:OAUTHnesia.java
private static String sendRequest(String url, String postString) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); if (postString.compareTo("") != 0) { // GET & POST Request HttpPost post = new HttpPost(url); // Create POST List List<NameValuePair> pairs = new ArrayList<NameValuePair>(); String[] exp = postString.split("&"); int max = exp.length; for (int i = 0; i < max; i++) { String[] kv = exp[i].split("="); pairs.add(new BasicNameValuePair(kv[0], kv[1])); }// w w w . ja va 2s. co m post.setEntity(new UrlEncodedFormEntity(pairs)); // Get HTTP Response & Parse it HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = convertStreamToString(instream); instream.close(); return result; } } else { // GET Request HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = convertStreamToString(instream); instream.close(); return result; } } return ""; }
From source file:com.ebay.erl.mobius.core.model.TupleColumnComparator.java
private static int compare(TreeMap<String, String> m1, TreeMap<String, String> m2) { int _COMPARE_RESULT = Integer.MAX_VALUE; int m1_size = m1.size(); int m2_size = m2.size(); if (m1_size == 0 || m2_size == 0) { if (m1_size == m2_size) return 0; else if (m1_size != 0) return 1; else/*w w w .ja v a2 s .com*/ return -1; } Iterator<String> k1_it = m1.keySet().iterator(); Iterator<String> k2_it = m2.keySet().iterator(); boolean hasDiff = false; while (k1_it.hasNext()) { String k1 = k1_it.next(); if (k2_it.hasNext()) { String k2 = k2_it.next(); _COMPARE_RESULT = String.CASE_INSENSITIVE_ORDER.compare(k1, k2); if (_COMPARE_RESULT == 0) { // same key, check their value String v1 = m1.get(k1); String v2 = m2.get(k2); _COMPARE_RESULT = v1.compareTo(v2); } } else { // m1 has more keys than m2 and m1 has the same // values for all the keys in m2 _COMPARE_RESULT = 1; } if (_COMPARE_RESULT != 0 && _COMPARE_RESULT != Integer.MAX_VALUE) { hasDiff = true; break;// has result } } if (!hasDiff) { if (k2_it.hasNext()) { // m2 has more keys than m1, and m2 has the same // values for all the keys in m1 _COMPARE_RESULT = -1; } else { // m1 and m2 are the same } } return _COMPARE_RESULT; }
From source file:fr.openwide.core.spring.util.StringUtils.java
/** * Compare deux chanes potentiellement nulles. * @param string1 la premire chane/*from w w w. j av a 2s .c o m*/ * @param string2 la seconde chane * @return rsultat de la comparaison */ public static int compare(String string1, String string2) { if (string1 == null) { if (string2 == null) { return 0; } else { return -1; } } if (string2 == null) { return 1; } return string1.compareTo(string2); }
From source file:com.bstek.dorado.core.pkgs.PackageManager.java
private static int compareVersionSection(String section1, String section2) { if (StringUtils.isNumeric(section1) && StringUtils.isNumeric(section2)) { return Integer.valueOf(section1) - Integer.valueOf(section2); } else {//ww w . j a v a2s. c o m return section1.compareTo(section2); } }