Jadex 0.96-beta1

jadex.util
Class SUtil

java.lang.Object
  extended by jadex.util.SUtil

public class SUtil
extends Object

This class provides several useful static util methods.


Field Summary
static int CONVERT_ALL
          Constant that indicates a conversion of all known characters.
static int CONVERT_ALL_EXCEPT_AMP
          Constant that indicates a conversion of all known characters except &.
static int CONVERT_NONE
          Constant that indicates a conversion of no characters.
static String NULL
          A Null value.
static int SORT_DOWN
          Constant for sorting down.
static int SORT_UP
          Constant for sorting up.
 
Constructor Summary
SUtil()
           
 
Method Summary
static boolean arrayContains(Object array, Object value)
          Check if an element is contained in an array.
static boolean arrayEquals(Object array1, Object array2)
           
static List arrayToList(Object a)
          Transform an array to a vector.
static Set arrayToSet(Object a)
          Transform an array to a vector.
static String arrayToString(Object array)
          Get a string representation for an array.
static List calculateCartesianProduct(String[] names, Object[] values)
          Calculate the cartesian product of parameters.
static String colorToHTML(Color color)
          Convert a color to an html representation.
static int compareTo(String a, String b)
          Compares two strings, ignoring case.
static String convertPathToPackage(String path)
          Find a package name from a path.
static Object cutArrays(Object a1, Object a2)
          Cut two arrays.
static boolean equals(Object val1, Object val2)
           
static String fontToHTML(Font font)
          Convert a font to an html representation.
static String getDurationHMS(long ms)
          Get a string representation for a duration.
static String getPlural(String s)
          Get the plural of a word in singular.
static String getRelativePath(String startdir, String destdir)
          Find the relativ path from a start directory to a destination directory.
static InputStream getResource(String name)
          Get an input stream for whatever provided. 1.
static InputStream getResource0(String name)
          Get an input stream for whatever provided. 1.
static ResourceInfo getResourceInfo0(String name)
          Get an input stream for whatever provided. 1.
static String getSingular(String s)
          Get the singular of a word in plural.
static String[] getStringArray(String key, Properties props)
          Get a string array of properties that are separated by commas.
static boolean isInRange(Date date, Date start, Date end)
          Test if the date is in the range.
static Object[] iteratorToArray(Iterator it, Class clazz)
          Transform an iterator to an array.
static List iteratorToList(Iterator it)
          Transform an iterator to a list.
static List iteratorToList(Iterator it, List ret)
          Transform an iterator to a list.
static Object[] joinArbitraryArrays(Object[] as)
          Joins any arrays of (possibly) different type.
static Object joinArrays(Object a1, Object a2)
          Joins two arrays of the same type.
static String makeConform(String input)
          Convert an output to html/wml conform presentation.
static String makeConform(String input, int flag)
          Convert an output to html/wml conform presentation.
static String makeEnglishConform(String input)
          Convert an output readable in english.
static String removeExtension(String fn)
          Remove file extension.
static void replace(String source, StringBuffer dest, String old, String newstring)
          Parse a source string replacing occurrences and storing the result in the given string buffer.
static String replace(String source, String old, String newstring)
          Parse a source string replacing occurrences and returning the result.
static String stripTags(String source)
          Strip tags (e.g. html) from a string, leaving only the text content.
static Object substractArrays(Object a1, Object a2)
          First array minus second array.
static String wrapText(String text)
          Wrap a text at a given line length.
static String wrapText(String text, int wrap)
          Wrap a text at a given line length.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERT_ALL

public static final int CONVERT_ALL
Constant that indicates a conversion of all known characters.

See Also:
Constant Field Values

CONVERT_ALL_EXCEPT_AMP

public static final int CONVERT_ALL_EXCEPT_AMP
Constant that indicates a conversion of all known characters except &.

See Also:
Constant Field Values

CONVERT_NONE

public static final int CONVERT_NONE
Constant that indicates a conversion of no characters.

See Also:
Constant Field Values

NULL

public static final String NULL
A Null value.

See Also:
Constant Field Values

SORT_UP

public static final int SORT_UP
Constant for sorting up.

See Also:
Constant Field Values

SORT_DOWN

public static final int SORT_DOWN
Constant for sorting down.

See Also:
Constant Field Values
Constructor Detail

SUtil

public SUtil()
Method Detail

getStringArray

public static String[] getStringArray(String key,
                                      Properties props)
Get a string array of properties that are separated by commas.

Parameters:
key - The key.
props - The properties.
Returns:
The strings.

joinArrays

public static Object joinArrays(Object a1,
                                Object a2)
Joins two arrays of the same type. Creates a new array containing the values of the first array followed by the values of the second.

Parameters:
a1 - The first array.
a2 - The second array.
Returns:
The joined array.

joinArbitraryArrays

public static Object[] joinArbitraryArrays(Object[] as)
Joins any arrays of (possibly) different type. todo: Does not support basic types yet. Problem basic type array and object arrays cannot be mapped (except they are mapped).

Parameters:
as - The array of arrays to join..
Returns:
The joined array.

cutArrays

public static Object cutArrays(Object a1,
                               Object a2)
Cut two arrays.

Parameters:
a1 - The first array.
a2 - The second array.
Returns:
The cutted array.

substractArrays

public static Object substractArrays(Object a1,
                                     Object a2)
First array minus second array.

Parameters:
a1 - The first array.
a2 - The second array.
Returns:
The substracted array.

arrayToList

public static List arrayToList(Object a)
Transform an array to a vector.

Parameters:
a - The array.
Returns:
The vector for the array.

arrayToSet

public static Set arrayToSet(Object a)
Transform an array to a vector.

Parameters:
a - The array.
Returns:
The vector for the array.

iteratorToList

public static List iteratorToList(Iterator it)
Transform an iterator to a list.


iteratorToList

public static List iteratorToList(Iterator it,
                                  List ret)
Transform an iterator to a list.


iteratorToArray

public static Object[] iteratorToArray(Iterator it,
                                       Class clazz)
Transform an iterator to an array.


arrayContains

public static boolean arrayContains(Object array,
                                    Object value)
Check if an element is contained in an array.

Parameters:
array - The array.
value - The value.

equals

public static boolean equals(Object val1,
                             Object val2)

arrayEquals

public static boolean arrayEquals(Object array1,
                                  Object array2)

arrayToString

public static String arrayToString(Object array)
Get a string representation for an array.

Parameters:
array - The array.
Returns:
formatted string.

getSingular

public static String getSingular(String s)
Get the singular of a word in plural. Does NOT find all correct singular.

Parameters:
s - The plural word.
Returns:
The singular of this word.

getPlural

public static String getPlural(String s)
Get the plural of a word in singular. Does NOT find all correct plurals.

Parameters:
s - The word.
Returns:
The plural of this word.

compareTo

public static int compareTo(String a,
                            String b)
Compares two strings, ignoring case.

Parameters:
a - The first string.
b - The second string.
Returns:
a <0

isInRange

public static boolean isInRange(Date date,
                                Date start,
                                Date end)
Test if the date is in the range. Start or end may null and will so not be checked.

Parameters:
date - The date.
start - The start.
end - The end.
Returns:
True, if date is in range.

removeExtension

public static String removeExtension(String fn)
Remove file extension.

Parameters:
fn - The filename..
Returns:
filename without extension.

wrapText

public static String wrapText(String text)
Wrap a text at a given line length. Doesn't to word wrap, just inserts linebreaks every nth character. If the string already contains linebreaks, these are handled properly (extra linebreaks will only be inserted when needed).

Parameters:
text - The text to wrap.

wrapText

public static String wrapText(String text,
                              int wrap)
Wrap a text at a given line length. Doesn't to word wrap, just inserts linebreaks every nth character. If the string already contains linebreaks, these are handled properly (extra linebreaks will only be inserted when needed).

Parameters:
text - The text to wrap.
wrap - The column width.

makeConform

public static String makeConform(String input)
Convert an output to html/wml conform presentation.

Parameters:
input - The input string.
Returns:
The converted output string.

makeConform

public static String makeConform(String input,
                                 int flag)
Convert an output to html/wml conform presentation.

Parameters:
input - The input string.
flag - CONVERT_ALL, CONVERT_NONE, CONVERT_ALL_EXCEPT_AMP;
Returns:
The converted output string.

stripTags

public static String stripTags(String source)
Strip tags (e.g. html) from a string, leaving only the text content.


makeEnglishConform

public static String makeEnglishConform(String input)
Convert an output readable in english. Therefore remove all äs, ös, üs etc.

Parameters:
input - The input string.
Returns:
The converted output string.

colorToHTML

public static String colorToHTML(Color color)
Convert a color to an html representation.

Parameters:
color - The color.
Returns:
The html string representing the color.

fontToHTML

public static String fontToHTML(Font font)
Convert a font to an html representation.

Parameters:
font - The font.
Returns:
The html string representing the font.

replace

public static void replace(String source,
                           StringBuffer dest,
                           String old,
                           String newstring)
Parse a source string replacing occurrences and storing the result in the given string buffer. This is a fast alternative to String.replaceAll(), because it does not use regular expressions.

Parameters:
source - The source string.
dest - The destination string buffer.
old - The string to replace.
newstring - The string to use as replacement.

replace

public static String replace(String source,
                             String old,
                             String newstring)
Parse a source string replacing occurrences and returning the result. This is a fast alternative to String.replaceAll(), because it does not use regular expressions.

Parameters:
source - The source string.
old - The string to replace.
newstring - The string to use as replacement.

getResource

public static InputStream getResource(String name)
                               throws IOException
Get an input stream for whatever provided. 1. It is tried to load the resource as file. 2. It is tried to load the resource via the ClassLoader. 3. It is tried to load the resource as URL.

Parameters:
name - The resource description.
Returns:
The input stream for the resource.
Throws:
IOException - when the resource was not found.

getResource0

public static InputStream getResource0(String name)
Get an input stream for whatever provided. 1. It is tried to load the resource as file. 2. It is tried to load the resource via the ClassLoader. 3. It is tried to load the resource as URL.

Parameters:
name - The resource description.
Returns:
The input stream for the resource or null when the resource was not found.

getResourceInfo0

public static ResourceInfo getResourceInfo0(String name)
Get an input stream for whatever provided. 1. It is tried to load the resource as file. 2. It is tried to load the resource via the ClassLoader. 3. It is tried to load the resource as URL.

Parameters:
name - The resource description.
Returns:
The info object for the resource or null when the resource was not found.

getDurationHMS

public static String getDurationHMS(long ms)
Get a string representation for a duration.

Parameters:
ms - The duration in ms.
Returns:
The string representation.

convertPathToPackage

public static String convertPathToPackage(String path)
Find a package name from a path. Searches the most specific classpath and uses the rest of the pathname as package name.

Parameters:
path - The directory.
Returns:
The package.

calculateCartesianProduct

public static List calculateCartesianProduct(String[] names,
                                             Object[] values)
Calculate the cartesian product of parameters. Example: names = {"a", "b"}, values = {{"1", "2"}, {"3", "4"}} result = {{"a=1", b="3"}, {"a=2", b="3"}, {"a=1", b="4"}, {"a=2", b="4"}}

Parameters:
names - The names.
values - The values (must be some form of collection, i.e. array, list, iterator etc.)

getRelativePath

public static String getRelativePath(String startdir,
                                     String destdir)
Find the relativ path from a start directory to a destination directory.

Parameters:
startdir - The start directory.
destdir - The destination directory.
Returns:
The relativ path from start to destination. // todo: what if paths are on different drives

Jadex 0.96-beta1

Submit a bug or feature
For further API reference and developer documentation, see the Jadex User Guide and the Jadex Tutorial. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, and working code examples.

Copyright (C) 2002-2007 Lars Braubach, Alexander Pokahr - University of Hamburg. Use is subject to license terms.