Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/StringUtils.java @ 1129:ccfa07b88476
merged geo-backend
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:01 +0200 |
parents | f953c9a559d8 |
children |
rev | line source |
---|---|
1115
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
1 /* |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
3 * |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
7 */ |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
806
diff
changeset
|
8 |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.gnv.utils; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 /** |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
12 * Helper class which supports some methods for working with strings. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
13 * |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
14 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 */ |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 public final class StringUtils |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 private StringUtils() { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
21 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
22 * Append a string to a string array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
23 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
24 * @param haystack String array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
25 * @param straw String to append. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
26 * @return the new string array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
27 */ |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public static final String [] append(String [] haystack, String straw) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 if (haystack == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 return new String [] { straw }; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
442
52e031261eaa
Create a new 'gnv' section in config file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
439
diff
changeset
|
32 String [] nhaystack = new String[haystack.length + 1]; |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 System.arraycopy(haystack, 0, nhaystack, 0, haystack.length); |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 nhaystack[haystack.length] = straw; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 return nhaystack; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
38 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
39 * Checks the existence of a string in a given string array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
40 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
41 * @param haystack String array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
42 * @param needle String for being checked. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
43 * @return true, if the string is contained in <i>haystack</i> - else false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
44 */ |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 public static final boolean contains(String [] haystack, String needle) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 if (haystack == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 return false; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 if (needle == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 for (int i = haystack.length - 1; i >= 0; --i) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 if (haystack[i] == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return true; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 else { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 for (int i = haystack.length - 1; i >= 0; --i) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 String straw = haystack[i]; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 if (straw != null && straw.equals(needle)) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 return true; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 return false; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |