Coverage Report - org.seasar.teeda.core.util.TagConvertUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
TagConvertUtil
83%
19/23
70%
7/10
2.6
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.util;
 17  
 
 18  
 import java.util.StringTokenizer;
 19  
 
 20  
 public class TagConvertUtil {
 21  
 
 22  1
     private static final String[] EMPTY_STRING = new String[0];
 23  
 
 24  0
     private TagConvertUtil() {
 25  0
     }
 26  
 
 27  
     public static String[] convertToSetter(String tagName) {
 28  144
         return convertToSetter(tagName, "-");
 29  
     }
 30  
 
 31  
     public static String[] convertToSetter(String tagName, String delim) {
 32  144
         if (tagName == null) {
 33  0
             return EMPTY_STRING;
 34  
         }
 35  
 
 36  144
         if (tagName.indexOf(delim) < 0) {
 37  4
             tagName = capitalizePropertyName(tagName);
 38  4
             return createSetters(tagName);
 39  
         }
 40  
 
 41  140
         StringBuffer buf = new StringBuffer(20);
 42  140
         StringTokenizer st = new StringTokenizer(tagName, delim);
 43  140
         String s = null;
 44  454
         while (st.hasMoreElements()) {
 45  314
             s = (String) st.nextElement();
 46  314
             if (s.length() >= 1) {
 47  314
                 buf.append(capitalizePropertyName(s));
 48  
             }
 49  
         }
 50  140
         return createSetters(buf.toString());
 51  
     }
 52  
 
 53  
     private static String capitalizePropertyName(String propertyName) {
 54  318
         if (propertyName.length() >= 1) {
 55  318
             char[] chars = propertyName.toCharArray();
 56  318
             chars[0] = Character.toUpperCase(chars[0]);
 57  318
             return new String(chars);
 58  
         }
 59  0
         return propertyName;
 60  
     }
 61  
 
 62  
     private static String[] createSetters(String property) {
 63  144
         return new String[] { "set" + property, "add" + property };
 64  
     }
 65  
 }