List of usage examples for java.lang Character compareTo
public int compareTo(Character anotherCharacter)
From source file:Main.java
public static void main(String[] args) { Character c1 = new Character('a'); Character c2 = new Character('b'); int result = c1.compareTo(c2); String str1 = "Equal "; String str2 = "First character is numerically greater"; String str3 = "Second character is numerically greater"; if (result == 0) { System.out.println(str1); } else if (result > 0) { System.out.println(str2); } else if (result < 0) { System.out.println(str3); }/* w ww . java 2s . c om*/ }
From source file:CharacterDemo.java
public static void main(String args[]) { Character a = new Character('a'); Character a2 = new Character('a'); Character b = new Character('b'); int difference = a.compareTo(b); if (difference == 0) { System.out.println("a is equal to b."); } else if (difference < 0) { System.out.println("a is less than b."); } else if (difference > 0) { System.out.println("a is greater than b."); }//from w ww. j ava 2 s . c o m System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal") + " to a2."); System.out.println("The character " + a.toString() + " is " + (Character.isUpperCase(a.charValue()) ? "upper" : "lower") + "case."); }
From source file:MainClass.java
public static void main(String[] args) { Character c1 = new Character('6'); Character c2 = new Character('7'); char c3 = c1.charValue(); char c4 = c2.charValue(); if (c3 < c4) System.out.println(c3 + " is less than " + c4); if (c1.compareTo(c2) < 0) System.out.println(c1 + " is less than " + c4); }
From source file:org.gbif.portal.web.controller.AlphabetBrowserController.java
public static void sortChars(List<Character> listOfChars) { Collections.sort(listOfChars, new Comparator<Character>() { public int compare(Character o1, Character o2) { return o1.compareTo(o2); }/* ww w . j av a 2 s . c om*/ }); }
From source file:com.comcast.cns.util.Util.java
public static boolean isPhoneNumber(String phone) { int size = phone.length(); for (int i = 0; i < size; i++) { Character c = phone.charAt(i); if ((c == '-') || (c == '+') || (c == '.') || (c == '(') || (c == ')')) { //skip } else if ((c.compareTo('0') >= 0) && (c.compareTo('9') <= 0)) { //skip } else {/* www .j a va 2s.c o m*/ return false; } } return true; }
From source file:org.opensilk.common.ui.widget.ColorCodedThumbnail.java
public void init(String title) { Integer color = null;//from w w w . ja v a 2s .c o m if (!TextUtils.isEmpty(title)) { if (title.equals("..")) { setText(title); color = R.color.red; } else { Character c = title.toUpperCase(Locale.US).charAt(0); setText(c.toString()); if (c.compareTo('A') >= 0 && c.compareTo('Z') <= 0) { color = COLORS.get(c); } else if (c.compareTo('0') >= 0 && c.compareTo('9') <= 0) { color = COLORS.get(COLORS.keyAt(Integer.valueOf(c.toString()))); } } } if (color == null) { color = R.color.gray; } ShapeDrawable bg = new ShapeDrawable(new OvalShape()); bg.getPaint().setColor(getResources().getColor(color)); setBackgroundDrawable(bg); }
From source file:org.apache.wiki.util.comparators.HumanComparator.java
public int compare(String str1, String str2) { // Some quick and easy checks if (StringUtils.equals(str1, str2)) { // they're identical, possibly both null return 0; } else if (str1 == null) { // str1 is null and str2 isn't so str1 is smaller return -1; } else if (str2 == null) { // str2 is null and str1 isn't so str1 is bigger return 1; }//w ww .jav a 2 s . c om char[] s1 = str1.toCharArray(); char[] s2 = str2.toCharArray(); int len1 = s1.length; int len2 = s2.length; int idx = 0; // caseComparison used to defer a case sensitive comparison int caseComparison = 0; while (idx < len1 && idx < len2) { char c1 = s1[idx]; char c2 = s2[idx++]; // Convert to lower case char lc1 = Character.toLowerCase(c1); char lc2 = Character.toLowerCase(c2); // If case makes a difference, note the difference the first time // it's encountered if (caseComparison == 0 && c1 != c2 && lc1 == lc2) { if (Character.isLowerCase(c1)) caseComparison = 1; else if (Character.isLowerCase(c2)) caseComparison = -1; } // Do the rest of the tests in lower case c1 = lc1; c2 = lc2; // leading zeros are a special case if (c1 != c2 || c1 == '0') { // They might be different, now we can do a comparison CharType type1 = mapCharTypes(c1); CharType type2 = mapCharTypes(c2); // Do the character class check int result = compareCharTypes(type1, type2); if (result != 0) { // different character classes so that's sufficient return result; } // If they're not digits, use character to character comparison if (type1 != CharType.TYPE_DIGIT) { Character ch1 = Character.valueOf(c1); Character ch2 = Character.valueOf(c2); return ch1.compareTo(ch2); } // The only way to get here is both characters are digits assert (type1 == CharType.TYPE_DIGIT && type2 == CharType.TYPE_DIGIT); result = compareDigits(s1, s2, idx - 1); if (result != 0) { // Got a result so return it return result; } // No result yet, spin through the digits and continue trying while (idx < len1 && idx < len2 && Character.isDigit(s1[idx])) { idx++; } } } if (len1 == len2) { // identical so return any case dependency return caseComparison; } // Shorter String is less return len1 - len2; }
From source file:com.edgenius.wiki.render.handler.PageIndexHandler.java
public void renderStart(AbstractPage page) { if (page != null && page.getSpace() != null) { String spaceUname = page.getSpace().getUnixName(); List<Page> pages = pageService.getPageTree(spaceUname); indexMap = new TreeMap<String, LinkModel>(new Comparator<String>() { public int compare(String o1, String o2) { Character c1 = Character.toUpperCase(o1.charAt(0)); Character c2 = Character.toUpperCase(o2.charAt(0)); if (c1.equals(c2)) { return o1.compareToIgnoreCase(o2); } else { return c1.compareTo(c2); }/*from w w w .j ava 2 s . c o m*/ } }); indexer = new TreeMap<Character, Integer>(new Comparator<Character>() { public int compare(Character o1, Character o2) { return o1.compareTo(o2); } }); Character indexKey = null; int indexAnchor = 1; for (Page pg : pages) { String title = pg.getTitle(); if (StringUtils.isBlank(title)) { log.error("Blank title page found in {}", spaceUname); continue; } LinkModel link = new LinkModel(); link.setLink(title); link.setType(LinkModel.LINK_TO_VIEW_FLAG); link.setSpaceUname(spaceUname); link.setView(title); indexMap.put(title, link); Character first = Character.toUpperCase(title.charAt(0)); if (!first.equals(indexKey)) { indexKey = first; indexer.put(indexKey, indexAnchor++); } } } }
From source file:oscar.oscarDemographic.pageUtil.CihiExportPHC_VRSAction.java
private void buildOngoingproblemsDiseaseRegistry(Demographic demo, PatientRecord patientRecord) { List<Dxresearch> dxResearchList = dxresearchDAO.getDxResearchItemsByPatient(demo.getDemographicNo()); String description;/*from www . jav a 2 s . com*/ String dateFormat = "yyyy-MM-dd"; Date date; Character status; for (Dxresearch dxResearch : dxResearchList) { status = dxResearch.getStatus(); if (status.compareTo('D') == 0) { continue; } ProblemList problemList = patientRecord.addNewProblemList(); StandardCoding standardCoding = problemList.addNewDiagnosisCode(); standardCoding.setStandardCodingSystem(dxResearch.getCodingSystem()); standardCoding.setStandardCode(dxResearch.getDxresearchCode()); if ("icd9".equalsIgnoreCase(dxResearch.getCodingSystem())) { List<Icd9> icd9List = icd9Dao.getIcd9Code(standardCoding.getStandardCode()); if (icd9List != null && icd9List.size() > 0) { description = icd9List.get(0).getDescription(); standardCoding.setStandardCodeDescription(description); } } date = dxResearch.getStartDate(); if (date != null) { this.putPartialDate(problemList.addNewOnsetDate(), date, dateFormat); } if (status.compareTo('C') == 0) { date = dxResearch.getUpdateDate(); if (date != null) { this.putPartialDate(problemList.addNewResolutionDate(), date, dateFormat); } } } }