本文整理了Java中cascading.util.Util.getTypeName()
方法的一些代码示例,展示了Util.getTypeName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getTypeName()
方法的具体详情如下:
包路径:cascading.util.Util
类名称:Util
方法名:getTypeName
暂无
代码示例来源:origin: cwensel/cascading
public static String[] typeNames( Type[] types )
{
String[] names = new String[ types.length ];
for( int i = 0; i < types.length; i++ )
names[ i ] = getTypeName( types[ i ] );
return names;
}
代码示例来源:origin: cascading/lingual-core
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder();
sb.append( "Column" );
sb.append( "{name='" ).append( name ).append( '\'' );
sb.append( ", type=" ).append( Util.getTypeName( type ) );
sb.append( '}' );
return sb.toString();
}
}
代码示例来源:origin: cwensel/cascading
private String getSafeMessage( Object object, int i )
{
try
{
return "field " + sourceFields.get( i ) + " cannot be coerced from : " + object + " to: " + Util.getTypeName( types[ i ] );
}
catch( Throwable throwable )
{
// you may get an exception while composing the message (e.g. ArrayIndexOutOfBoundsException)
// use a generic string
return "field pos " + i + " cannot be coerced from: " + object + ", pos has no corresponding field name or coercion type";
}
}
代码示例来源:origin: cwensel/cascading
private static CoercibleType getInstance( Class<CoercibleType> typeClass )
{
try
{
return typeClass.newInstance();
}
catch( Exception exception )
{
throw new CascadeException( "unable to instantiate class: " + Util.getTypeName( typeClass ) );
}
}
代码示例来源:origin: cwensel/cascading
@Override
public Long canonical( Object value )
{
if( value == null )
return null;
Class from = value.getClass();
if( from == String.class )
return parse( (String) value ).getTime();
if( from == Date.class )
return ( (Date) value ).getTime(); // in UTC
if( from == Long.class || from == long.class )
return (Long) value;
throw new CascadingException( "unknown type coercion requested from: " + Util.getTypeName( from ) );
}
代码示例来源:origin: cwensel/cascading
@Override
public Object coerce( Object value, Type to )
{
if( value == null )
return null;
Class from = value.getClass();
if( from != Long.class )
throw new IllegalStateException( "was not normalized" );
// no coercion, or already in canonical form
if( to == Long.class || to == long.class || to == Object.class || DateType.class == to.getClass() )
return value;
if( to == String.class )
{
Calendar calendar = getCalendar();
calendar.setTimeInMillis( (Long) value );
return getDateFormat().format( calendar.getTime() );
}
throw new CascadingException( "unknown type coercion requested, from: " + Util.getTypeName( from ) + " to: " + Util.getTypeName( to ) );
}
代码示例来源:origin: cascading/lingual-core
@Override
public Object canonical( Object value )
{
if( value == null )
return null;
Class from = value.getClass();
if( from == String.class )
return (int) ( parse( (String) value ).getTimeValue() );
if( Date.class.isAssignableFrom( from ) )
return (int) ( ( (Date) value ).getTime() % MILLIS_PER_DAY ); // in UTC
if( from == Integer.class || from == int.class )
return value;
if( from == Long.class || from == long.class )
return ( (Long) value ).intValue();
throw new CascadingException( "unknown type coercion requested from: " + Util.getTypeName( from ) );
}
代码示例来源:origin: cascading/lingual-core
@Override
public Object canonical( Object value )
{
if( value == null )
return null;
Class from = value.getClass();
if( from == String.class )
return parse( (String) value ).getJdbcTimestamp( DateTimeUtil.defaultZone );
if( Date.class.isAssignableFrom( from ) )
return ( (Date) value ).getTime(); // in UTC
if( from == Long.class || from == long.class )
return value;
throw new CascadingException( "unknown type coercion requested from: " + Util.getTypeName( from ) );
}
代码示例来源:origin: cascading/lingual-core
@Override
public Object canonical( Object value )
{
if( value == null )
return null;
Class from = value.getClass();
if( from == String.class )
{
Calendar calendar = DateTimeUtil.parseDateFormat( (String) value, DateTimeUtil.DateFormatStr, DateTimeUtil.defaultZone );
return truncateDate( calendar.getTimeInMillis() );
}
if( Date.class.isAssignableFrom( from ) )
{
Date fromDate = (Date) value;
return truncateDate( fromDate.getTime() );
}
if( from == Integer.class || from == int.class )
return value;
if( from == Long.class || from == long.class )
return ( (Long) value ).intValue();
throw new CascadingException( "unknown type coercion requested from: " + Util.getTypeName( from ) );
}
代码示例来源:origin: cascading/lingual-core
@Override
public Object coerce( Object value, Type to )
{
if( value == null )
return null;
Class from = value.getClass();
if( from != Integer.class )
throw new IllegalStateException( "was not normalized" );
// no coercion, or already in canonical form
if( to == Integer.class || to == int.class || to == Object.class )
return value;
if( to == Long.class )
return ( (Integer) value ).intValue();
// offset by the current timezone so we get only yyyy-mm-hh precision per the spec for DATE
// Even with a "cast" of DATE to TIMESTAMP the value should be considered "yyyy-mm-hh 00:00:00"
Calendar calendar = Calendar.getInstance();
int timezoneOffset = calendar.get( Calendar.ZONE_OFFSET ) + calendar.get( Calendar.DST_OFFSET );
long shiftedTime = ( ( (Integer) value ).longValue() * MILLIS_PER_DAY ) + timezoneOffset;
ZonelessDatetime date = createInstance();
date.setZonedTime( shiftedTime, DateTimeUtil.defaultZone );
if( to == String.class )
return date.toString();
if( to == java.sql.Date.class )
return new java.sql.Date( date.getJdbcDate( DateTimeUtil.defaultZone ) );
if( to == java.sql.Timestamp.class )
return new java.sql.Timestamp( date.getJdbcTimestamp( DateTimeUtil.defaultZone ) );
if( to == java.sql.Time.class )
return new java.sql.Time( date.getJdbcTime( DateTimeUtil.defaultZone ) );
throw new CascadingException( "unknown type coercion requested, from: " + Util.getTypeName( from ) + " to: " + Util.getTypeName( to ) );
}
代码示例来源:origin: cascading/lingual-core
@Override
public Object coerce( Object value, Type to )
{
if( value == null )
return null;
Class from = value.getClass();
if( from != Long.class )
throw new IllegalStateException( "was not normalized" );
// TIMESTAMP has no timezone precision so set this for the current timezone
long timezoneOffset = TimeZone.getDefault().getOffset( (Long) value );
value = ( (Long) value ) + timezoneOffset;
// no coercion, or already in canonical form
if( to == Long.class || to == long.class || to == Object.class )
return value;
if( to == Integer.class )
return ( (Long) value ).intValue();
ZonelessDatetime date = createInstance();
date.setZonelessTime( (Long) value );
if( to == String.class )
return date.toString();
if( to == java.sql.Date.class )
return new java.sql.Date( date.getJdbcDate( DateTimeUtil.defaultZone ) );
if( to == java.sql.Timestamp.class )
return new java.sql.Timestamp( date.getJdbcTimestamp( DateTimeUtil.defaultZone ) );
if( to == java.sql.Time.class )
return new java.sql.Time( date.getJdbcTime( DateTimeUtil.defaultZone ) );
throw new CascadingException( "unknown type coercion requested, from: " + Util.getTypeName( from ) + " to: " + Util.getTypeName( to ) );
}
代码示例来源:origin: cascading/lingual-core
@Override
public Object coerce( Object value, Type to )
{
if( value == null )
return null;
Class from = value.getClass();
if( from != Integer.class )
throw new IllegalStateException( "was not normalized" );
// no coercion, or already in canonical form
if( to == Integer.class || to == int.class || to == Object.class )
return value;
if( to == Long.class )
return ( (Integer) value ).intValue();
ZonelessDatetime date = createInstance();
date.setZonelessTime( (Integer) value % MILLIS_PER_DAY );
if( to == String.class )
return date.toString();
if( to == java.sql.Date.class )
return new java.sql.Date( date.getJdbcDate( DateTimeUtil.defaultZone ) );
if( to == java.sql.Timestamp.class )
return new java.sql.Timestamp( date.getJdbcTimestamp( DateTimeUtil.defaultZone ) );
if( to == java.sql.Time.class )
return new java.sql.Time( date.getJdbcTime( DateTimeUtil.defaultZone ) );
throw new CascadingException( "unknown type coercion requested, from: " + Util.getTypeName( from ) + " to: " + Util.getTypeName( to ) );
}
}
代码示例来源:origin: cwensel/cascading
return (Coerce) convert( value, (Class) to );
throw new CascadingException( "unknown type coercion requested, from: " + Util.getTypeName( from ) + " to: " + Util.getTypeName( to ) );
内容来源于网络,如有侵权,请联系作者删除!