Coverage Report - net.fckeditor.tool.Utils
 
Classes in this File Line Coverage Branch Coverage Complexity
Utils
88%
14/16
86%
12/14
0
 
 1  
 /*
 2  
  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 3  
  * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 4  
  * 
 5  
  * == BEGIN LICENSE ==
 6  
  * 
 7  
  * Licensed under the terms of any of the following licenses at your
 8  
  * choice:
 9  
  * 
 10  
  *  - GNU General Public License Version 2 or later (the "GPL")
 11  
  *    http://www.gnu.org/licenses/gpl.html
 12  
  * 
 13  
  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 14  
  *    http://www.gnu.org/licenses/lgpl.html
 15  
  * 
 16  
  *  - Mozilla Public License Version 1.1 or later (the "MPL")
 17  
  *    http://www.mozilla.org/MPL/MPL-1.1.html
 18  
  * 
 19  
  * == END LICENSE ==
 20  
  */
 21  
 package net.fckeditor.tool;
 22  
 
 23  
 import java.util.HashSet;
 24  
 import java.util.Set;
 25  
 import java.util.StringTokenizer;
 26  
 
 27  
 /**
 28  
  * Some static helper methods.
 29  
  * 
 30  
  * @version $Id: Utils.java 2151 2008-07-02 22:03:15Z mosipov $
 31  
  */
 32  0
 public class Utils {
 33  
 
 34  
         /**
 35  
          * Constructs a set of uppercased strings from a delimiter-separated string.
 36  
          * 
 37  
          * @param stringList
 38  
          * @param delimiter
 39  
          *            The delimiter.
 40  
          * @return An emtpy list if 'stringList' is empty else a lowercased set of
 41  
          *         strings.
 42  
          * @throws IllegalArgumentException
 43  
          *             if 'delimiter' is empty.
 44  
          */
 45  
         public static Set<String> getSet(final String stringList,
 46  
                         final String delimiter) {
 47  15
                 if (isEmpty(delimiter))
 48  0
                         throw new IllegalArgumentException(
 49  
                                         "Argument 'delimiter' shouldn't be empty!");
 50  15
                 if (isEmpty(stringList))
 51  6
                         return new HashSet<String>();
 52  
 
 53  9
                 Set<String> set = new HashSet<String>();
 54  9
                 StringTokenizer st = new StringTokenizer(stringList, delimiter);
 55  106
                 while (st.hasMoreTokens()) {
 56  97
                         String tmp = st.nextToken();
 57  97
                         if (isNotEmpty(tmp)) // simple empty filter
 58  97
                                 set.add(tmp.toLowerCase());
 59  97
                 }
 60  9
                 return set;
 61  
         }
 62  
 
 63  
         /**
 64  
          * Just a wrapper to {@link #getSet(String, String)} for using '&#124;' as
 65  
          * delimiter.
 66  
          */
 67  
         public static Set<String> getSet(final String stringList) {
 68  14
                 return getSet(stringList, "|");
 69  
         }
 70  
 
 71  
         /**
 72  
          * Checks if a string is <code>null</code> or empty.
 73  
          * 
 74  
          * @param str
 75  
          *            to check
 76  
          * @return <code>true</code> if the string is <code>null</code>.
 77  
          */
 78  
         public static boolean isEmpty(final String str) {
 79  203
                 return str == null || str.length() == 0;
 80  
         }
 81  
 
 82  
         /**
 83  
          * Just a wrapper to {@link #isEmpty(String)}.
 84  
          * 
 85  
          * @param str
 86  
          * @return <code>true</code> if the String is not empty and not
 87  
          *         <code>null</code>.
 88  
          */
 89  
         public static boolean isNotEmpty(final String str) {
 90  102
                 return !isEmpty(str);
 91  
         }
 92  
 }