xsmeral.semnet.util
Class Util

java.lang.Object
  extended by xsmeral.semnet.util.Util

public class Util
extends Object

Various utility methods.


Constructor Summary
Util()
           
 
Method Summary
static
<T> T
nonNull(T... objects)
          Simplifies the following expression:
a !
static Object nonNullObject(Object... objects)
          Non-generic version of nonNull(T...)
static
<T> T
objectFromXml(String xmlFileName, Class<T> cls)
          Deserializes an object from XML file, using XStream
static boolean objectToXml(Object obj, String xmlFileName)
          Serializes an object to XML file, using XStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

nonNull

public static <T> T nonNull(T... objects)
Simplifies the following expression:
  a != null ? a : b != null ? b : c
to
  nonNull(a, b, c)

Type Parameters:
T - Any object type (or primitive (autoboxed))
Parameters:
objects - The objects
Returns:
First non-null object or null, if all are null

nonNullObject

public static Object nonNullObject(Object... objects)
Non-generic version of nonNull(T...)


objectFromXml

public static <T> T objectFromXml(String xmlFileName,
                                  Class<T> cls)
                       throws ConfigurationException
Deserializes an object from XML file, using XStream

Parameters:
xmlFileName - Name of the XML file
cls - The class of the object
Returns:
The deserialized object, or null if the file is not found
Throws:
ConfigurationException

objectToXml

public static boolean objectToXml(Object obj,
                                  String xmlFileName)
Serializes an object to XML file, using XStream

Parameters:
obj - The object to serialize
xmlFileName - Name of the XML file
Returns:
True on success, false otherwise