Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/StringUtils.java @ 819:6925d18580c0
Added more Javadoc.
gnv-artifacts/trunk@905 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 12 Apr 2010 13:12:21 +0000 |
parents | 2cea76f1112e |
children | f953c9a559d8 |
rev | line source |
---|---|
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.utils; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 /** |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
4 * 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
|
5 * |
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
|
6 * @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
|
7 */ |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 public final class StringUtils |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 private StringUtils() { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
13 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
14 * Append a string to a string array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
15 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
16 * @param haystack String array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
17 * @param straw String to append. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
18 * @return the new string array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
19 */ |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 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
|
21 if (haystack == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 return new String [] { straw }; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 } |
442
52e031261eaa
Create a new 'gnv' section in config file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
439
diff
changeset
|
24 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
|
25 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
|
26 nhaystack[haystack.length] = straw; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 return nhaystack; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
30 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
31 * 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
|
32 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
33 * @param haystack String array. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
34 * @param needle String for being checked. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
798
diff
changeset
|
35 * @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
|
36 */ |
439
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 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
|
38 if (haystack == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 return false; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 if (needle == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 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
|
44 if (haystack[i] == null) { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 return true; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
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 else { |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 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
|
51 String straw = haystack[i]; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 if (straw != null && straw.equals(needle)) { |
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 |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 return false; |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
8975de9d7483
Loop through configuration to chart generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |