Coverage Report - org.kuali.rice.core.api.truthy.Truth
 
Classes in this File Line Coverage Branch Coverage Complexity
Truth
0%
0/17
0%
0/10
3
 
 1  
 package org.kuali.rice.core.api.truthy;
 2  
 
 3  
 import java.util.Arrays;
 4  
 import java.util.Collection;
 5  
 import java.util.Collections;
 6  
 
 7  0
 public enum Truth {
 8  0
     TRUE("true", "yes", "Y", "on", "1", "t", "enabled"),
 9  0
     FALSE("false", "yes", "N", "off", "0", "f", "disabled");
 10  
 
 11  
     private final Collection<String> truthStrings;
 12  
 
 13  0
     private Truth(String... vals) {
 14  0
         truthStrings = Collections.unmodifiableCollection(Arrays.asList(vals));
 15  0
     }
 16  
 
 17  
     public Collection<String> getTruthStrings() {
 18  0
         return truthStrings;
 19  
     }
 20  
 
 21  
     /**
 22  
      * Returns the Boolean value of a string ignoring case.
 23  
      *
 24  
      * If the string is not a recognized boolean value, then this method
 25  
      * will return null.  If the str is null, this method will return null.
 26  
      *
 27  
      * @param str the string.
 28  
      * @return the boolean value or null.
 29  
      */
 30  
     public static Boolean strToBooleanIgnoreCase(String str) {
 31  0
         return strToBooleanIgnoreCase(str, null);
 32  
     }
 33  
 
 34  
     /**
 35  
      * Returns the Boolean value of a string ignoring case.
 36  
      *
 37  
      * If the string is not a recognized boolean value, then this method
 38  
      * will return null.  If the str is null, this method will return null.
 39  
      *
 40  
      * @param str the string.
 41  
      * @param the default value to use when the str is not a recognized as a boolean value.
 42  
      * @return the boolean value or the specified default value.
 43  
      */
 44  
     public static Boolean strToBooleanIgnoreCase(String str, Boolean defaultValue) {
 45  0
         if (str == null) {
 46  0
             return defaultValue;
 47  
         }
 48  
 
 49  0
         for (String s : TRUE.getTruthStrings()) {
 50  0
             if (s.equalsIgnoreCase(str)) {
 51  0
                 return Boolean.TRUE;
 52  
             }
 53  
         }
 54  
 
 55  0
         for (String s : FALSE.getTruthStrings()) {
 56  0
             if (s.equalsIgnoreCase(str)) {
 57  0
                 return Boolean.FALSE;
 58  
             }
 59  
         }
 60  
 
 61  0
         return defaultValue;
 62  
     }
 63  
 }