01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
18: */
19:
20: package edu.umd.cs.findbugs.util;
21:
22: import java.util.Arrays;
23:
24: /** A class for static String utility methods.
25: * @author Brian Cole
26: */
27: public class Strings {
28:
29: /** This is intended to be semantically equivalent to <code>source.replace(find, repl)</code>
30: * but also compatible with JDK 1.4.
31: * @param source The String on which to operate
32: * @param find The literal substring to be replaced
33: * @param repl The literal replacement substring
34: * @return The resultant String after substitution
35: * @throws NullPointerException if any of the arguments are null
36: * @throws IllegalArgumentException if <code>find</code> has zero length
37: * @see java.lang.String#replace(CharSequence target, CharSequence replacement)
38: */
39: public static String replace(String source, String find, String repl) {
40: return source.replace(find, repl);
41: }
42:
43: /** This is intended to be equivalent to <code>Arrays.toString(a)</code>
44: * but also compatible with JDK 1.4.
45: * This concatenates the results of calling String.valueOf() on each element
46: * of the array, so this won't work well for multi-dimensional arrays.
47: * @see java.lang.String#valueOf(Object)
48: * @see java.util.Arrays#toString(Object[])
49: * @see java.util.Arrays#deepToString(Object[])
50: */
51: public static String toString(final Object[] a) {
52: return Arrays.toString(a);
53: }
54:
55: /**
56: * Trim trailing comma from given string.
57: *
58: * @param s a string
59: * @return the same string with trailing comma trimmed (if any)
60: */
61: public static String trimComma(String s) {
62: if (s.endsWith(",")) {
63: s = s.substring(0, s.length() - 1);
64: }
65: return s;
66: }
67:
68: }
|