Coverage Report - org.seasar.cubby.internal.util.StringUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
StringUtils
92%
24/26
86%
24/28
3
 
 1  
 /*
 2  
  * Copyright 2004-2009 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.cubby.internal.util;
 17  
 
 18  
 /**
 19  
  * {@link String}用のユーティリティクラスです。
 20  
  * 
 21  
  * @author baba
 22  
  * @since 2.0.0
 23  
  */
 24  0
 public class StringUtils {
 25  
 
 26  
         /**
 27  
          * 空かどうかを返します。
 28  
          * 
 29  
          * @param text
 30  
          *            文字列
 31  
          * @return 空かどうか
 32  
          */
 33  
         public static final boolean isEmpty(final String text) {
 34  602
                 return text == null || text.length() == 0;
 35  
         }
 36  
 
 37  
         /**
 38  
          * ケースインセンシティブで文字列同士が等しいかどうか返します。どちらもnullの場合は、<code>true</code>を返します。
 39  
          * 
 40  
          * @param target1
 41  
          *            文字列1
 42  
          * @param target2
 43  
          *            文字列2
 44  
          * @return ケースインセンシティブで文字列同士が等しいか
 45  
          */
 46  
         public static boolean equalsIgnoreCase(final String target1,
 47  
                         final String target2) {
 48  18
                 return (target1 == null) ? (target2 == null) : target1
 49  
                                 .equalsIgnoreCase(target2);
 50  
         }
 51  
 
 52  
         /**
 53  
          * ブランクかどうか返します。
 54  
          * 
 55  
          * @param str
 56  
          *            文字列
 57  
          * @return ブランクかどうか
 58  
          */
 59  
         public static boolean isBlank(final String str) {
 60  8
                 if (str == null || str.length() == 0) {
 61  2
                         return true;
 62  
                 }
 63  10
                 for (int i = 0; i < str.length(); i++) {
 64  8
                         if (!Character.isWhitespace(str.charAt(i))) {
 65  4
                                 return false;
 66  
                         }
 67  
                 }
 68  2
                 return true;
 69  
         }
 70  
 
 71  
         /**
 72  
          * ブランクではないかどうか返します。
 73  
          * 
 74  
          * @param str
 75  
          *            文字列
 76  
          * @return ブランクではないかどうか
 77  
          * @see #isBlank(String)
 78  
          */
 79  
         public static boolean isNotBlank(final String str) {
 80  4
                 return !isBlank(str);
 81  
         }
 82  
 
 83  
         /**
 84  
          * 文字列を置き換えます。
 85  
          * 
 86  
          * @param text
 87  
          *            テキスト
 88  
          * @param fromText
 89  
          *            置き換え対象のテキスト
 90  
          * @param toText
 91  
          *            置き換えるテキスト
 92  
          * @return 結果
 93  
          */
 94  
         public static final String replace(final String text,
 95  
                         final String fromText, final String toText) {
 96  
 
 97  576
                 if (text == null || fromText == null || toText == null) {
 98  0
                         return null;
 99  
                 }
 100  576
                 final StringBuilder builder = new StringBuilder(100);
 101  576
                 int pos = 0;
 102  576
                 int pos2 = 0;
 103  
                 while (true) {
 104  591
                         pos = text.indexOf(fromText, pos2);
 105  591
                         if (pos == 0) {
 106  3
                                 builder.append(toText);
 107  3
                                 pos2 = fromText.length();
 108  588
                         } else if (pos > 0) {
 109  12
                                 builder.append(text.substring(pos2, pos));
 110  12
                                 builder.append(toText);
 111  12
                                 pos2 = pos + fromText.length();
 112  
                         } else {
 113  576
                                 builder.append(text.substring(pos2));
 114  576
                                 break;
 115  
                         }
 116  
                 }
 117  576
                 return builder.toString();
 118  
         }
 119  
 
 120  
 }