comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/StringUtils.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.utils;
10
11 /**
12 * Helper class which supports some methods for working with strings.
13 *
14 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
15 */
16 public final class StringUtils
17 {
18 private StringUtils() {
19 }
20
21 /**
22 * Append a string to a string array.
23 *
24 * @param haystack String array.
25 * @param straw String to append.
26 * @return the new string array.
27 */
28 public static final String [] append(String [] haystack, String straw) {
29 if (haystack == null) {
30 return new String [] { straw };
31 }
32 String [] nhaystack = new String[haystack.length + 1];
33 System.arraycopy(haystack, 0, nhaystack, 0, haystack.length);
34 nhaystack[haystack.length] = straw;
35 return nhaystack;
36 }
37
38 /**
39 * Checks the existence of a string in a given string array.
40 *
41 * @param haystack String array.
42 * @param needle String for being checked.
43 * @return true, if the string is contained in <i>haystack</i> - else false.
44 */
45 public static final boolean contains(String [] haystack, String needle) {
46 if (haystack == null) {
47 return false;
48 }
49
50 if (needle == null) {
51 for (int i = haystack.length - 1; i >= 0; --i) {
52 if (haystack[i] == null) {
53 return true;
54 }
55 }
56 }
57 else {
58 for (int i = haystack.length - 1; i >= 0; --i) {
59 String straw = haystack[i];
60 if (straw != null && straw.equals(needle)) {
61 return true;
62 }
63 }
64 }
65
66 return false;
67 }
68 }
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org