com.senn.magic.util
Class GeneralUtils

java.lang.Object
  extended by com.senn.magic.util.GeneralUtils

public final class GeneralUtils
extends Object

This class contains useful methods like conversion from an array to a List, etc.

Since:
2.0
Author:
Bart Thierens
Last modification: 23/01/2011

Method Summary
static
<S> boolean
addIfNotNull(Collection<S> collection, S o)
          Method that adds an object to a Collection if that object is not null.
static
<S> ArrayList<S>
asArrayList(S[] array)
          Generic method to create an ArrayList of an array of objects.
static boolean canBeBoolean(String value)
          Checks if a String value can be cast to a an int or Integer
static boolean canBeByte(String value)
          Checks if a String value can be cast to a byte or Byte
static boolean canBeDouble(String value)
          Checks if a String value can be cast to a double or Double
static boolean canBeFloat(String value)
          Checks if a String value can be cast to a float or Float
static boolean canBeInteger(String value)
          Checks if a String value can be cast to an int or Integer
static boolean canBeLong(String value)
          Checks if a String value can be cast to a long or Long
static boolean canBeShort(String value)
          Checks if a String value can be cast to a short or Short
static
<S extends OutputStream>
S
convertToOutputStream(InputStream in, Class<S> outClass)
          Generic method that converts an InputStream to an OutputStream of choice.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asArrayList

public static <S> ArrayList<S> asArrayList(S[] array)
Generic method to create an ArrayList of an array of objects.
Java provides a method to create arrays from List, but not the other way around.
So here it is!

Parameters:
array - an array containing your items
Returns:
ArrayList - an ArrayList containing your items.

canBeInteger

public static boolean canBeInteger(String value)
Checks if a String value can be cast to an int or Integer

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

canBeLong

public static boolean canBeLong(String value)
Checks if a String value can be cast to a long or Long

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

canBeDouble

public static boolean canBeDouble(String value)
Checks if a String value can be cast to a double or Double

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

canBeShort

public static boolean canBeShort(String value)
Checks if a String value can be cast to a short or Short

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

canBeFloat

public static boolean canBeFloat(String value)
Checks if a String value can be cast to a float or Float

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

canBeByte

public static boolean canBeByte(String value)
Checks if a String value can be cast to a byte or Byte

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

canBeBoolean

public static boolean canBeBoolean(String value)
Checks if a String value can be cast to a an int or Integer

Parameters:
value -
Returns:
boolean - true if it's possible, false if not

convertToOutputStream

public static <S extends OutputStream> S convertToOutputStream(InputStream in,
                                                               Class<S> outClass)
                                                    throws Exception
Generic method that converts an InputStream to an OutputStream of choice.
Method is not guaranteed to work for every type of OutputStream.

Parameters:
in - an instance of any subclass of InputStream
outClass - a subclass of OutputStream
Returns:
- an instance of the subclass provided containing your data
Throws:
Exception

addIfNotNull

public static <S> boolean addIfNotNull(Collection<S> collection,
                                       S o)
Method that adds an object to a Collection if that object is not null.

Parameters:
collection - the collection to add the item to
o - the item to add if not null
Returns:
boolean - true if the item was not null and it was successfully added to the collection, false if the item was null or if it could not be added to the collection