dk.netarkivet.common.utils
Class StringUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.StringUtils

public class StringUtils
extends java.lang.Object

Utilities for wirking with strings.


Field Summary
static org.apache.commons.logging.Log log
           
 
Constructor Summary
StringUtils()
           
 
Method Summary
static
<T> java.lang.String
conjoin(java.util.Collection<T> objects, java.lang.String sep)
          Concatenate all objects in a collection with the given separator between each.
static java.lang.String conjoin(java.lang.String[] strings, java.lang.String sep)
          Concatenate all strings in a collection with the given separator between each.
static java.util.List<java.lang.Integer> parseIntList(java.lang.String[] stringArray)
          Change all Strings to Integers.
static java.lang.String repeat(java.lang.String s, int n)
          Repeat the string n times.
static java.lang.String replace(java.lang.String sentence, java.lang.String oldString, java.lang.String newString)
          Replace all occurrences of oldString with newString in a string.
static java.lang.String surjoin(java.util.List<java.lang.String> strings, java.lang.String pre, java.lang.String post)
          Concatenate all strings in a collection, with the fixed strings appended and prepended to each.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.commons.logging.Log log
Constructor Detail

StringUtils

public StringUtils()
Method Detail

replace

public static final java.lang.String replace(java.lang.String sentence,
                                             java.lang.String oldString,
                                             java.lang.String newString)
Replace all occurrences of oldString with newString in a string.

Parameters:
sentence - the string, where all occurrences of oldString are to be replaced with newString
oldString - the oldString
newString - the newString
Returns:
the resulting string, where all occurrences of oldString are replaced with newString

conjoin

public static final <T> java.lang.String conjoin(java.util.Collection<T> objects,
                                                 java.lang.String sep)
Concatenate all objects in a collection with the given separator between each. If the Collection is a List, this method will generate the conjoined string in list order. If the objects are not Strings, the toString method will be used to convert them to strings.

Parameters:
objects - A collection of object to concatenate as a string.
sep - A string to separate the list items.
Returns:
The concatenated string, or null if the list was null.

conjoin

public static final java.lang.String conjoin(java.lang.String[] strings,
                                             java.lang.String sep)
Concatenate all strings in a collection with the given separator between each.

Parameters:
strings - An array of strings to concatenate
sep - A string to separate the list items.
Returns:
The concatenated string, or null if the list was null.

surjoin

public static final java.lang.String surjoin(java.util.List<java.lang.String> strings,
                                             java.lang.String pre,
                                             java.lang.String post)
Concatenate all strings in a collection, with the fixed strings appended and prepended to each.

Parameters:
strings - A list of strings to join up.
pre - A string that will be put in front of each string in the list.
post - A string that will be put after each string in the list.
Returns:
The joined string, or null if strings is null.

repeat

public static final java.lang.String repeat(java.lang.String s,
                                            int n)
Repeat the string n times.

Parameters:
s - A string to repeat
n - How many times to repeat it.
Returns:
A repeated string
Throws:
ArgumentNotValid - if a negative amount is specified

parseIntList

public static java.util.List<java.lang.Integer> parseIntList(java.lang.String[] stringArray)
Change all Strings to Integers.

Parameters:
stringArray - the given array of Strings to convert
Returns:
a List of Integers.