Coverage Report - org.kuali.rice.core.web.format.LittleBooleanFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
LittleBooleanFormatter
0%
0/16
0%
0/12
4.333
 
 1  
 /**
 2  
  * Copyright 2005-2011 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 org.kuali.rice.core.api.util.RiceKeyConstants;
 19  
 import org.kuali.rice.core.api.util.Truth;
 20  
 
 21  
 /**
 22  
  * This class is a formatter for little-b boolean classes, that cannot accept a null.
 23  
  */
 24  0
 public class LittleBooleanFormatter extends Formatter {
 25  
 
 26  
     private static final long serialVersionUID = -1800859871401901842L;
 27  
 
 28  
     protected Object convertToObject(String target) {
 29  0
         if (Formatter.isEmptyValue(target))
 30  0
             return Boolean.FALSE;
 31  
 
 32  0
         String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target;
 33  0
         stringValue = stringValue.trim().toLowerCase();
 34  
 
 35  0
         Boolean b = Truth.strToBooleanIgnoreCase(stringValue);
 36  0
         if (b == null) {
 37  0
             throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue);
 38  
         }
 39  0
         return b;
 40  
     }
 41  
 
 42  
     public Object format(Object target) {
 43  0
         if (target == null)
 44  0
             return "No";
 45  0
         if (target instanceof String) {
 46  0
             return target;
 47  
         }
 48  
 
 49  0
         boolean isTrue = ((Boolean) target).booleanValue();
 50  
 
 51  0
         return isTrue ? "Yes" : "No";
 52  
     }
 53  
 
 54  
     protected Object getNullObjectValue() {
 55  0
         return Boolean.FALSE;
 56  
     }
 57  
 
 58  
 }