org.norther.tammi.spray.engine.tool
Class TypeTool

java.lang.Object
  extended by org.norther.tammi.core.pool.RecyclableSupport
      extended by org.norther.tammi.core.pool.PoolableSupport
          extended by org.norther.tammi.spray.engine.tool.GlobalTool
              extended by org.norther.tammi.spray.engine.tool.TypeTool
All Implemented Interfaces:
Serializable, Cloneable, EventListener, Poolable, Recyclable, ContextBindingListener

public class TypeTool
extends GlobalTool

A global context tool for type conversions.

Version:
$Id: TypeTool.java,v 1.60 2010-07-08 22:06:59 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
TypeTool()
          Constructs a new tool.
 
Method Summary
 Object append(Object array, Object element)
          Appends an element to an array.
 Object asArray(Object object)
          Returns an object in an array.
<E> List<E>
asList(Object... object)
          Returns a collection, array or objects as a list.
<E> Set<E>
asOrderedSet(Object... object)
          Returns a collection, array or object as an ordered set.
<E> Set<E>
asSet(Object... object)
          Returns a collection, array or objects as a set.
 String cite(Object obj)
          Returns an object within apostrophes.
 Object clone(Object array)
          Clones an array and its elements.
 String concat(String... str)
          Concatenates strings.
 Object copy(Object array)
          Copies an array but not its elements.
 Collection<Boolean> counter()
          Returns an endless counter.
 Collection<Boolean> counter(int size)
          Returns a counter.
 String cut(String str, int max)
          Returns a string cut to the specified size.
 String cut(String str, int max, String tail)
          Returns a string cut to the specified size.
 String digest(String algorithm, String string)
          Computes a digest hash.
 String digest(String algorithm, String string, String encoding)
          Computes a digest hash applying the specified encoding.
 String digest(String algorithm, String salt, String string, String encoding)
          Computes a digest hash using the given salt and applying the specified encoding.
 boolean equals(Object object1, Object object2)
          Checks whether two objects are equal.
 String escape(CharSequence sequence)
          Excapes the specified sequence.
 String escape(CharSequence sequence, int limit, String additions)
          Escapes the specified sequence with additions.
 String fromXML(Object object)
          Converts an XML encoded object to a text string.
 String get(String str, String delim, int index)
          Gets an indexed element from a string.
 int indexOf(Object source, Object object, int... limits)
          Gets the index of the specified object within the source.
 Object insert(Object array, int index, Object element)
          Inserts an element to an array.
 boolean isArray(Object object)
          Checks whether an object is an array.
 boolean isBoolean(Object object)
          Checks whether an object is a boolean.
 boolean isBooleanType(String className, Class<?>... loaded)
          Checks whether the named class is boolean.
 boolean isByte(Object object)
          Checks whether an object is a byte.
 boolean isChar(String str, int c)
          Checks whether a string represents the specified char.
 boolean isCharacter(Object object)
          Checks whether an object is a character.
 boolean isCharSequence(Object object)
          Checks whether an object is a char sequence.
 boolean isCharSequenceType(String className, Class<?>... loaded)
          Checks whether the named class is character based.
 boolean isDateType(String className, Class<?>... loaded)
          Checks whether the named class is date based.
 boolean isDouble(Object object)
          Checks whether an object is a doouble.
 boolean isFloat(Object object)
          Checks whether an object is a float.
 boolean isInstance(Object object, String className)
          Checks whether the specified object is an instance of the named class.
 boolean isInteger(Object object)
          Checks whether an object is an integer.
 boolean isLOBType(String className, Class<?>... loaded)
          Checks whether the named class is a large object.
 boolean isLocationType(String className, Class<?>... loaded)
          Checks whether the named class is location based.
 boolean isLong(Object object)
          Checks whether an object is a long.
 boolean isNull(Object object)
          Checks whether an object is null.
 boolean isNumber(Object object)
          Checks whether an object is a number.
 boolean isNumericType(String className, Class<?>... loaded)
          Checks whether the named class is numeric.
 boolean isPrimitiveType(String className)
          Checks whether the specified class name is primitive.
 boolean isShort(Object object)
          Checks whether an object is a short.
 boolean isString(Object object)
          Checks whether an object is a string.
 boolean isStringType(String className, Class<?>... loaded)
          Checks whether the named class is string based.
 String join(Object array, String delims)
          Joins an array to delimited items to a string.
 Object newArray(int length)
          Returns an array of the specified size.
 StringBuffer newBuffer()
          Returns an empty buffer.
 StringBuffer newBuffer(Object object)
          Returns an initialized buffer.
 OutputStream newByteStream()
          Returns a byte stream.
 File newFile(Object obj)
          Returns a new file.
<E> List<E>
newList()
          Returns an empty list.
<E> List<E>
newList(int size)
          Returns a sized list.
 Locale newLocale(Object obj)
          Returns a new locale.
<K,V> Map<K,V>
newMap()
          Returns an empty map.
<K,V> OrderedMap<K,V>
newOrderedMap()
          Returns an empty ordered map.
<E> OrderedSet<E>
newOrderedSet()
          Returns an empty ordered set.
<E> Set<E>
newSet()
          Returns an empty set.
 ZipEntry newZipEntry(String path)
          Returns a zip entry.
 OutputStream newZipStream(OutputStream out)
          Returns a zip stream.
 Object none()
          Returns a null.
 Date now()
          Returns the current date.
<V> Map<String,V>
prefix(String prefix, Map<? super String,V> map)
          Returns a map that is a prefixed subset of the given one.
<V> Map<String,V>
prefix(String prefix, String delims, Map<? super String,V> map)
          Returns a map that is a prefixed subset of the given one.
 String printStackTrace(Throwable error)
          Prints the stack trace of a throwable.
 String quote(Object obj)
          Returns an object within quotation.
 String replace(String source, String from, String to)
          Replaces occurancies of the specified substring in a string to another substring.
 Object sort(Object source)
          Sorts the specified source into ascending order.
 Object sort(Object source, Comparator<?> comp)
          Sorts the specified source to the order induced by the specified comparator.
 Object sort(Object array, int fromIndex, int toIndex)
          Sorts the specified range of the specified array into ascending order.
 Object sort(Object source, String className)
          Sorts the specified source to the order induced by the specified comparator class.
 String[] split(String items, String delims)
          Splits the delimited items of a string to an array.
<V> Map<String,V>
suffix(String suffix, Map<? super String,V> map)
          Returns a map that is a suffixed subset of the given one.
<V> Map<String,V>
suffix(String suffix, String delims, Map<? super String,V> map)
          Returns a map that is a suffixed subset of the given one.
 String tab(int depth)
          Returns a tab of the specified depth.
 boolean toBoolean(Object obj)
          Converts a string into a boolean.
 byte toByte(Object object)
          Converts an object to a byte.
 byte[] toBytes(Object object, String... encoding)
          Converts an object to bytes.
 char toChar(Object obj)
          Converts an object to a char.
 Class<?> toClass(String className, boolean... options)
          Returns the class instance of the named class.
 Comparator<Object> toComparator(List<String> attributes)
          Returns an attribute comparator for the specified attributes.
 double toDouble(Object obj)
          Converts a string into a double.
 float toFloat(Object obj)
          Converts a string into a float.
 int toInt(Object obj)
          Converts a string into an int.
 long toLong(Object obj)
          Converts a string into a long.
 Object toObject(String className, Object object)
          Converts objects.
 Object toObject(String className, Object object, String pattern)
          Converts objects by applying a pattern.
<K> Map<K,Object>
toObjects(Map<?,?> classNames, Map<K,?> objects)
          Converts a map of objects.
<K> Map<K,Object>
toObjects(Map<?,?> classNames, Map<K,?> objects, String pattern)
          Converts a map of objects by applying a pattern.
 Paint toPaint(String color)
          Converts a named color to a paint.
 int toPermissionMask(String actions)
          Converts permitted actions to a permission mask.
 String toPermittedActions(int permission)
          Converts a permission mask to permitted actions.
 String toPlainType(Class<?> clazz)
          Converts a class to its plain type.
 String toPlainType(String className)
          Converts a qualified class name to its plain type.
 short toShort(Object obj)
          Converts a string into a short.
 String toString(Object object)
          Converts an object to a string.
 String toString(Object object, String pattern)
          Converts an object to a string by applying a pattern.
 String toString(String className, Object object)
          Converts an object of the named class to a string.
 String toString(String className, Object object, String pattern)
          Converts an object of the named class to a string by applying a pattern.
 StringDate toStringDate(Date date)
          Converts a date to a string date.
 StringDate toStringDate(Object obj)
          Converts a string to a string date.
 String[] toStrings(Object object)
          Converts objects to a strings.
 String[] toStrings(String className, Object object)
          Converts objects of the named class to strings.
 String[] toStrings(String className, Object object, String pattern)
          Converts objects of the named class to strings by applying a pattern.
 Stroke toStroke(String pattern)
          Converts a pattern to a stroke.
 String toXML(Object object)
          Converts an object to an XML encoded string.
 String toXML(String className, Object object)
          Converts an object to an XML encoded string.
 String toXML(String className, Object object, String pattern)
          Converts an object to an XML encoded string applying a pattern.
 String unescape(CharSequence sequence)
          Unescapes the specified sequence.
 String unescape(CharSequence sequence, int limit, String exceptions)
          Unescapes the specified sequence with exceptions.
 String wrap(String str)
          Returns a string wrapped by linefeeds.
 
Methods inherited from class org.norther.tammi.spray.engine.tool.GlobalTool
clone, dispose, getContext, getContextToolFilter, getMBeanServer, isBound, nop, toString, valueBound, valueUnbound
 
Methods inherited from class org.norther.tammi.core.pool.PoolableSupport
disposed, recycled
 
Methods inherited from class org.norther.tammi.core.pool.RecyclableSupport
isDisposed, recycle
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.pool.Recyclable
isDisposed, recycle
 

Constructor Detail

TypeTool

public TypeTool()
Constructs a new tool.

Method Detail

indexOf

public int indexOf(Object source,
                   Object object,
                   int... limits)
Gets the index of the specified object within the source.

Parameters:
source - the source.
object - the object.
limits - inclusive start and exclusive end indices.
Returns:
the found index or -1.

copy

public Object copy(Object array)
Copies an array but not its elements.

Parameters:
array - the array.
Returns:
the copy.

clone

public Object clone(Object array)
Clones an array and its elements.

Parameters:
array - the array.
Returns:
the clone.

get

public String get(String str,
                  String delim,
                  int index)
Gets an indexed element from a string.

Parameters:
str - the string.
delim - the delimiter.
index - the index.
Returns:
the element or null if not found.

concat

public String concat(String... str)
Concatenates strings.

Parameters:
str - the strings.
Returns:
the concatenated string.

prefix

public <V> Map<String,V> prefix(String prefix,
                                Map<? super String,V> map)
Returns a map that is a prefixed subset of the given one. The key components must be delimited by periods.

Type Parameters:
V - the subset value type.
Parameters:
prefix - a key prefix.
map - the source map.
Returns:
the subset map.

prefix

public <V> Map<String,V> prefix(String prefix,
                                String delims,
                                Map<? super String,V> map)
Returns a map that is a prefixed subset of the given one.

Type Parameters:
V - the subset value type.
Parameters:
prefix - a key prefix.
delims - key delimiters.
map - the source map.
Returns:
the subset map.

suffix

public <V> Map<String,V> suffix(String suffix,
                                Map<? super String,V> map)
Returns a map that is a suffixed subset of the given one. The key components must be delimited by periods.

Type Parameters:
V - the subset value type.
Parameters:
suffix - a key suffix.
map - the source map.
Returns:
the subset map.

suffix

public <V> Map<String,V> suffix(String suffix,
                                String delims,
                                Map<? super String,V> map)
Returns a map that is a suffixed subset of the given one.

Type Parameters:
V - the subset value type.
Parameters:
suffix - a key suffix.
delims - key delimiters.
map - the source map.
Returns:
the subset map.

replace

public String replace(String source,
                      String from,
                      String to)
Replaces occurancies of the specified substring in a string to another substring.

Parameters:
source - the source string.
from - the substring to replace from.
to - the substring to replace to.
Returns:
the replaced string.

isBooleanType

public boolean isBooleanType(String className,
                             Class<?>... loaded)
Checks whether the named class is boolean.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a boolean type, otherwise false.

isNumericType

public boolean isNumericType(String className,
                             Class<?>... loaded)
Checks whether the named class is numeric.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a numeric type, otherwise false.

isStringType

public boolean isStringType(String className,
                            Class<?>... loaded)
Checks whether the named class is string based.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a string based type, otherwise false.

isCharSequenceType

public boolean isCharSequenceType(String className,
                                  Class<?>... loaded)
Checks whether the named class is character based.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a characted based type, otherwise false.

isDateType

public boolean isDateType(String className,
                          Class<?>... loaded)
Checks whether the named class is date based.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a date type, otherwise false.

isLocationType

public boolean isLocationType(String className,
                              Class<?>... loaded)
Checks whether the named class is location based.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a location type, otherwise false.

isLOBType

public boolean isLOBType(String className,
                         Class<?>... loaded)
Checks whether the named class is a large object.

Parameters:
className - the class name to check.
loaded - an optionally loaded class.
Returns:
true for a LOB type, otherwise false.

isPrimitiveType

public boolean isPrimitiveType(String className)
Checks whether the specified class name is primitive.

Parameters:
className - the class name to check.
Returns:
true for a primitive type, otherwise false.

isArray

public boolean isArray(Object object)
Checks whether an object is an array.

Parameters:
object - an object.
Returns:
true if an array, otherwise false.

isNumber

public boolean isNumber(Object object)
Checks whether an object is a number.

Parameters:
object - an object.
Returns:
true if a number, otherwise false.

isByte

public boolean isByte(Object object)
Checks whether an object is a byte.

Parameters:
object - an object.
Returns:
true if a byte, otherwise false.

isCharacter

public boolean isCharacter(Object object)
Checks whether an object is a character.

Parameters:
object - an object.
Returns:
true if a character, otherwise false.

isShort

public boolean isShort(Object object)
Checks whether an object is a short.

Parameters:
object - an object.
Returns:
true if a short, otherwise false.

isInteger

public boolean isInteger(Object object)
Checks whether an object is an integer.

Parameters:
object - an object.
Returns:
true if an integer, otherwise false.

isLong

public boolean isLong(Object object)
Checks whether an object is a long.

Parameters:
object - an object.
Returns:
true if a long, otherwise false.

isFloat

public boolean isFloat(Object object)
Checks whether an object is a float.

Parameters:
object - an object.
Returns:
true if a float, otherwise false.

isDouble

public boolean isDouble(Object object)
Checks whether an object is a doouble.

Parameters:
object - an object.
Returns:
true if a double, otherwise false.

isBoolean

public boolean isBoolean(Object object)
Checks whether an object is a boolean.

Parameters:
object - an object.
Returns:
true if a boolean, otherwise false.

isString

public boolean isString(Object object)
Checks whether an object is a string.

Parameters:
object - an object.
Returns:
true if a string, otherwise false.

isCharSequence

public boolean isCharSequence(Object object)
Checks whether an object is a char sequence.

Parameters:
object - an object.
Returns:
true if a char sequence, otherwise false.

isNull

public boolean isNull(Object object)
Checks whether an object is null.

Parameters:
object - an object.
Returns:
true if null, otherwise false.

isInstance

public boolean isInstance(Object object,
                          String className)
Checks whether the specified object is an instance of the named class.

Parameters:
object - an object.
className - the class name.
Returns:
true if an instance, false otherwise.

isChar

public boolean isChar(String str,
                      int c)
Checks whether a string represents the specified char.

Parameters:
str - the string.
c - the char.
Returns:
true if a char, false otherwise.

equals

public boolean equals(Object object1,
                      Object object2)
Checks whether two objects are equal. Array elements are compared one by one, if both objects are arrays. Numbers are compared as doubles.

Parameters:
object1 - the first object.
object2 - the second object.
Returns:
true if objects are equal, otherwise false.

none

public Object none()
Returns a null.

Returns:
always null.

toBytes

public byte[] toBytes(Object object,
                      String... encoding)
Converts an object to bytes.

Parameters:
object - the object.
encoding - the encoding.
Returns:
the byte.

toByte

public byte toByte(Object object)
Converts an object to a byte.

Parameters:
object - the object.
Returns:
the byte.

toChar

public char toChar(Object obj)
Converts an object to a char.

Parameters:
obj - the object.
Returns:
the char.

toShort

public short toShort(Object obj)
Converts a string into a short.

Parameters:
obj - the object.
Returns:
the short.

toInt

public int toInt(Object obj)
Converts a string into an int.

Parameters:
obj - the object.
Returns:
the int.

toLong

public long toLong(Object obj)
Converts a string into a long.

Parameters:
obj - the object.
Returns:
the long.

toFloat

public float toFloat(Object obj)
Converts a string into a float.

Parameters:
obj - the object.
Returns:
the float.

toDouble

public double toDouble(Object obj)
Converts a string into a double.

Parameters:
obj - the object.
Returns:
the double.

toBoolean

public boolean toBoolean(Object obj)
Converts a string into a boolean.

Parameters:
obj - the object.
Returns:
the boolean.

toStringDate

public StringDate toStringDate(Object obj)
Converts a string to a string date.

Parameters:
obj - the object.
Returns:
the string date.

toStringDate

public StringDate toStringDate(Date date)
Converts a date to a string date.

Parameters:
date - the date.
Returns:
the string date.

toString

public String toString(Object object)
Converts an object to a string.

Parameters:
object - the object to convert.
Returns:
the converted string.

toString

public String toString(Object object,
                       String pattern)
Converts an object to a string by applying a pattern.

Parameters:
object - the object to convert.
pattern - the conversion pattern.
Returns:
the converted string.

toString

public String toString(String className,
                       Object object)
Converts an object of the named class to a string.

Parameters:
className - the source class name.
object - the object to convert.
Returns:
the converted string.

toString

public String toString(String className,
                       Object object,
                       String pattern)
Converts an object of the named class to a string by applying a pattern.

Parameters:
className - the source class name.
object - the object to convert.
pattern - the conversion pattern.
Returns:
the converted string.

toStrings

public String[] toStrings(Object object)
Converts objects to a strings.

Parameters:
object - the object to convert.
Returns:
the converted strings.

toStrings

public String[] toStrings(String className,
                          Object object)
Converts objects of the named class to strings.

Parameters:
className - the source class name.
object - the object to convert.
Returns:
the converted strings.

toStrings

public String[] toStrings(String className,
                          Object object,
                          String pattern)
Converts objects of the named class to strings by applying a pattern.

Parameters:
className - the source class name.
object - the object to convert.
pattern - the conversion pattern.
Returns:
the converted strings.

toObject

public Object toObject(String className,
                       Object object)
Converts objects.

Parameters:
className - the target class name.
object - the object to convert.
Returns:
the converted object.

toObject

public Object toObject(String className,
                       Object object,
                       String pattern)
Converts objects by applying a pattern.

Parameters:
className - the target class name.
object - the object to convert.
pattern - the conversion pattern.
Returns:
the converted object.

toObjects

public <K> Map<K,Object> toObjects(Map<?,?> classNames,
                                   Map<K,?> objects)
Converts a map of objects.

Type Parameters:
K - the key type.
Parameters:
classNames - a map of class names.
objects - a map of objects to convert.
Returns:
the map of converted object.

toObjects

public <K> Map<K,Object> toObjects(Map<?,?> classNames,
                                   Map<K,?> objects,
                                   String pattern)
Converts a map of objects by applying a pattern.

Type Parameters:
K - the key type.
Parameters:
classNames - a map of class names.
objects - a map of objects to convert.
pattern - the conversion pattern.
Returns:
the map of converted object.

toPermittedActions

public String toPermittedActions(int permission)
Converts a permission mask to permitted actions.

Parameters:
permission - the permission to convert.
Returns:
the action string.

toPlainType

public String toPlainType(Class<?> clazz)
Converts a class to its plain type.

Parameters:
clazz - the class.
Returns:
the plain type.

toPlainType

public String toPlainType(String className)
Converts a qualified class name to its plain type.

Parameters:
className - the qualified class name.
Returns:
the plain type.

toPermissionMask

public int toPermissionMask(String actions)
Converts permitted actions to a permission mask.

Parameters:
actions - the actions to convert.
Returns:
the action mask.

counter

public Collection<Boolean> counter()
Returns an endless counter.

Returns:
the counter.

counter

public Collection<Boolean> counter(int size)
Returns a counter.

Parameters:
size - the size of the counter.
Returns:
the counter.

sort

public Object sort(Object source)
Sorts the specified source into ascending order.

Parameters:
source - the source to sort.
Returns:
the sorted source.

sort

public Object sort(Object source,
                   Comparator<?> comp)
Sorts the specified source to the order induced by the specified comparator.

Parameters:
source - the source to sort.
comp - the comparator.
Returns:
the sorted source.

sort

public Object sort(Object source,
                   String className)
Sorts the specified source to the order induced by the specified comparator class.

Parameters:
source - the source to sort.
className - the class name of the comparator.
Returns:
the sorted source.

sort

public Object sort(Object array,
                   int fromIndex,
                   int toIndex)
Sorts the specified range of the specified array into ascending order.

Parameters:
array - the array to sort.
fromIndex - the indext to start from.
toIndex - the index to end to.
Returns:
the original array sorted in place.

toComparator

public Comparator<Object> toComparator(List<String> attributes)
Returns an attribute comparator for the specified attributes.

Parameters:
attributes - a list of attributes.
Returns:
the attribute comparator.

now

public Date now()
Returns the current date.

Returns:
the current date.

newFile

public File newFile(Object obj)
Returns a new file.

Parameters:
obj - the object.
Returns:
the file.

newLocale

public Locale newLocale(Object obj)
Returns a new locale.

Parameters:
obj - the object.
Returns:
the locale.

newOrderedMap

public <K,V> OrderedMap<K,V> newOrderedMap()
Returns an empty ordered map.

Type Parameters:
K - the key type.
V - the value type.
Returns:
an empty ordered map.

newOrderedSet

public <E> OrderedSet<E> newOrderedSet()
Returns an empty ordered set.

Type Parameters:
E - the element type.
Returns:
an empty ordered set.

asOrderedSet

public <E> Set<E> asOrderedSet(Object... object)
Returns a collection, array or object as an ordered set.

Type Parameters:
E - the element type.
Parameters:
object - the object.
Returns:
an ordered set of items.

newMap

public <K,V> Map<K,V> newMap()
Returns an empty map.

Type Parameters:
K - the key type.
V - the value type.
Returns:
an empty map.

newSet

public <E> Set<E> newSet()
Returns an empty set.

Type Parameters:
E - the element type.
Returns:
an empty set.

asSet

public <E> Set<E> asSet(Object... object)
Returns a collection, array or objects as a set.

Type Parameters:
E - the element type.
Parameters:
object - the object.
Returns:
a set of items.

newList

public <E> List<E> newList()
Returns an empty list.

Type Parameters:
E - the element type.
Returns:
an empty list.

newList

public <E> List<E> newList(int size)
Returns a sized list.

Type Parameters:
E - the element type.
Parameters:
size - the size.
Returns:
a sized list.

asList

public <E> List<E> asList(Object... object)
Returns a collection, array or objects as a list.

Type Parameters:
E - the element type.
Parameters:
object - the object.
Returns:
a list of itemss.

newBuffer

public StringBuffer newBuffer()
Returns an empty buffer.

Returns:
an empty buffer.

newBuffer

public StringBuffer newBuffer(Object object)
Returns an initialized buffer.

Parameters:
object - the initial object.
Returns:
an initialized buffer.

newByteStream

public OutputStream newByteStream()
Returns a byte stream.

Returns:
an empty byte stream.

newZipStream

public OutputStream newZipStream(OutputStream out)
Returns a zip stream.

Parameters:
out - the output stream.
Returns:
a zip stream.

newZipEntry

public ZipEntry newZipEntry(String path)
Returns a zip entry.

Parameters:
path - the entry path.
Returns:
a zip entry.

newArray

public Object newArray(int length)
Returns an array of the specified size.

Parameters:
length - the length.
Returns:
a new array.

asArray

public Object asArray(Object object)
Returns an object in an array.

Parameters:
object - the object.
Returns:
an array containing the object.

append

public Object append(Object array,
                     Object element)
Appends an element to an array.

Parameters:
array - the array or first element.
element - the element(s).
Returns:
an array of elements.

insert

public Object insert(Object array,
                     int index,
                     Object element)
Inserts an element to an array.

Parameters:
array - the array or first element.
index - the index (-1 = append).
element - the element(s).
Returns:
an array of elements.

toClass

public Class<?> toClass(String className,
                        boolean... options)
Returns the class instance of the named class.

Parameters:
className - the class name to load.
options - to disgard array dimensions and to prefer object classes.
Returns:
the loaded class or null.

toXML

public String toXML(Object object)
Converts an object to an XML encoded string.

Parameters:
object - the object to convert.
Returns:
an XML string or null.

toXML

public String toXML(String className,
                    Object object)
Converts an object to an XML encoded string.

Parameters:
className - the source class name.
object - the object to convert.
Returns:
the converted string.

toXML

public String toXML(String className,
                    Object object,
                    String pattern)
Converts an object to an XML encoded string applying a pattern.

Parameters:
className - the source class name.
object - the object to convert.
pattern - the conversion pattern.
Returns:
the converted string.

fromXML

public String fromXML(Object object)
Converts an XML encoded object to a text string.

Parameters:
object - the object to convert.
Returns:
an XML string.

toPaint

public Paint toPaint(String color)
Converts a named color to a paint.

Parameters:
color - the name of the color.
Returns:
the corresponding paint.

toStroke

public Stroke toStroke(String pattern)
Converts a pattern to a stroke. The pattern is a comma separated list starting with the width followed by dash lenghts.

Parameters:
pattern - the stroke pattern.
Returns:
the corresponding stroke.

cut

public String cut(String str,
                  int max)
Returns a string cut to the specified size.

Parameters:
str - the string.
max - the max length.
Returns:
the cut string.

cut

public String cut(String str,
                  int max,
                  String tail)
Returns a string cut to the specified size. The cut part of the string is replaced by the specified tail.

Parameters:
str - the string.
max - the max length.
tail - an optional tail.
Returns:
the cut string.

wrap

public String wrap(String str)
Returns a string wrapped by linefeeds.

Parameters:
str - the string.
Returns:
the wrapped string.

cite

public String cite(Object obj)
Returns an object within apostrophes.

Parameters:
obj - the object.
Returns:
the cited string.

quote

public String quote(Object obj)
Returns an object within quotation.

Parameters:
obj - the object.
Returns:
the quoted string.

tab

public String tab(int depth)
Returns a tab of the specified depth.

Parameters:
depth - the depth.
Returns:
the tab string.

split

public String[] split(String items,
                      String delims)
Splits the delimited items of a string to an array.

Parameters:
items - the items to convert.
delims - the delimiters to apply.
Returns:
the string array or null.

join

public String join(Object array,
                   String delims)
Joins an array to delimited items to a string.

Parameters:
array - the array to join.
delims - the delimiters to apply.
Returns:
the string of items or null.

escape

public String escape(CharSequence sequence)
Excapes the specified sequence. All control characters and non-Latin characters are escaped.

Parameters:
sequence - the sequence.
Returns:
the escaped string.

escape

public String escape(CharSequence sequence,
                     int limit,
                     String additions)
Escapes the specified sequence with additions. All control characters, characters above the limit and additions are escaped.

Parameters:
sequence - the sequence.
limit - the escaping limit (-1 = unlimited).
additions - a list of additions.
Returns:
the escaped string.

unescape

public String unescape(CharSequence sequence)
Unescapes the specified sequence.

Parameters:
sequence - the sequence.
Returns:
the unescaped string.

unescape

public String unescape(CharSequence sequence,
                       int limit,
                       String exceptions)
Unescapes the specified sequence with exceptions. Characters above the limit and exceptions are not unescaped.

Parameters:
sequence - the sequence.
limit - the escaping limit (-1 = unlimited).
exceptions - a list of exceptions.
Returns:
the unescaped string.

digest

public String digest(String algorithm,
                     String string)
Computes a digest hash.

Parameters:
algorithm - the digest algorithm.
string - the string to use.
Returns:
the encoded hash or null if failed.

digest

public String digest(String algorithm,
                     String string,
                     String encoding)
Computes a digest hash applying the specified encoding.

Parameters:
algorithm - the digest algorithm.
string - the string to use.
encoding - the character encoding.
Returns:
the encoded hash or null if failed.

digest

public String digest(String algorithm,
                     String salt,
                     String string,
                     String encoding)
Computes a digest hash using the given salt and applying the specified encoding.

Parameters:
algorithm - the digest algorithm.
salt - the salt to use.
string - the string to use.
encoding - the character encoding.
Returns:
the encoded hash or null if failed.

printStackTrace

public String printStackTrace(Throwable error)
Prints the stack trace of a throwable.

Parameters:
error - the throwable.
Returns:
the stack trace.


Copyright © 2004 The Norther Organization. All rights reserved.