| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.util; |
| 17 | |
|
| 18 | |
import java.lang.reflect.Constructor; |
| 19 | |
import java.text.NumberFormat; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.List; |
| 22 | |
|
| 23 | |
import org.apache.commons.lang.StringUtils; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | 0 | public class KNSUtils { |
| 29 | |
|
| 30 | |
public final static String getBusinessTitleForClass(Class<? extends Object> clazz) { |
| 31 | 0 | if (clazz == null) { |
| 32 | 0 | throw new IllegalArgumentException("The getBusinessTitleForClass method of KNSUtils requires a non-null class"); |
| 33 | |
} |
| 34 | 0 | String className = clazz.getSimpleName(); |
| 35 | |
|
| 36 | 0 | StringBuffer label = new StringBuffer(className.substring(0, 1)); |
| 37 | 0 | for (int i = 1; i < className.length(); i++) { |
| 38 | 0 | if (Character.isLowerCase(className.charAt(i))) { |
| 39 | 0 | label.append(className.charAt(i)); |
| 40 | |
} else { |
| 41 | 0 | label.append(" ").append(className.charAt(i)); |
| 42 | |
} |
| 43 | |
} |
| 44 | 0 | return label.toString().trim(); |
| 45 | |
} |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public final static List<String> getFileNameFromPath(List<String> fullFileNames) { |
| 51 | 0 | List<String> fileNameList = new ArrayList<String>(); |
| 52 | |
|
| 53 | 0 | for (String fullFileName : fullFileNames) { |
| 54 | 0 | if (StringUtils.contains(fullFileName, "/")) { |
| 55 | 0 | fileNameList.add(StringUtils.substringAfterLast(fullFileName, "/")); |
| 56 | |
} |
| 57 | |
else { |
| 58 | 0 | fileNameList.add(StringUtils.substringAfterLast(fullFileName, "\\")); |
| 59 | |
} |
| 60 | |
} |
| 61 | |
|
| 62 | 0 | return fileNameList; |
| 63 | |
} |
| 64 | |
|
| 65 | 0 | private static final KualiDecimal ONE_HUNDRED = new KualiDecimal("100.00"); |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public final static String convertDecimalIntoInteger(KualiDecimal decimalNumber) { |
| 73 | 0 | KualiDecimal decimalAmount = decimalNumber.multiply(ONE_HUNDRED); |
| 74 | 0 | NumberFormat formatter = NumberFormat.getIntegerInstance(); |
| 75 | 0 | String formattedAmount = formatter.format(decimalAmount); |
| 76 | |
|
| 77 | 0 | return StringUtils.replace(formattedAmount, ",", ""); |
| 78 | |
} |
| 79 | |
|
| 80 | |
public static Integer getIntegerValue(String numberStr){ |
| 81 | 0 | Integer numberInt = null; |
| 82 | |
try{ |
| 83 | 0 | numberInt = new Integer(numberStr); |
| 84 | 0 | } catch(NumberFormatException nfe){ |
| 85 | 0 | Double numberDbl = new Double(numberStr); |
| 86 | 0 | numberInt = new Integer(numberDbl.intValue()); |
| 87 | 0 | } |
| 88 | 0 | return numberInt; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public static Object createObject(Class<?> clazz, Class<?>[] argumentClasses, Object[] argumentValues) { |
| 92 | 0 | if(clazz==null) |
| 93 | 0 | return null; |
| 94 | |
try { |
| 95 | 0 | Constructor<?> constructor = clazz.getConstructor(argumentClasses); |
| 96 | 0 | return constructor.newInstance(argumentValues); |
| 97 | 0 | } catch (Exception e) { |
| 98 | 0 | return null; |
| 99 | |
} |
| 100 | |
} |
| 101 | |
|
| 102 | |
public static String joinWithQuotes(List<String> list){ |
| 103 | 0 | if(list==null || list.size()==0) return ""; |
| 104 | |
|
| 105 | 0 | return KNSConstants.SINGLE_QUOTE+ |
| 106 | |
StringUtils.join(list.iterator(), KNSConstants.SINGLE_QUOTE+","+KNSConstants.SINGLE_QUOTE)+ |
| 107 | |
KNSConstants.SINGLE_QUOTE; |
| 108 | |
} |
| 109 | |
} |