Knopflerfish OSGi 3.0.0

org.knopflerfish.util
Class Text

java.lang.Object
  extended by org.knopflerfish.util.Text

public class Text
extends java.lang.Object

Misc static text utility methods.


Nested Class Summary
static class Text.AttributeTokenizer
          Class for tokenize an attribute string.
 
Field Summary
protected static char CITCHAR
          Default citation char for splitwords().
protected static java.lang.String WHITESPACE
          Default whitespace string for splitwords().
 
Constructor Summary
Text()
           
 
Method Summary
static int binarySearch(java.util.List pl, java.util.Comparator c, java.lang.Object p)
          Do binary search for a package entry in the list with the same version number add the specifies package entry.
static java.lang.String capitalize(java.lang.String s)
          Make first (and only) character in string upper case.
static boolean containsIgnoreCase(java.util.List l, java.util.List l2)
          Check if a string exists in a list.
static java.lang.String formatJavaType(java.lang.String s, java.lang.String[] prefixIgnore)
          Format a java type in human readable way.
static java.lang.String getParam(java.lang.String s, java.lang.String param, java.lang.String def)
          Retrieves a parameter value from a parameter string.
static java.lang.String join(java.lang.Object[] s, java.lang.String sep)
          Join an array into a single string with a given separator.
static java.util.Iterator parseEntries(java.lang.String a, java.lang.String s, boolean single, boolean unique, boolean single_entry)
          Parse strings of format: ENTRY (, ENTRY)* ENTRY = key (; key)* (; PARAM)* PARAM = attribute '=' value PARAM = directive ':=' value
static java.util.ArrayList parseEnumeration(java.lang.String d, java.lang.String s)
          Parse strings of format: ENTRY (, ENTRY)*
static java.lang.String replace(java.lang.String s, java.lang.String v1, boolean v2)
          Utility method for replacing substrings with a boolean.
static java.lang.String replace(java.lang.String s, java.lang.String v1, int v2)
          Utility method for replacing substrings with an integer.
static java.lang.String replace(java.lang.String s, java.lang.String v1, java.lang.String v2)
          Replace all occurances of a substring with another string.
static java.lang.String[] split(java.lang.String s, java.lang.String sep)
          Splits a string into words, using the StringTokenizer class.
static java.lang.String[] splitwords(java.lang.String s)
          Utility method to split a string into words separated by whitespace.
static java.lang.String[] splitwords(java.lang.String s, java.lang.String whiteSpace)
          Utility method to split a string into words separated by whitespace.
static java.lang.String[] splitwords(java.lang.String s, java.lang.String whiteSpace, char citChar)
          Split a string into words separated by whitespace.
static java.lang.Object[] toArray(java.util.Vector v)
           
static java.lang.String untabify(java.lang.String s, int tabSize)
          Expand all tabs in a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WHITESPACE

protected static java.lang.String WHITESPACE
Default whitespace string for splitwords(). Value is " \t\n\r")


CITCHAR

protected static char CITCHAR
Default citation char for splitwords(). Value is '"'

Constructor Detail

Text

public Text()
Method Detail

getParam

public static java.lang.String getParam(java.lang.String s,
                                        java.lang.String param,
                                        java.lang.String def)
Retrieves a parameter value from a parameter string. If the parameter is not found the default value is returned.

Parameters:
s - Parameter string, format '<param1>=data1::<param2>=data2'
param - Parameter to retrieve.
def - Default value to return, if the parameter is not found.
Returns:
parameter value or default value.

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String v1,
                                       java.lang.String v2)
Replace all occurances of a substring with another string.

The returned string will shrink or grow as necessary, depending on the lengths of v1 and v2.

Implementation note: This method avoids using the standard String manipulation methods to increase execution speed. Using the replace method does however include two new operations in the case when matches are found.

Parameters:
s - Source string.
v1 - String to be replaced with v2.
v2 - String replacing v1.
Returns:
Modified string. If any of the input strings are null, the source string s will be returned unmodified. If v1.length == 0, v1.equals(v2) or no occurances of v1 is found, also return s unmodified.

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String v1,
                                       int v2)
Utility method for replacing substrings with an integer.

Equivalent to replace(s, v1, Integer.toString(v2))


replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String v1,
                                       boolean v2)
Utility method for replacing substrings with a boolean.

Equivalent to replace(s, v1, v2 ? "true" : "false")


untabify

public static java.lang.String untabify(java.lang.String s,
                                        int tabSize)
Expand all tabs in a string. Tab stop positions are placed at the columns which are multiples of tabSize.

Parameters:
s - String to untabify.
tabSize - Tab stop interval.
Returns:
String with expanded tabs.

formatJavaType

public static java.lang.String formatJavaType(java.lang.String s,
                                              java.lang.String[] prefixIgnore)
Format a java type in human readable way.

Parameters:
s - Type string to format.
prefixIgnore - Prefix strings to ignore in output.
Returns:
Nice-to-read string.

capitalize

public static java.lang.String capitalize(java.lang.String s)
Make first (and only) character in string upper case.

Parameters:
s - String to capitalize.
Returns:
Capitalized string. If s is null or equals the empty string, return s.

splitwords

public static java.lang.String[] splitwords(java.lang.String s)
Utility method to split a string into words separated by whitespace.

Equivalent to splitwords(s, Text.WHITESPACE)


splitwords

public static java.lang.String[] splitwords(java.lang.String s,
                                            java.lang.String whiteSpace)
Utility method to split a string into words separated by whitespace.

Equivalent to splitwords(s, Text.WHITESPACE, Text.CITCHAR)


splitwords

public static java.lang.String[] splitwords(java.lang.String s,
                                            java.lang.String whiteSpace,
                                            char citChar)
Split a string into words separated by whitespace.

Citation chars may be used to group words with embedded whitespace.

Parameters:
s - String to split.
whiteSpace - whitespace to use for splitting. Any of the characters in the whiteSpace string are considered whitespace between words and will be removed from the result. If no words are found, return an array of length zero.
citChar - Citation character used for grouping words with embedded whitespace. Typically '"'

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String sep)
Splits a string into words, using the StringTokenizer class.


join

public static java.lang.String join(java.lang.Object[] s,
                                    java.lang.String sep)
Join an array into a single string with a given separator.


toArray

public static java.lang.Object[] toArray(java.util.Vector v)

parseEnumeration

public static java.util.ArrayList parseEnumeration(java.lang.String d,
                                                   java.lang.String s)
Parse strings of format: ENTRY (, ENTRY)*

Parameters:
d - Directive being parsed
s - String to parse
Returns:
A sorted ArrayList with enumeration or null if enumeration string was null.
Throws:
java.lang.IllegalArgumentException - If syntax error in input string.

binarySearch

public static int binarySearch(java.util.List pl,
                               java.util.Comparator c,
                               java.lang.Object p)
Do binary search for a package entry in the list with the same version number add the specifies package entry.

Parameters:
pl - Sorted list of package entries to search.
p - Package entry to search for.
Returns:
index of the found entry. If no entry is found, return (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list.

parseEntries

public static java.util.Iterator parseEntries(java.lang.String a,
                                              java.lang.String s,
                                              boolean single,
                                              boolean unique,
                                              boolean single_entry)
Parse strings of format: ENTRY (, ENTRY)* ENTRY = key (; key)* (; PARAM)* PARAM = attribute '=' value PARAM = directive ':=' value

Parameters:
a - Attribute being parsed
s - String to parse
single - If true, only allow one key per ENTRY
unique - Only allow unique parameters for each ENTRY.
single_entry - If true, only allow one ENTRY is allowed.
Returns:
Iterator(Map(param -> value)) or null if input string is null.
Throws:
java.lang.IllegalArgumentException - If syntax error in input string.

containsIgnoreCase

public static boolean containsIgnoreCase(java.util.List l,
                                         java.util.List l2)
Check if a string exists in a list. Ignore case when comparing.


Knopflerfish OSGi 3.0.0