Coverage Report - org.kuali.rice.core.web.format.KualiIntegerCurrencyFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiIntegerCurrencyFormatter
0%
0/15
0%
0/4
4.5
 
 1  
 /*
 2  
  * Copyright 2006-2007 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.core.web.format;
 17  
 
 18  
 import java.text.NumberFormat;
 19  
 
 20  
 import org.kuali.rice.core.util.RiceKeyConstants;
 21  
 import org.kuali.rice.core.util.type.KualiDecimal;
 22  
 import org.kuali.rice.core.util.type.KualiInteger;
 23  
 
 24  0
 public class KualiIntegerCurrencyFormatter extends CurrencyFormatter {
 25  
 
 26  
     private static final long serialVersionUID = 1022217841658237940L;
 27  
 
 28  
         protected Object convertToObject(String target) {
 29  0
         KualiDecimal value = (KualiDecimal) (super.convertToObject(target));
 30  0
         return new KualiInteger(value.longValue());
 31  
     }
 32  
 
 33  
     /**
 34  
      * Returns a string representation of its argument formatted as a currency value.
 35  
      */
 36  
     public Object format(Object obj) {
 37  0
         if (obj == null)
 38  0
             return null;
 39  
 
 40  0
         NumberFormat formatter = NumberFormat.getNumberInstance();
 41  0
         String string = null;
 42  
 
 43  
         try {
 44  0
             KualiInteger number = (KualiInteger) obj;
 45  0
             string = formatter.format(number.doubleValue());
 46  
         }
 47  0
         catch (IllegalArgumentException e) {
 48  0
             throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
 49  
         }
 50  0
         catch (ClassCastException e) {
 51  0
             throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
 52  0
         }
 53  
 
 54  0
         return showSymbol() ? string : removeSymbol(string);
 55  
     }
 56  
 }