当前位置: 首页>>代码示例>>Java>>正文


Java Castable类代码示例

本文整理汇总了Java中lucee.runtime.op.Castable的典型用法代码示例。如果您正苦于以下问题:Java Castable类的具体用法?Java Castable怎么用?Java Castable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Castable类属于lucee.runtime.op包,在下文中一共展示了Castable类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toDateAdvanced

import lucee.runtime.op.Castable; //导入依赖的package包/类
/**	
 * converts a Object to a DateTime Object (Advanced but slower)
 * @param o Object to Convert
 * @param timezone
 * @return Date Time Object
 * @throws PageException
 */
public static DateTime toDateAdvanced(Object o,TimeZone timezone) throws PageException {
	if(o instanceof Date) 		{
		if(o instanceof DateTime) return (DateTime)o;
		return new DateTimeImpl((Date)o);
	}
	else if(o instanceof Castable) 	return ((Castable)o).castToDateTime();
	else if(o instanceof String) 	{
	    DateTime dt=toDateAdvanced((String)o,timezone,null);
	    if(dt==null)
			throw new ExpressionException("can't cast ["+o+"] to date value");
	    return dt;
	}
	else if(o instanceof Number) 		return util.toDateTime(((Number)o).doubleValue());
	else if(o instanceof ObjectWrap) return toDateAdvanced(((ObjectWrap)o).getEmbededObject(),timezone);
	else if(o instanceof Calendar){
		
		return new DateTimeImpl((Calendar)o);
	}
	throw new ExpressionException("can't cast ["+Caster.toClassName(o)+"] to date value");
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:28,代码来源:DateCaster.java

示例2: toDateSimple

import lucee.runtime.op.Castable; //导入依赖的package包/类
/**
 * converts a Object to a DateTime Object, returns null if invalid string
 * @param o Object to Convert
 * @param convertingType one of the following values:
 * - CONVERTING_TYPE_NONE: number are not converted at all
 * - CONVERTING_TYPE_YEAR: integers are handled as years
 * - CONVERTING_TYPE_OFFSET: numbers are handled as offset from 1899-12-30 00:00:00 UTC
 * @param timeZone
 * @return coverted Date Time Object
 * @throws PageException
 */
public static DateTime toDateSimple(Object o, short convertingType,boolean alsoMonthString, TimeZone timeZone) throws PageException {
	if(o instanceof DateTime) 		return (DateTime)o;
	else if(o instanceof Date) 		return new DateTimeImpl((Date)o);
	else if(o instanceof Castable) 	return ((Castable)o).castToDateTime();
	else if(o instanceof String) 	return toDateSimple(o.toString(),convertingType,alsoMonthString, timeZone);
	else if(o instanceof Number) 		return util.toDateTime(((Number)o).doubleValue());
	else if(o instanceof Calendar) 		return new DateTimeImpl((Calendar)o);
	else if(o instanceof ObjectWrap) return toDateSimple(((ObjectWrap)o).getEmbededObject(),convertingType,alsoMonthString,timeZone);
	else if(o instanceof Calendar){
		return new DateTimeImpl((Calendar)o);
	}
	
	if(o instanceof Component)
		throw new ExpressionException("can't cast component ["+((Component)o).getAbsName()+"] to date value");
	
	throw new ExpressionException("can't cast ["+Caster.toTypeName(o)+"] to date value");
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:29,代码来源:DateCaster.java

示例3: toTime

import lucee.runtime.op.Castable; //导入依赖的package包/类
/**
 * converts a Object to a Time Object, returns null if invalid string
 * @param o Object to Convert
 * @return coverted Date Time Object
 * @throws PageException
 */
public static Time toTime(TimeZone timeZone,Object o) throws PageException {
    if(o instanceof Time) 		return (Time)o;
    else if(o instanceof Date) 		return new TimeImpl((Date)o);
	else if(o instanceof Castable) 	return new TimeImpl(((Castable)o).castToDateTime());
	else if(o instanceof String) 	{
	    Time dt=toTime(timeZone,o.toString(),null);
	    if(dt==null)
			throw new ExpressionException("can't cast ["+o+"] to time value");
	    return dt;
	}
	else if(o instanceof ObjectWrap) return toTime(timeZone,((ObjectWrap)o).getEmbededObject());
	else if(o instanceof Calendar){
		// TODO check timezone offset
		return new TimeImpl(((Calendar)o).getTimeInMillis(),false);
	}
	throw new ExpressionException("can't cast ["+Caster.toClassName(o)+"] to time value");
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:24,代码来源:DateCaster.java

示例4: _toDateAdvanced

import lucee.runtime.op.Castable; //导入依赖的package包/类
private static DateTime _toDateAdvanced(Object o,short convertingType, TimeZone timeZone, DateTime defaultValue, boolean advanced) {
      if(o instanceof DateTime)       return (DateTime)o;
      else if(o instanceof Date)      return new DateTimeImpl((Date)o);
      else if(o instanceof Castable)  {
          return ((Castable)o).castToDateTime(defaultValue);
      }
      else if(o instanceof String)    {
      	if(advanced)return toDateAdvanced(o.toString(),convertingType, timeZone,defaultValue);
      	return toDateSimple(o.toString(),convertingType,true, timeZone,defaultValue);
      }
      else if(o instanceof Number){
      	return numberToDate(timeZone, ((Number)o).doubleValue(), convertingType, defaultValue);
      }
      else if(o instanceof ObjectWrap) {
      	return _toDateAdvanced(((ObjectWrap)o).getEmbededObject(defaultValue),convertingType,timeZone,defaultValue,advanced);
      }
      else if(o instanceof Calendar){
	return new DateTimeImpl((Calendar)o);
}
return defaultValue;
  }
 
开发者ID:lucee,项目名称:Lucee4,代码行数:22,代码来源:DateCaster.java

示例5: _toDateAdvanced

import lucee.runtime.op.Castable; //导入依赖的package包/类
private static DateTime _toDateAdvanced(Object o,short convertingType, TimeZone timeZone, DateTime defaultValue, boolean advanced) {
      if(o instanceof DateTime)       return (DateTime)o;
      else if(o instanceof Date)      return new DateTimeImpl((Date)o);
      else if(o instanceof Castable)  {
          return ((Castable)o).castToDateTime(defaultValue);
      }
      else if(o instanceof String)    {
      	if (advanced)
      		return toDateAdvanced(o.toString(), convertingType, timeZone, defaultValue);

      	return toDateSimple(o.toString(),convertingType,true, timeZone,defaultValue);
      }
      else if(o instanceof Number){
      	return numberToDate(timeZone, ((Number)o).doubleValue(), convertingType, defaultValue);
      }
      else if(o instanceof ObjectWrap) {
      	return _toDateAdvanced(((ObjectWrap)o).getEmbededObject(defaultValue),convertingType,timeZone,defaultValue,advanced);
      }
      else if(o instanceof Calendar){
	return new DateTimeImpl((Calendar)o);
}
return defaultValue;
  }
 
开发者ID:lucee,项目名称:Lucee,代码行数:24,代码来源:DateCaster.java


注:本文中的lucee.runtime.op.Castable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。