Coverage Report - org.kuali.rice.core.web.format.LittleBooleanFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
LittleBooleanFormatter
0%
0/19
0%
0/14
5.333
 
 1  
 /*
 2  
  * Copyright 2006-2008 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.util.Arrays;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.util.RiceKeyConstants;
 22  
 
 23  
 /**
 24  
  * This class is a formatter for little-b boolean classes, that cannot accept a null.
 25  
  */
 26  0
 public class LittleBooleanFormatter extends Formatter {
 27  
 
 28  
     private static final long serialVersionUID = -1800859871401901842L;
 29  
     
 30  0
         static final List<String> TRUE_VALUES = Arrays.asList(new String[] { "yes", "y", "true", "t", "on", "1", "enabled" });
 31  0
     static final List<String> FALSE_VALUES = Arrays.asList(new String[] { "no", "n", "false", "f", "off", "0", "disabled" });
 32  
 
 33  
     protected Object convertToObject(String target) {
 34  0
         if (Formatter.isEmptyValue(target))
 35  0
             return Boolean.FALSE;
 36  
 
 37  0
         String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target;
 38  0
         stringValue = stringValue.trim().toLowerCase();
 39  
 
 40  0
         if (TRUE_VALUES.contains(stringValue))
 41  0
             return Boolean.TRUE;
 42  0
         if (FALSE_VALUES.contains(stringValue))
 43  0
             return Boolean.FALSE;
 44  
 
 45  0
         throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue);
 46  
     }
 47  
 
 48  
     public Object format(Object target) {
 49  0
         if (target == null)
 50  0
             return "No";
 51  0
         if (target instanceof String) {
 52  0
             return target;
 53  
         }
 54  
 
 55  0
         boolean isTrue = ((Boolean) target).booleanValue();
 56  
 
 57  0
         return isTrue ? "Yes" : "No";
 58  
     }
 59  
 
 60  
     protected Object getNullObjectValue() {
 61  0
         return Boolean.FALSE;
 62  
     }
 63  
 
 64  
 }