From: Eric P. <th...@us...> - 2009-11-19 01:58:09
|
Update of /cvsroot/sandev/sand/apps/basics/src/org/sandev/basics/util In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7399 Modified Files: StringUtil.java Log Message: Added ordinal and isJustNumbers utility methods. Index: StringUtil.java =================================================================== RCS file: /cvsroot/sandev/sand/apps/basics/src/org/sandev/basics/util/StringUtil.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** StringUtil.java 3 Nov 2009 20:56:53 -0000 1.35 --- StringUtil.java 19 Nov 2009 01:57:52 -0000 1.36 *************** *** 182,185 **** --- 182,207 ---- + /** + * Returns the standard ordinal value 1st, 2nd, 3rd etc for the given + * value. + */ + public static String ordinal(int val) + { + switch(val) { + case 11: return "11th"; + case 12: return "12th"; + case 13: return "13th"; + default: { + String valstr="" + val; + if(valstr.endsWith("1")) { + return valstr + "st"; } + if(valstr.endsWith("2")) { + return valstr + "nd"; } + if(valstr.endsWith("3")) { + return valstr + "rd"; } + return valstr + "th"; } } + } + + //////////////////////////////////////// // Long conversion methods. *************** *** 1397,1400 **** --- 1419,1435 ---- /** + * Return true if the given string consists only of numbers, false + * otherwise. + */ + public static boolean isJustNumbers(String str) + { + for(int i=0;i<str.length();i++) { + if(!Character.isDigit(str.charAt(i))) { + return false; } } + return true; + } + + + /** * Wrap the given string so there are no more than maxCharsPerLine * without a terminating newline string. |