Coverage Report - org.kuali.rice.kns.util.KNSUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
KNSUtils
0%
0/36
0%
0/16
3.333
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Miscellaneous Utility Methods.
 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  
      * Picks off the filename from the full path. Takes care of different OS seperators.
 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  
      * Convert the given monney amount into an interger string. Since the return string cannot have decimal point, multiplies the
 68  
      * amount by 100 so the decimal places are not lost, for example, 320.15 is converted into 32015. 
 69  
      * 
 70  
      * @return an integer string of the given money amount through multiplicating by 100 and removing the fraction portion.
 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  
 }