|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
StringUtil.java | 0% | 0% | 0% | 0% |
|
1 | /* | |
2 | * Copyright (c) 2002-2003 by OpenSymphony | |
3 | * All rights reserved. | |
4 | */ | |
5 | package com.opensymphony.oscache.util; | |
6 | ||
7 | import java.util.ArrayList; | |
8 | import java.util.List; | |
9 | ||
10 | /** | |
11 | * Provides common utility methods for handling strings. | |
12 | * | |
13 | * @author <a href="mailto:chris@swebtec.com">Chris Miller</a> | |
14 | */ | |
15 | public class StringUtil { | |
16 | ||
17 | /** | |
18 | * Splits a string into substrings based on the supplied delimiter | |
19 | * character. Each extracted substring will be trimmed of leading | |
20 | * and trailing whitespace. | |
21 | * | |
22 | * @param str The string to split | |
23 | * @param delimiter The character that delimits the string | |
24 | * @return A string array containing the resultant substrings | |
25 | */ | |
26 | 0 | public static final List split(String str, char delimiter) { |
27 | // return no groups if we have an empty string | |
28 | 0 | if ((str == null) || "".equals(str)) { |
29 | 0 | return new ArrayList(); |
30 | } | |
31 | ||
32 | 0 | ArrayList parts = new ArrayList(); |
33 | 0 | int currentIndex; |
34 | 0 | int previousIndex = 0; |
35 | ||
36 | 0 | while ((currentIndex = str.indexOf(delimiter, previousIndex)) > 0) { |
37 | 0 | String part = str.substring(previousIndex, currentIndex).trim(); |
38 | 0 | parts.add(part); |
39 | 0 | previousIndex = currentIndex + 1; |
40 | } | |
41 | ||
42 | 0 | parts.add(str.substring(previousIndex, str.length()).trim()); |
43 | ||
44 | 0 | return parts; |
45 | } | |
46 | ||
47 | /** | |
48 | * @param s the string to be checked | |
49 | * @return true if the string parameter contains at least one element | |
50 | */ | |
51 | 0 | public static final boolean hasLength(String s) { |
52 | 0 | return (s != null) && (s.length() > 0); |
53 | } | |
54 | ||
55 | } |
|