KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > util > StringUtils


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * StringUtils.java
26  *
27  * Created on November 16, 2000, 12:01 AM
28  */

29
30 package com.sun.enterprise.tools.common.util;
31
32 /**
33  *
34  * @author bnevins
35  * @version 1.0
36  */

37 public class StringUtils
38 {
39     public static String JavaDoc UpperCaseFirstLetter(String JavaDoc s)
40     {
41         if(s == null || s.length() <= 0)
42             return s;
43         
44         return s.substring(0, 1).toUpperCase() + s.substring(1);
45     }
46
47     ////////////////////////////////////////////////////////////////////////////
48

49     public static String JavaDoc padRight(String JavaDoc s, int len)
50     {
51         if(s == null || s.length() >= len)
52             return s;
53
54         for(int i = len - s.length(); i > 0; --i)
55             s += ' ';
56
57         return s;
58     }
59
60
61     ////////////////////////////////////////////////////////////////////////////
62

63     public static String JavaDoc padLeft(String JavaDoc s, int len)
64     {
65         if(s == null || s.length() >= len)
66             return s;
67
68         String JavaDoc ret = ""; // NOI18N
69

70         for(int i = len - s.length(); i > 0; --i)
71             ret += ' ';
72
73         return ret + s;
74     }
75
76     ////////////////////////////////////////////////////////////////////////////
77

78     public static String JavaDoc toShortClassName(String JavaDoc className)
79     {
80         int index = className.lastIndexOf('.');
81
82         if(index >= 0 && index < className.length() - 1)
83             return className.substring(index + 1);
84
85         return className;
86     }
87
88                 ////////////////////////////////////////////////////////////////////////////
89

90         public static String JavaDoc replace(String JavaDoc s, String JavaDoc token, String JavaDoc replace)
91     {
92         if(s == null || s.length() <= 0 || token == null || token.length() <= 0)
93             return s;
94         
95         int index = s.indexOf(token);
96
97         if(index < 0)
98             return s;
99
100         int tokenLength = token.length();
101         String JavaDoc ret = s.substring(0, index);
102         ret += replace;
103         ret += s.substring(index + tokenLength);
104
105         return ret;
106     }
107
108         ////////////////////////////////////////////////////////////////////////////
109

110     public static void main(String JavaDoc[] args)
111     {
112         String JavaDoc[] test = new String JavaDoc[] { "xyz", "HITHERE", "123aa", "aSSS", "yothere" };//NOI18N
113

114         for(int i = 0; i < test.length; i++)
115         {
116             System.out.println(test[i] + " >>> " + UpperCaseFirstLetter(test[i]));//NOI18N
117
}
118     }
119         public static boolean isEmpty(String JavaDoc s)
120     {
121             if((s != null) && (! s.trim().equals(""))) // NOI18N
122
{
123                 return false;
124             }else
125             {
126                 return true;
127             }
128         }
129         
130
131 }
132
Popular Tags