Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jboss.portal.common.util
Class Tools

    java.lang.Object
      org.jboss.portal.common.util.Tools

    public class Tools

extends java.lang.Object

Version:
  $Revision: 7377 $
Author:
  Julien Viet, Thomas Heute, Boleslaw Dawidowicz, Chris Laprun

Field Summary
`static int` | `DEFAULT_BUFFER_SIZE`
`static java.util.ResourceBundle` | `EMPTY_BUNDLE`
`static java.util.Enumeration` | `EMPTY_ENUMERATION`
`static java.util.Iterator` | `EMPTY_ITERATOR`
`static org.apache.log4j.Logger` | `log`
`static java.lang.String` | `VMID` 16 chars long VMID.

Constructor Summary
`Tools()`

Method Summary
`static
`<E> E[]`
` | `appendTo(E[] array, E o)` Append an object to an array of objects.
`static java.lang.String` | `buildClassLoaderInfo(java.lang.ClassLoader loader)`
`static int` | `computeStringHash(int hash, java.lang.String s)`
`static boolean` | `confirmTemporaryHash(java.lang.String hash, java.lang.String value, long time)`
`static java.lang.String` | `dumpClassLoaderHierarchyInfo(java.lang.ClassLoader loader)`
`static void` | `dumpClassLoaderHierarchyInfo(org.apache.log4j.Logger log, java.lang.ClassLoader loader)`
`static void` | `dumpClassLoaderHierarchyInfo(org.apache.log4j.Logger log, org.apache.log4j.Level level, java.lang.ClassLoader loader)`
`static void` | `dumpClassLoaderHierarchyInfo(java.io.Writer writer, java.lang.ClassLoader loader)`
`static byte[]` | `fromHexString(java.lang.String hex)` Returns a byte array converted from the hexadecimal format.
`static java.lang.String` | `generateTemporaryHash(java.lang.String value, long time)`
`static java.lang.String` | `getPackageOf(java.lang.Class clazz)`
`static java.lang.String` | `getShortNameOf(java.lang.Class clazz)`
`static java.lang.String` | `hashAndEncodeString(java.lang.String text, java.lang.String algorithm, java.lang.String encoding)` Computes a hash with specified algorighm and returns the result as a string in hexadecimal format
`static boolean` | `isContainedIn(java.lang.Object value, java.lang.Object[] array)` Determines if value is contained in array.
`static
`<E> java.util.Iterator<E>`
` | `iterator(E... objects)` Returns an iterator over the array elements.
`static
`<E> java.util.Iterator<E>`
` | `iterator(E o)` Returns a singleton iterator.
`static
`<E> java.util.Iterator<E>`
` | `iterator(E[] objects, int from, int to)` Returns an iterator over the array elements within the specified range.
`static byte[]` | `md5(java.lang.String text)` Computes an md5 hash of a string.
`static java.lang.String` | `md5AsHexString(java.lang.String text)` Computes an md5 hash and returns the result as a string in hexadecimal format.
`static java.lang.String` | `replace(java.lang.String string, java.lang.String pattern, java.lang.String replacement)` Replace occurence in a string.
`static java.lang.String` | `replaceAllInstancesOfBoundedString(java.lang.String initial, java.lang.String prefix, java.lang.String suffix, java.lang.String replacement)`
`static java.lang.String` | `replaceBoundedString(java.lang.String initial, java.lang.String prefix, java.lang.String suffix, java.lang.String replacement, boolean replaceIfBoundedStringEmpty, boolean keepBoundaries)` Todo : define what "bounded" means.
`static boolean` | `safeEquals(java.lang.Object o1, java.lang.Object o2)` Return true if o1 is null and o2 is nullequals(Object o) on o1 wit o2 as argument returns true
`static java.lang.Object[]` | `toArray(java.util.Iterator i)` Deprecated.
`static
`<E> java.util.Enumeration<E>`
` | `toEnumeration(E o)`
`static
`<E> java.util.Enumeration<E>`
` | `toEnumeration(E[] objects)`
`static
`<E> java.util.Enumeration<E>`
` | `toEnumeration(java.util.Iterator<E> iterator)`
`static java.lang.String` | `toHexString(byte[] bytes)` Returns a string in the hexadecimal format.
`static
`<E> java.util.List<E>`
` | `toList(E... objects)`
`static
`<E> java.util.List<E>`
` | `toList(java.util.Enumeration<E> e)`
`static
`<E> java.util.List<E>`
` | `toList(java.util.Iterator<E> iterator)`
`static
`<E> java.util.Set<E>`
` | `toSet(E... objects)`
`static
`<E> java.util.Set<E>`
` | `toSet(java.util.Enumeration<E> e)`
`static
`<E> java.util.Set<E>`
` | `toSet(java.util.Iterator<E> iterator)` Transforms an iterator into an unordered Set
`static
`<E> java.util.Set<E>`
` | `toSet(java.util.Iterator<E> iterator, boolean preserveOrder)` Transforms an iterator into a Set

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_BUFFER_SIZE

    public static final int DEFAULT_BUFFER_SIZE

See Also:
  Constant Field Values

### log

    public static final org.apache.log4j.Logger log

### VMID

    public static final java.lang.String VMID

  16 chars long VMID.

### EMPTY_ENUMERATION

    public static final java.util.Enumeration EMPTY_ENUMERATION

### EMPTY_ITERATOR

    public static final java.util.Iterator EMPTY_ITERATOR

### EMPTY_BUNDLE

    public static final java.util.ResourceBundle EMPTY_BUNDLE

Constructor Detail

### Tools

    public Tools()

Method Detail

### toEnumeration

    public static <E> java.util.Enumeration<E> toEnumeration(java.util.Iterator<E> iterator)

### toEnumeration

    public static <E> java.util.Enumeration<E> toEnumeration(E[] objects)

### toEnumeration

    public static <E> java.util.Enumeration<E> toEnumeration(E o)

### toSet

    public static <E> java.util.Set<E> toSet(java.util.Enumeration<E> e)

### toSet

    public static <E> java.util.Set<E> toSet(E... objects)

### toSet

    public static <E> java.util.Set<E> toSet(java.util.Iterator<E> iterator)

  Transforms an iterator into an unordered Set

  Parameters:
    `iterator` - The iterator to transform
  Returns:
    A HashSet

### toSet

    public static <E> java.util.Set<E> toSet(java.util.Iterator<E> iterator,
                                             boolean preserveOrder)

  Transforms an iterator into a Set

  Parameters:
    `iterator` - The iterator to transform
    `preserveOrder` - true if the set must respect the ordering of the iterator
  Returns:
    a LinkedHashSet if ordered is true, a HashSet otherwise

### toList

    public static <E> java.util.List<E> toList(java.util.Enumeration<E> e)

### toList

    public static <E> java.util.List<E> toList(java.util.Iterator<E> iterator)

### toList

    public static <E> java.util.List<E> toList(E... objects)

### toArray

    @Deprecated
    public static java.lang.Object[] toArray(java.util.Iterator i)

  Deprecated.

  Consider remove this method as it cannot be generified.

  Parameters:
    `i` -
  Returns:

### iterator

    public static <E> java.util.Iterator<E> iterator(E o)

  Returns a singleton iterator.

  Parameters:
    `o` - the singleton object
  Returns:
    the iterator

### iterator

    public static <E> java.util.Iterator<E> iterator(E... objects)
                                          throws java.lang.IllegalArgumentException

  Returns an iterator over the array elements.

  Parameters:
    `objects` - the array containing the objects to iterate on
  Returns:
    the iterator
  Throws:
    `java.lang.IllegalArgumentException` - if the object array is null or the specified range is not valid

### iterator

    public static <E> java.util.Iterator<E> iterator(E[] objects,
                                                     int from,
                                                     int to)
                                          throws java.lang.IllegalArgumentException

  Returns an iterator over the array elements within the specified range. The range is considered as valid if the from argument is greater or equals than zero, the to argument is lesser or equals than array size and the from argument is lesser or equals to the to argument.

  Parameters:
    `objects` - the array containing the objects to iterate on
    `from` - the inclusive start index
    `to` - the exclusive stop index
  Returns:
    the iterator
  Throws:
    `java.lang.IllegalArgumentException` - if the object array is null or the specified range is not valid or if the range is not valid

### computeStringHash

    public static int computeStringHash(int hash,
                                        java.lang.String s)

### md5

    public static byte[] md5(java.lang.String text)

  Computes an md5 hash of a string.

  Parameters:
    `text` - the hashed string
  Returns:
    the string hash
  Throws:
    `java.lang.NullPointerException` - if text is null

### md5AsHexString

    public static java.lang.String md5AsHexString(java.lang.String text)

  Computes an md5 hash and returns the result as a string in hexadecimal format.

  Parameters:
    `text` - the hashed string
  Returns:
    the string hash
  Throws:
    `java.lang.NullPointerException` - if text is null

### hashAndEncodeString

    public static java.lang.String hashAndEncodeString(java.lang.String text,
                                                       java.lang.String algorithm,
                                                       java.lang.String encoding)
                                                throws java.security.NoSuchAlgorithmException

  Computes a hash with specified algorighm and returns the result as a string in hexadecimal format

  Parameters:
    `text` -
    `algorithm` -
    `encoding` -
  Returns:
  Throws:
    `java.security.NoSuchAlgorithmException`

### toHexString

    public static java.lang.String toHexString(byte[] bytes)

  Returns a string in the hexadecimal format.

  Parameters:
    `bytes` - the converted bytes
  Returns:
    the hexadecimal string representing the bytes data
  Throws:
    `java.lang.IllegalArgumentException` - if the byte array is null

### fromHexString

    public static byte[] fromHexString(java.lang.String hex)

  Returns a byte array converted from the hexadecimal format.

  Parameters:
    `hex` - the string to convert
  Returns:
    the byte array corresponding
  Throws:
    `java.lang.IllegalArgumentException` - if the string is null or does not have the good format

### generateTemporaryHash

    public static java.lang.String generateTemporaryHash(java.lang.String value,
                                                         long time)

### confirmTemporaryHash

    public static boolean confirmTemporaryHash(java.lang.String hash,
                                               java.lang.String value,
                                               long time)

### getShortNameOf

    public static java.lang.String getShortNameOf(java.lang.Class clazz)

### getPackageOf

    public static java.lang.String getPackageOf(java.lang.Class clazz)

### buildClassLoaderInfo

    public static java.lang.String buildClassLoaderInfo(java.lang.ClassLoader loader)

### dumpClassLoaderHierarchyInfo

    public static java.lang.String dumpClassLoaderHierarchyInfo(java.lang.ClassLoader loader)

### dumpClassLoaderHierarchyInfo

    public static void dumpClassLoaderHierarchyInfo(java.io.Writer writer,
                                                    java.lang.ClassLoader loader)

### dumpClassLoaderHierarchyInfo

    public static void dumpClassLoaderHierarchyInfo(org.apache.log4j.Logger log,
                                                    java.lang.ClassLoader loader)

### dumpClassLoaderHierarchyInfo

    public static void dumpClassLoaderHierarchyInfo(org.apache.log4j.Logger log,
                                                    org.apache.log4j.Level level,
                                                    java.lang.ClassLoader loader)

### replace

    public static java.lang.String replace(java.lang.String string,
                                           java.lang.String pattern,
                                           java.lang.String replacement)

  Replace occurence in a string.

  Parameters:
    `string` - the source string
    `pattern` - the replaced pattern
    `replacement` - the replacement text
  Returns:
    the new string

### appendTo

    public static <E> E[] appendTo(E[] array,
                                   E o)
                        throws java.lang.IllegalArgumentException,
                               java.lang.ClassCastException

  Append an object to an array of objects. The original array is not modified. The returned array will be of the same component type of the provided array and its first n elements where n is the size of the provided array will be the elements of the provided array. The last element of the array will be the provided object to append.

  Parameters:
    `array` - the array to augment
    `o` - the object to append
  Returns:
    a new array
  Throws:
    `java.lang.IllegalArgumentException` - if the array is null
    `java.lang.ClassCastException` - if the appended object class prevents it from being added to the array

### safeEquals

    public static boolean safeEquals(java.lang.Object o1,
                                     java.lang.Object o2)

  Return true if
  - o1 is null and o2 is nullo1 is not null and the invocation of `equals(Object o)` on o1 wit o2 as argument returns true

  Parameters:
    `o1` - the first argument
    `o2` - the second argument
  Returns:
    if arguments are equals according to the semantic defined by the method contract

### replaceAllInstancesOfBoundedString

    public static java.lang.String replaceAllInstancesOfBoundedString(java.lang.String initial,
                                                                      java.lang.String prefix,
                                                                      java.lang.String suffix,
                                                                      java.lang.String replacement)

### replaceBoundedString

    public static java.lang.String replaceBoundedString(java.lang.String initial,
                                                        java.lang.String prefix,
                                                        java.lang.String suffix,
                                                        java.lang.String replacement,
                                                        boolean replaceIfBoundedStringEmpty,
                                                        boolean keepBoundaries)

  Todo : define what "bounded" means.

  Parameters:
    `initial` -
    `prefix` -
    `suffix` -
    `replacement` -
    `replaceIfBoundedStringEmpty` -
    `keepBoundaries` -
  Returns:

### isContainedIn

    public static boolean isContainedIn(java.lang.Object value,
                                        java.lang.Object[] array)

  Determines if value is contained in array. todo: correct this method contract in order to make it more reusable, it looks like for now like a method which has a contract convenient only for some kind of callers. 1/ null value should be accepted (or the method should be called isContainedInButNotForNullValue ?) 2/ null array should not be accepted (or the method should be called isContainedInExceptIfThePassedArrayIsNull ?)

  Parameters:
    `value` -
    `array` -
  Returns:
  Since:
    2.4.2

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD