01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */package com.bm.ejb3guice.internal;
16:
17: /**
18: * String utilities.
19: *
20: * @author crazybob@google.com (Bob Lee)
21: */
22: public class Strings {
23:
24: /**
25: * Returns a string that is equivalent to the specified string with its
26: * first character converted to uppercase as by {@link String#toUpperCase}.
27: * The returned string will have the same value as the specified string if
28: * its first character is non-alphabetic, if its first character is already
29: * uppercase, or if the specified string is of length 0.
30: *
31: * <p>For example:
32: * <pre>
33: * capitalize("foo bar").equals("Foo bar");
34: * capitalize("2b or not 2b").equals("2b or not 2b")
35: * capitalize("Foo bar").equals("Foo bar");
36: * capitalize("").equals("");
37: * </pre>
38: *
39: * @param s the string whose first character is to be uppercased
40: * @return a string equivalent to <tt>s</tt> with its first character
41: * converted to uppercase
42: * @throws NullPointerException if <tt>s</tt> is null
43: */
44: public static String capitalize(String s) {
45: if (s.length() == 0)
46: return s;
47: char first = s.charAt(0);
48: char capitalized = Character.toUpperCase(first);
49: return (first == capitalized) ? s : capitalized
50: + s.substring(1);
51: }
52: }
|