net.shibboleth.utilities.java.support.primitive
Class StringSupport

java.lang.Object
  extended by net.shibboleth.utilities.java.support.primitive.StringSupport

public final class StringSupport
extends Object

String utility methods.


Constructor Summary
private StringSupport()
          Constructor.
 
Method Summary
static String listToStringValue(List<String> values, String delimiter)
          Converts a List of strings into a single string, with values separated by a specified delimiter.
static List<String> stringToList(String string, String delimiter)
          Converts a delimited string into a list.
static String trim(String s)
          Safely trims a string.
static String trimOrNull(String s)
          Safely trims a string and, if empty, converts it to null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringSupport

private StringSupport()
Constructor.

Method Detail

listToStringValue

@Nonnull
public static String listToStringValue(@Nonnull
                                               List<String> values,
                                               @Nonnull
                                               String delimiter)
Converts a List of strings into a single string, with values separated by a specified delimiter.

Parameters:
values - list of strings
delimiter - the delimiter used between values
Returns:
delimited string of values

stringToList

@Nonnull
public static List<String> stringToList(@Nonnull
                                                String string,
                                                @Nonnull
                                                String delimiter)
Converts a delimited string into a list. We cannot user an ungarnished tokenizer since it doesn't add a empty String if end of the input String was the delimiter. Hence we have to explicitly check.

Parameters:
string - the string to be split into a list
delimiter - the delimiter between values. This string may contain multiple delimiter characters, as allowed by StringTokenizer
Returns:
the list of values or an empty list if the given string is empty

trim

@Nullable
public static String trim(@Nullable
                                   String s)
Safely trims a string.

Parameters:
s - the string to trim, may be null
Returns:
the trimmed string or null if the given string was null

trimOrNull

@Nullable
public static String trimOrNull(@Nullable
                                         String s)
Safely trims a string and, if empty, converts it to null.

Parameters:
s - the string to trim, may be null
Returns:
the trimmed string or null if the given string was null or the trimmed string was empty


Copyright © 1999-2012. All Rights Reserved.