KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > StringHelper


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: StringHelper.java 154 2006-03-27 15:30:10Z ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 /**
25  *
26  * @author ofabre - EBM Websourcing
27  *
28  */

29 public final class StringHelper {
30
31     private StringHelper() {
32         super();
33     }
34
35     /**
36      * Test the equality of the specified strings. test is : ( (a==b==null) ||
37      * a.equals(b) )
38      *
39      * @param a
40      * @param b
41      * @return
42      */

43     public static boolean equal(String JavaDoc a, String JavaDoc b) {
44         if (a != null) {
45             return a.equals(b);
46         } else {
47             return b == null;
48         }
49     }
50
51     /**
52      * Same as equal, with ignoreCase
53      *
54      * @param a
55      * @param b
56      * @return
57      */

58     public static boolean equalIgnoreCase(String JavaDoc a, String JavaDoc b) {
59         if (a != null) {
60             return a.equalsIgnoreCase(b);
61         } else {
62             return b == null;
63         }
64     }
65
66     /**
67      * Check if the given String is empty or null.
68      *
69      * @param s
70      * the <code>String</code> to analyse
71      * @return true if the <code>String</code> is empty or null, false
72      * otherwise
73      */

74     public static boolean isEmpty(String JavaDoc s) {
75         if (s == null) {
76             return true;
77         }
78
79         if (s.trim().equals("")) {
80             return true;
81         }
82
83         return false;
84     }
85 }
86
Popular Tags