Class BasicFieldTransformer


public class BasicFieldTransformer extends FieldTransformer
See FieldPath for supported field name expressions.
  • Constructor Details

    • BasicFieldTransformer

      public BasicFieldTransformer(String... names)
    • BasicFieldTransformer

      public BasicFieldTransformer(Collection<String> names)
    • BasicFieldTransformer

      public BasicFieldTransformer(String name)
  • Method Details

    • isContinueOnException

      public boolean isContinueOnException()
      Indicates if exceptions thrown by operations are ignored so the remaining operations still run; the last one is kept in getException() (default is false).
    • setContinueOnException

      public BasicFieldTransformer setContinueOnException(boolean continueOnException)
      Indicates if exceptions thrown by operations are ignored so the remaining operations still run; the last one is kept in getException() (default is false).
    • getException

      public Throwable getException()
      Returns the last exception an operation threw on the most recently transformed field or null if none did.
    • add

      Appends operations that run, in the order added, on each named field.
    • transformField

      protected void transformField(Field field) throws Throwable
      Description copied from class: FieldTransformer
      Transforms the given field in place; called for each named field found in the record.
      Specified by:
      transformField in class FieldTransformer
      Throws:
      Throwable
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Transformer
      Adds this transformer's details to an exception raised by its host reader or writer; returns the same exception.
      Overrides:
      addExceptionProperties in class FieldTransformer
    • valueToString

      public BasicFieldTransformer valueToString()
    • nullToValue

      public BasicFieldTransformer nullToValue(String value)
      Replaces null values with the given string.
    • nullToValue

      public BasicFieldTransformer nullToValue(Date value)
      Replaces null values with the given date-time.
    • nullToValue

      public BasicFieldTransformer nullToValue(Date value)
      Replaces null values with the given date.
    • nullToValue

      public BasicFieldTransformer nullToValue(Time value)
      Replaces null values with the given time.
    • nullToValue

      public BasicFieldTransformer nullToValue(int value)
      Replaces null values with the given int.
    • nullToValue

      public BasicFieldTransformer nullToValue(long value)
      Replaces null values with the given long.
    • nullToValue

      public BasicFieldTransformer nullToValue(BigInteger value)
      Replaces null values with the given big integer.
    • nullToValue

      public BasicFieldTransformer nullToValue(short value)
      Replaces null values with the given short.
    • nullToValue

      public BasicFieldTransformer nullToValue(byte value)
      Replaces null values with the given byte.
    • nullToValue

      public BasicFieldTransformer nullToValue(boolean value)
      Replaces null values with the given boolean.
    • nullToValue

      public BasicFieldTransformer nullToValue(char value)
      Replaces null values with the given character.
    • nullToValue

      public BasicFieldTransformer nullToValue(BigDecimal value)
      Replaces null values with the given big decimal.
    • nullToValue

      public BasicFieldTransformer nullToValue(double value)
      Replaces null values with the given double.
    • nullToValue

      public BasicFieldTransformer nullToValue(float value)
      Replaces null values with the given float.
    • nullToValue

      public BasicFieldTransformer nullToValue(byte[] value)
      Replaces null values with the given bytes.
    • nullToValue

      public BasicFieldTransformer nullToValue(Instant value)
      Replaces null values with the given instant.
    • nullToValue

      public BasicFieldTransformer nullToValue(LocalDateTime value)
      Replaces null values with the given local date-time.
    • nullToValue

      public BasicFieldTransformer nullToValue(LocalDate value)
      Replaces null values with the given local date.
    • nullToValue

      public BasicFieldTransformer nullToValue(LocalTime value)
      Replaces null values with the given local time.
    • nullToExpression

      public BasicFieldTransformer nullToExpression(String expressionAsString)
      Replaces null values with the result of the given expression, evaluated against the current record.
    • lowerCase

      public BasicFieldTransformer lowerCase()
      Converts values to lower case using the default locale.
    • upperCase

      public BasicFieldTransformer upperCase()
      Converts values to upper case using the default locale.
    • lowerCaseFirstChar

      public BasicFieldTransformer lowerCaseFirstChar()
      Converts the first character of each value to lower case, leaving the rest unchanged.
    • upperCaseFirstChar

      public BasicFieldTransformer upperCaseFirstChar()
      Converts the first character of each value to upper case, leaving the rest unchanged.
    • trim

      public BasicFieldTransformer trim()
      Removes leading and trailing characters up to and including U+0020 (the space), such as tabs and line breaks.
    • trimLeft

      public BasicFieldTransformer trimLeft()
      Removes leading characters up to and including U+0020 (the space), such as tabs and line breaks.
    • trimRight

      public BasicFieldTransformer trimRight()
      Removes trailing characters up to and including U+0020 (the space), such as tabs and line breaks.
    • trimLeft

      public BasicFieldTransformer trimLeft(char padChar)
      Removes all leading occurrences of the given character.
    • trimRight

      public BasicFieldTransformer trimRight(char padChar)
      Removes all trailing occurrences of the given character.
    • padLeft

      public BasicFieldTransformer padLeft(int length, char padChar)
      Pads values on the left with padChar up to length characters; longer values are unchanged and null values are padded as empty strings.
    • padRight

      public BasicFieldTransformer padRight(int length, char padChar)
      Pads values on the right with padChar up to length characters; longer values are unchanged and null values are padded as empty strings.
    • left

      public BasicFieldTransformer left(int length)
      Keeps the first length characters of each value; shorter values are unchanged.
    • right

      public BasicFieldTransformer right(int length)
      Keeps the last length characters of each value; shorter values are unchanged.
    • substring

      public BasicFieldTransformer substring(int begin, int end)
      Keeps the characters from the 0-based begin (inclusive) to end (exclusive); values shorter than end become empty strings.
    • substring

      public BasicFieldTransformer substring(int begin)
      Keeps the characters from the 0-based begin to the end; values shorter than begin become empty strings.
    • append

      public BasicFieldTransformer append(String suffix)
      Appends suffix to each value, treating null values as empty strings.
    • prepend

      public BasicFieldTransformer prepend(String prefix)
      Prepends prefix to each value, treating null values as empty strings.
    • insert

      public BasicFieldTransformer insert(int index, String text)
      Inserts text at the 0-based index, or appends it if the value is not longer than index.
    • delete

      public BasicFieldTransformer delete(int start, int end)
      Removes the characters from the 0-based start (inclusive) to end (exclusive, capped at the value's length).
    • replace

      public BasicFieldTransformer replace(int start, int end, String string)
      Replaces the characters from the 0-based start (inclusive) to end (exclusive, capped at the value's length) with string.
    • replaceChar

      public BasicFieldTransformer replaceChar(char oldChar, char newChar)
      Replaces every occurrence of oldChar with newChar.
    • replaceString

      public BasicFieldTransformer replaceString(CharSequence oldString, CharSequence newString)
      Replaces every literal (non-regex) occurrence of oldString with newString.
    • replaceAll

      public BasicFieldTransformer replaceAll(CharSequence regex, CharSequence replacement)
      Replaces every match of the regular expression regex with replacement ($n refers to a captured group).
    • replaceFirst

      public BasicFieldTransformer replaceFirst(CharSequence regex, CharSequence replacement)
      Replaces the first match of the regular expression regex with replacement ($n refers to a captured group).
    • stringToByte

      public BasicFieldTransformer stringToByte()
      Parses values as bytes using Byte.valueOf.
    • stringToShort

      public BasicFieldTransformer stringToShort()
      Parses values as shorts using Short.valueOf.
    • stringToInt

      public BasicFieldTransformer stringToInt()
      Parses values as ints using Integer.valueOf.
    • stringToLong

      public BasicFieldTransformer stringToLong()
      Parses values as longs using Long.valueOf.
    • stringToBigInteger

      public BasicFieldTransformer stringToBigInteger()
      Parses values as big integers using new BigInteger(String).
    • stringToBigDecimal

      public BasicFieldTransformer stringToBigDecimal()
      Parses values as big decimals using new BigDecimal(String).
    • stringToDouble

      public BasicFieldTransformer stringToDouble()
      Parses values as doubles using Double.valueOf.
    • stringToDouble

      public BasicFieldTransformer stringToDouble(DecimalFormat format)
      Parses values as doubles using the given DecimalFormat.
    • stringToDouble

      public BasicFieldTransformer stringToDouble(String pattern)
      Parses values as doubles using a DecimalFormat with the given pattern.
    • stringToFloat

      public BasicFieldTransformer stringToFloat()
      Parses values as floats using Float.valueOf.
    • stringToBoolean

      public BasicFieldTransformer stringToBoolean()
      Converts the string "true" (ignoring case) to true and any other value to false.
    • stringToBoolean

      public BasicFieldTransformer stringToBoolean(boolean lenient)
      Converts a string to a boolean. The lenient flag indicates if "yes", "on", and "1" should also be treated as true.
    • stringToChar

      public BasicFieldTransformer stringToChar()
      Converts values to their first character, or the NUL character for empty strings.
    • stringToDateTime

      public BasicFieldTransformer stringToDateTime(String pattern)
      Parses values as date-times using the given SimpleDateFormat pattern in the default time zone.
    • stringToDateTime

      public BasicFieldTransformer stringToDateTime(String pattern, String timeZoneId)
      Parses values as date-times using the given SimpleDateFormat pattern in the given time zone (an unknown ID falls back to GMT).
    • stringToDate

      public BasicFieldTransformer stringToDate(String pattern)
      Parses values as dates (java.sql.Date) using the given SimpleDateFormat pattern in the default time zone.
    • stringToDate

      public BasicFieldTransformer stringToDate(String pattern, String timeZoneId)
      Parses values as dates (java.sql.Date) using the given SimpleDateFormat pattern in the given time zone (an unknown ID falls back to GMT).
    • stringToTime

      public BasicFieldTransformer stringToTime(String pattern)
      Parses values as times (java.sql.Time) using the given SimpleDateFormat pattern in the default time zone.
    • stringToTime

      public BasicFieldTransformer stringToTime(String pattern, String timeZoneId)
      Parses values as times (java.sql.Time) using the given SimpleDateFormat pattern in the given time zone (an unknown ID falls back to GMT).
    • numberToInt

      public BasicFieldTransformer numberToInt()
      Converts numeric values to ints, truncating any fraction.
    • numberToLong

      public BasicFieldTransformer numberToLong()
      Converts numeric values to longs, truncating any fraction.
    • numberToBigInteger

      public BasicFieldTransformer numberToBigInteger()
      Converts numeric values to big integers, truncating any fraction.
    • numberToBigDecimal

      public BasicFieldTransformer numberToBigDecimal()
    • numberToDouble

      public BasicFieldTransformer numberToDouble()
    • numberToBoolean

      public BasicFieldTransformer numberToBoolean()
      Converts the field's value to true if non-zero, otherwise false.
    • numberToString

      public BasicFieldTransformer numberToString(DecimalFormat format)
      Formats numeric values with the given DecimalFormat, converting them to double first.
    • numberToString

      public BasicFieldTransformer numberToString(String pattern)
      Formats numeric values with a DecimalFormat of the given pattern, converting them to double first.
    • round

      public BasicFieldTransformer round(Rounder rounding)
      Rounds numeric values with the given Rounder, producing doubles.
    • numberToDateTime

      protected BasicFieldTransformer numberToDateTime(String operationName, long multiplier)
      Adds an operation named operationName that converts numbers to date-times by multiplying them by multiplier to get milliseconds since the epoch; other values are left unchanged.
    • numberToDateTime

      public BasicFieldTransformer numberToDateTime(long multiplier)
      Converts numbers to date-times by multiplying them by multiplier to get milliseconds since the epoch; other values are left unchanged.
    • millisecondsToDateTime

      public BasicFieldTransformer millisecondsToDateTime()
      Converts numbers of milliseconds since the epoch to date-times; other values are left unchanged.
    • secondsToDateTime

      public BasicFieldTransformer secondsToDateTime()
      Converts numbers of seconds since the epoch to date-times; other values are left unchanged.
    • minutesToDateTime

      public BasicFieldTransformer minutesToDateTime()
      Converts numbers of minutes since the epoch to date-times; other values are left unchanged.
    • hoursToDateTime

      public BasicFieldTransformer hoursToDateTime()
      Converts numbers of hours since the epoch to date-times; other values are left unchanged.
    • daysToDateTime

      public BasicFieldTransformer daysToDateTime()
      Converts numbers of days since the epoch to date-times; other values are left unchanged.
    • numberToDate

      protected BasicFieldTransformer numberToDate(String operationName, long multiplier)
      Adds an operation named operationName that converts numbers to dates by multiplying them by multiplier to get milliseconds since the epoch and clearing the time of day in the default time zone; other values are left unchanged.
    • numberToDate

      public BasicFieldTransformer numberToDate(long multiplier)
      Converts numbers to dates by multiplying them by multiplier to get milliseconds since the epoch and clearing the time of day in the default time zone; other values are left unchanged.
    • millisecondsToDate

      public BasicFieldTransformer millisecondsToDate()
      Converts numbers of milliseconds since the epoch to dates (midnight in the default time zone); other values are left unchanged.
    • secondsToDate

      public BasicFieldTransformer secondsToDate()
      Converts numbers of seconds since the epoch to dates (midnight in the default time zone); other values are left unchanged.
    • minutesToDate

      public BasicFieldTransformer minutesToDate()
      Converts numbers of minutes since the epoch to dates (midnight in the default time zone); other values are left unchanged.
    • hoursToDate

      public BasicFieldTransformer hoursToDate()
      Converts numbers of hours since the epoch to dates (midnight in the default time zone); other values are left unchanged.
    • daysToDate

      public BasicFieldTransformer daysToDate()
      Converts numbers of days since the epoch to dates (midnight in the default time zone); other values are left unchanged.
    • numberToInterval

      protected BasicFieldTransformer numberToInterval(String operationName, String unitName)
      Adds an operation named operationName that converts numbers to intervals of that many unitName units; other values are left unchanged.
    • numberToInterval

      public BasicFieldTransformer numberToInterval(String unitName)
      Converts numbers to intervals of that many unitName units (millisecond, second, minute, hour, day, week, month or year; singular or plural, any case); other values are left unchanged.
    • numberToMillisecond

      public BasicFieldTransformer numberToMillisecond()
      Converts numbers to intervals of that many milliseconds; other values are left unchanged.
    • numberToSeconds

      public BasicFieldTransformer numberToSeconds()
      Converts numbers to intervals of that many seconds; other values are left unchanged.
    • numberToMinutes

      public BasicFieldTransformer numberToMinutes()
      Converts numbers to intervals of that many minutes; other values are left unchanged.
    • numberToHours

      public BasicFieldTransformer numberToHours()
      Converts numbers to intervals of that many hours; other values are left unchanged.
    • numberToDays

      public BasicFieldTransformer numberToDays()
      Converts numbers to intervals of that many days; other values are left unchanged.
    • numberToMonths

      public BasicFieldTransformer numberToMonths()
      Converts numbers to intervals of that many months; other values are left unchanged.
    • numberToYears

      public BasicFieldTransformer numberToYears()
      Converts numbers to intervals of that many years; other values are left unchanged.
    • dateTimeToString

      public BasicFieldTransformer dateTimeToString(DateFormat format)
    • dateTimeToString

      public BasicFieldTransformer dateTimeToString(String pattern)
      Formats date-time values using the given SimpleDateFormat pattern in the default time zone.
    • dateTimeToString

      public BasicFieldTransformer dateTimeToString(String pattern, String timeZoneId)
      Formats date-time values using the given SimpleDateFormat pattern in the given time zone (an unknown ID falls back to GMT).
    • dateToString

      public BasicFieldTransformer dateToString(DateFormat format)
    • dateToString

      public BasicFieldTransformer dateToString(String pattern)
      Formats date values using the given SimpleDateFormat pattern in the default time zone.
    • dateToString

      public BasicFieldTransformer dateToString(String pattern, String timeZoneId)
      Formats date values using the given SimpleDateFormat pattern in the given time zone (an unknown ID falls back to GMT).
    • timeToString

      public BasicFieldTransformer timeToString(DateFormat format)
    • timeToString

      public BasicFieldTransformer timeToString(String pattern)
      Formats time values using the given SimpleDateFormat pattern in the default time zone.
    • timeToString

      public BasicFieldTransformer timeToString(String pattern, String timeZoneId)
      Formats time values using the given SimpleDateFormat pattern in the given time zone (an unknown ID falls back to GMT).
    • dateTimeToDate

      public BasicFieldTransformer dateTimeToDate()
    • dateTimeToTime

      public BasicFieldTransformer dateTimeToTime()
    • intervalToMilliseconds

      public BasicFieldTransformer intervalToMilliseconds()
      Converts intervals to their millisecond part as a long, ignoring any months and years.
    • intervalToSeconds

      public BasicFieldTransformer intervalToSeconds()
      Converts intervals to the whole seconds in their millisecond part as a long, ignoring any months and years.
    • intervalToMonths

      public BasicFieldTransformer intervalToMonths()
      Converts intervals to their month part as an int (a year counts as 12 months), ignoring days and smaller units.
    • intervalToYears

      public BasicFieldTransformer intervalToYears()
      Converts intervals to the whole years in their month part as an int, ignoring days and smaller units.
    • flattenToString

      public BasicFieldTransformer flattenToString(String fieldSeparator)
      Replaces array and record values with a string of their nested values separated by fieldSeparator; null fields are left as is.
    • emptyToNull

      public BasicFieldTransformer emptyToNull()
      Converts empty string to null, otherwise the original value is returned.
    • valueToNull

      public BasicFieldTransformer valueToNull(Object object)
      Converts a field to null if its value matches the specified parameter.
    • stringToUuid

      public BasicFieldTransformer stringToUuid()
      Parses values as UUIDs using UUID.fromString.
    • uuidToString

      public BasicFieldTransformer uuidToString()
    • bytesToUuid

      public BasicFieldTransformer bytesToUuid()
      Converts 16-byte values (most significant bits first) to UUIDs; other lengths cause an exception.
    • uuidToBytes

      public BasicFieldTransformer uuidToBytes()
      Converts UUIDs to 16-byte arrays, most significant bits first.