Class FieldModifiers

java.lang.Object
de.siegmar.fastcsv.reader.FieldModifiers

public final class FieldModifiers extends Object

Provides some common FieldModifier implementations.

Example usage:

FieldModifier modifier = FieldModifiers.TRIM
    .andThen(FieldModifiers.modify(field -> field.toUpperCase(Locale.ENGLISH)));
CsvRecordHandler handler = CsvRecordHandler.of(c -> c.fieldModifier(modifier));
List<CsvRecord> records = CsvReader.builder()
    .build(handler, "  foo   ,   bar")
    .stream()
    .collect(Collectors.toList());

// fields would be: "FOO" and "BAR"
  • Field Details

    • NOP

      public static final FieldModifier NOP
      Modifier that does not modify anything.
    • TRIM

      public static final FieldModifier TRIM
      Modifier that modifies the field value with String.trim(). Comments are not modified.
    • STRIP

      public static final FieldModifier STRIP
      Modifier that modifies the field value with String.strip(). Comments are not modified.
  • Method Details

    • lower

      @Deprecated(since="3.7.0", forRemoval=true) public static FieldModifier lower(Locale locale)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use modify(Function) instead.
      Builds modifier that modifies the field value with String.toLowerCase(Locale). Comments are not modified.
      Parameters:
      locale - use the case transformation rules for this locale
      Returns:
      a new field modifier that converts the input to lower-case.
    • upper

      @Deprecated(since="3.7.0", forRemoval=true) public static FieldModifier upper(Locale locale)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use modify(Function) instead.
      Builds modifier that modifies the field value with String.toUpperCase(Locale). Comments are not modified.
      Parameters:
      locale - use the case transformation rules for this locale
      Returns:
      a new field modifier that converts the input to upper-case.
    • modify

      public static FieldModifier modify(Function<? super String, String> function)
      Builds a modifier that modifies the field value using the provided function. Comments are not modified.
      Parameters:
      function - the function to modify the field value. The contract of FieldModifier.modify(long, int, boolean, String) applies: the value passed to the function is never null and the return value must not be null.
      Returns:
      a new field modifier that applies the function to the field value
      Throws:
      NullPointerException - if the function is null