當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。