Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/StringUtils.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 52e031261eaa |
children | c4156275c1e1 |
comparison
equal
deleted
inserted
replaced
590:5f5f273c8566 | 657:af3f56758f59 |
---|---|
1 package de.intevation.gnv.utils; | |
2 | |
3 /** | |
4 * @author Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
5 */ | |
6 public final class StringUtils | |
7 { | |
8 private StringUtils() { | |
9 } | |
10 | |
11 public static final String [] append(String [] haystack, String straw) { | |
12 if (haystack == null) { | |
13 return new String [] { straw }; | |
14 } | |
15 String [] nhaystack = new String[haystack.length + 1]; | |
16 System.arraycopy(haystack, 0, nhaystack, 0, haystack.length); | |
17 nhaystack[haystack.length] = straw; | |
18 return nhaystack; | |
19 } | |
20 | |
21 public static final boolean contains(String [] haystack, String needle) { | |
22 if (haystack == null) { | |
23 return false; | |
24 } | |
25 | |
26 if (needle == null) { | |
27 for (int i = haystack.length - 1; i >= 0; --i) { | |
28 if (haystack[i] == null) { | |
29 return true; | |
30 } | |
31 } | |
32 } | |
33 else { | |
34 for (int i = haystack.length - 1; i >= 0; --i) { | |
35 String straw = haystack[i]; | |
36 if (straw != null && straw.equals(needle)) { | |
37 return true; | |
38 } | |
39 } | |
40 } | |
41 | |
42 return false; | |
43 } | |
44 } | |
45 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |