org.pentaho.di.core.Const.trimToType()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中org.pentaho.di.core.Const.trimToType()方法的一些代码示例,展示了Const.trimToType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Const.trimToType()方法的具体详情如下:
包路径:org.pentaho.di.core.Const
类名称:Const
方法名:trimToType

Const.trimToType介绍

[英]Return the input string trimmed as specified.
[中]返回按指定修剪的输入字符串。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

protected synchronized Long convertStringToInteger( String string ) throws KettleValueException {
 string = Const.trimToType( string, getTrimType() ); // see if trimming needs
 // to be performed before
 // conversion
 if ( Utils.isEmpty( string ) ) {
  return null;
 }
 try {
  Number number;
  if ( lenientStringToNumber ) {
   number = new Long( getDecimalFormat( false ).parse( string ).longValue() );
  } else {
   ParsePosition parsePosition = new ParsePosition( 0 );
   number = getDecimalFormat( false ).parse( string, parsePosition );
   if ( parsePosition.getIndex() < string.length() ) {
    throw new KettleValueException( toString()
      + " : couldn't convert String to number : non-numeric character found at position "
      + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" );
   }
  }
  return new Long( number.longValue() );
 } catch ( Exception e ) {
  throw new KettleValueException( toString() + " : couldn't convert String to Integer", e );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

protected synchronized InetAddress convertStringToInternetAddress( String string ) throws KettleValueException {
 // See if trimming needs to be performed before conversion
 //
 string = Const.trimToType( string, getTrimType() );
 if ( Utils.isEmpty( string ) ) {
  return null;
 }
 try {
  return InetAddress.getByName( string );
 } catch ( Exception e ) {
  throw new KettleValueException( toString()
   + " : couldn't convert string [" + string + "] to an internet address", e );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

protected synchronized Double convertStringToNumber( String string ) throws KettleValueException {
 string = Const.trimToType( string, getTrimType() ); // see if trimming needs
 // to be performed before
 // conversion
 if ( Utils.isEmpty( string ) ) {
  return null;
 }
 try {
  DecimalFormat format = getDecimalFormat( false );
  Number number;
  if ( lenientStringToNumber ) {
   number = format.parse( string );
  } else {
   ParsePosition parsePosition = new ParsePosition( 0 );
   number = format.parse( string, parsePosition );
   if ( parsePosition.getIndex() < string.length() ) {
    throw new KettleValueException( toString()
      + " : couldn't convert String to number : non-numeric character found at position "
      + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" );
   }
  }
  return new Double( number.doubleValue() );
 } catch ( Exception e ) {
  throw new KettleValueException( toString() + " : couldn't convert String to number ", e );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

protected synchronized BigDecimal convertStringToBigNumber( String string ) throws KettleValueException {
 string = Const.trimToType( string, getTrimType() ); // see if trimming needs

代码示例来源:origin: pentaho/pentaho-kettle

protected synchronized Timestamp convertStringToTimestamp( String string ) throws KettleValueException {
 // See if trimming needs to be performed before conversion
 //
 string = Const.trimToType( string, getTrimType() );
 if ( Utils.isEmpty( string ) ) {
  return null;
 }
 Timestamp returnValue;
 try {
  returnValue = Timestamp.valueOf( string );
 } catch ( IllegalArgumentException e ) {
  try {
   returnValue = (Timestamp) getDateFormat().parse( string );
  } catch ( ParseException ex ) {
   throw new KettleValueException( toString() + " : couldn't convert string [" + string
     + "] to a timestamp, expecting format [yyyy-mm-dd hh:mm:ss.ffffff]", e );
  }
 }
 return returnValue;
}

代码示例来源:origin: pentaho/pentaho-kettle

protected synchronized Date convertStringToDate( String string ) throws KettleValueException {
 string = Const.trimToType( string, getTrimType() ); // see if trimming needs
 // to be performed before
 // conversion
 if ( Utils.isEmpty( string ) ) {
  return null;
 }
 try {
  ParsePosition pp = new ParsePosition( 0 );
  Date result = getDateFormat( TYPE_DATE ).parse( string, pp );
  if ( pp.getErrorIndex() >= 0 ) {
   // error happen
   throw new ParseException( string, pp.getErrorIndex() );
  }
  // some chars can be after pp.getIndex(). That means, not full value was parsed. For example, for value
  // "25-03-1918 11:54" and format "dd-MM-yyyy", value will be "25-03-1918 00:00" without any exception.
  // If there are only spaces after pp.getIndex() - that means full values was parsed
  return result;
 } catch ( ParseException e ) {
  String dateFormat = ( getDateFormat() != null ) ? getDateFormat().toPattern() : "null";
  throw new KettleValueException( toString() + " : couldn't convert string [" + string
    + "] to a date using format [" + dateFormat + "] on offset location " + e.getErrorOffset(), e );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private byte[] formatField( ValueMetaInterface v, Object valueData ) throws KettleValueException {
 if ( v.isString() ) {
  if ( v.isStorageBinaryString() && v.getTrimType() == ValueMetaInterface.TRIM_TYPE_NONE && v.getLength() < 0
    && Utils.isEmpty( v.getStringEncoding() ) ) {
   return (byte[]) valueData;
  } else {
   String svalue = ( valueData instanceof String ) ? (String) valueData : v.getString( valueData );
   return convertStringToBinaryString( v, Const.trimToType( svalue, v.getTrimType() ) );
  }
 } else {
  return v.getBinaryString( valueData );
 }
}

相关文章