code: public static <T> T castOrNull(Object o, Class<T> cls)
  	{
  		if(o == null)
  			return null;
  		if(cls.isInstance(o))
  			return cls.cast(o);
  		return null;
  	}
docs: Cast object to class or return null.
  @param o The object to cast
  @param cls The class to cast o to
  @return o cast as cls. null if o is null or not a instance of cls.