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 working with strings.


Method Summary
static
<T> java.lang.String
conjoin(java.lang.String sep, java.util.Collection<T> objects)
          Concatenate all objects in a collection with the given separator between each.
static java.lang.String conjoin(java.lang.String sep, java.lang.String... strings)
          Concatenate all strings in a collection with the given separator between each.
static java.lang.String makeEllipsis(java.lang.String orgString, int maxLength)
          Generate a ellipsis of orgString.
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
 

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.lang.String sep,
                                                 java.util.Collection<T> objects)
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:
sep - A string to separate the list items.
objects - A collection of object to concatenate as a string.
Returns:
The concatenated string, or null if the list was null.

conjoin

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

Parameters:
sep - A string to separate the list items.
strings - An array of strings to concatenate
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.

makeEllipsis

public static java.lang.String makeEllipsis(java.lang.String orgString,
                                            int maxLength)
Generate a ellipsis of orgString. If orgString is longer than maxLength, then we return a String containing the first maxLength characters and then append " ..".

Parameters:
orgString - the original string
maxLength - the maximum length of the string before ellipsing it
Returns:
an ellipsis of orgString