Java Code Examples for org.supercsv.cellprocessor.ift.StringCellProcessor

The following examples show how to use org.supercsv.cellprocessor.ift.StringCellProcessor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: super-csv-annotation   Source File: PatternFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvPattern anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final int flags = Utils.buildRegexFlags(anno.flags());
    final java.util.regex.Pattern pattern;
    try {
        pattern = java.util.regex.Pattern.compile(anno.regex(), flags);
        
    } catch(PatternSyntaxException e) {
        throw new SuperCsvInvalidAnnotationException(anno, MessageBuilder.create("anno.attr.invalidType")
                .var("property", field.getNameWithClass())
                .varWithAnno("anno", anno.annotationType())
                .var("attrName", "regex")
                .var("attrValue", anno.regex())
                .var("type", "{key.regex}")
                .format(true));
    }
    
    final Pattern processor = next.map(n -> new Pattern(pattern, anno.description(), (StringCellProcessor)n))
            .orElseGet(() -> new Pattern(pattern, anno.description()));
    
    processor.setValidationMessage(anno.message());
    
    return Optional.of(processor);
}
 
Example 2
Source Project: super-csv-annotation   Source File: RightPadFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvRightPad anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    if(anno.size() <= 0) {
        throw new SuperCsvInvalidAnnotationException(anno, MessageBuilder.create("anno.attr.min")
                .var("property", field.getNameWithClass())
                .varWithAnno("anno", anno.annotationType())
                .var("attrName", "size")
                .var("attrValue", anno.size())
                .var("min", 1)
                .format());
    }
    
    final RightPad processor = next.map(n -> new RightPad(anno.size(), anno.padChar(), (StringCellProcessor)n))
            .orElseGet(() -> new RightPad(anno.size(), anno.padChar()));
    
    return Optional.of(processor);
}
 
Example 3
Source Project: super-csv-annotation   Source File: FullCharFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvFullChar anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final CharCategory[] categories;
    if(anno.categories().length == 0) {
        categories = CharCategory.values();
    } else {
        categories = anno.categories();
    }
    
    final FullChar processor = next.map(n -> new FullChar(categories, (StringCellProcessor) n))
            .orElseGet(() -> new FullChar(categories));
    
    return Optional.of(processor);
}
 
Example 4
Source Project: super-csv-annotation   Source File: HalfCharFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvHalfChar anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final CharCategory[] categories;
    if(anno.categories().length == 0) {
        categories = CharCategory.values();
    } else {
        categories = anno.categories();
    }
    
    final HalfChar processor = next.map(n -> new HalfChar(categories, (StringCellProcessor) n))
            .orElseGet(() -> new HalfChar(categories));
    
    return Optional.of(processor);
}
 
Example 5
Source Project: super-csv-annotation   Source File: LeftPadFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvLeftPad anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    if(anno.size() <= 0) {
        throw new SuperCsvInvalidAnnotationException(anno, MessageBuilder.create("anno.attr.min")
                .var("property", field.getNameWithClass())
                .varWithAnno("anno", anno.annotationType())
                .var("attrName", "size")
                .var("attrValue", anno.size())
                .var("min", 1)
                .format());
    }
    
    final LeftPad processor = next.map(n -> new LeftPad(anno.size(), anno.padChar(), (StringCellProcessor)n))
            .orElseGet(() -> new LeftPad(anno.size(), anno.padChar()));
    
    return Optional.of(processor);
}
 
Example 6
Source Project: super-csv-annotation   Source File: RegexReplaceFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvRegexReplace anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final int flags = Utils.buildRegexFlags(anno.flags());
    final Pattern pattern;
    try {
        pattern = Pattern.compile(anno.regex(), flags);
    } catch(PatternSyntaxException e) {
        throw new SuperCsvInvalidAnnotationException(anno, MessageBuilder.create("anno.attr.invalidType")
                .var("property", field.getNameWithClass())
                .varWithAnno("anno", anno.annotationType())
                .var("attrName", "regex")
                .var("attrValue", anno.regex())
                .var("type", "{key.regex}")
                .format(true));
    }
    
    final String replacement = anno.replacement();
    final boolean partialMatched = anno.partialMatched();
    
    final RegexReplace processor = next.map(n ->  new RegexReplace(pattern, replacement, partialMatched, (StringCellProcessor) n))
            .orElseGet(() -> new RegexReplace(pattern, replacement, partialMatched));
    
    return Optional.of(processor);
}
 
Example 7
Source Project: super-csv-annotation   Source File: MultiPadFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvMultiPad anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    if(anno.size() <= 0) {
        throw new SuperCsvInvalidAnnotationException(anno,
                MessageBuilder.create("anno.attr.min")
                    .var("property", field.getNameWithClass())
                    .varWithAnno("anno", anno.annotationType())
                    .var("attrName", "size")
                    .var("attrValue", anno.size())
                    .var("min", 1)
                    .format());
    }
    
    final PaddingProcessor paddingProcessor = (PaddingProcessor)config.getBeanFactory().create(anno.paddingProcessor());
    
    final MultiPad processor = next.map(n -> new MultiPad(anno.size(), anno.padChar(), anno.rightAlign(),
                anno.chopped(), paddingProcessor, (StringCellProcessor)n))
            .orElseGet(() -> new MultiPad(anno.size(), anno.padChar(), anno.rightAlign(),
                    anno.chopped(), paddingProcessor));
    
    return Optional.of(processor);
}
 
Example 8
Source Project: super-csv-annotation   Source File: TruncateFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvTruncate anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    if(anno.maxSize() <= 0) {
        throw new SuperCsvInvalidAnnotationException(anno, MessageBuilder.create("anno.attr.min")
                .var("property", field.getNameWithClass())
                .varWithAnno("anno", anno.annotationType())
                .var("attrName", "maxSize")
                .var("attrValue", anno.maxSize())
                .var("min", 1)
                .format());
    }
    
    final Truncate processor = next.map(n -> new Truncate(anno.maxSize(), anno.suffix(), (StringCellProcessor)n))
            .orElseGet(() -> new Truncate(anno.maxSize(), anno.suffix()));
    
    return Optional.of(processor);
}
 
Example 9
Source Project: super-csv-annotation   Source File: DefaultValueFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvDefaultValue anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final DefaultValue processor = next.map(n ->  new DefaultValue(anno.value(), (StringCellProcessor) n))
            .orElseGet(() -> new DefaultValue(anno.value()));
    
    return Optional.of(processor);
}
 
Example 10
Source Project: super-csv-annotation   Source File: NullConvertFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvNullConvert anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final Set<String> tokens = Arrays.stream(anno.value())
            .collect(Collectors.toSet());
    
    final NullConvert processor = next.map(n -> new NullConvert(tokens, anno.ignoreCase(), (StringCellProcessor)n))
            .orElseGet(() -> new NullConvert(tokens, anno.ignoreCase()));
    
    return Optional.of(processor);
}
 
Example 11
Source Project: super-csv-annotation   Source File: RightPad.java    License: Apache License 2.0 5 votes vote down vote up
public RightPad(final int padSize, final char padChar, final StringCellProcessor next) {
    super(next);
    
    checkPreconditions(padSize);
    this.padSize = padSize;
    this.padChar = padChar;
}
 
Example 12
Source Project: super-csv-annotation   Source File: TrimFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvTrim anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final Trim processor = next.map(n -> new Trim((StringCellProcessor)n))
            .orElseGet(() -> new Trim());
    
    return Optional.of(processor);
}
 
Example 13
Source Project: super-csv-annotation   Source File: LeftPad.java    License: Apache License 2.0 5 votes vote down vote up
public LeftPad(final int padSize, final char padChar, final StringCellProcessor next) {
    super(next);
    
    checkPreconditions(padSize);
    this.padSize = padSize;
    this.padChar = padChar;
}
 
Example 14
Source Project: super-csv-annotation   Source File: LowerFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvLower anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final Lower processor = next.map(n ->  new Lower((StringCellProcessor) n))
            .orElseGet(() -> new Lower());
    
    return Optional.of(processor);
}
 
Example 15
Source Project: super-csv-annotation   Source File: OneSideTrimFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvOneSideTrim anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final OneSideTrim processor = next.map(n -> new OneSideTrim(anno.trimChar(), anno.leftAlign(), (StringCellProcessor)n))
            .orElseGet(() -> new OneSideTrim(anno.trimChar(), anno.leftAlign()));
    
    return Optional.of(processor);
}
 
Example 16
Source Project: super-csv-annotation   Source File: MultiPad.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param size パディングのサイズ
 * @param padChar パディングする文字。
 * @param rightAlign 右詰めするかどうか。
 * @param chopped 処理対象の文字が固定長を超えている場合に、切り出すかどうか。
 * @param paddingProcessor パディング処理の実装
 * @param next チェインの中で呼ばれる次の{@link CellProcessor}.
 * @throws IllegalArgumentException {@literal length <= 0.}
 */
public MultiPad(final int size, final char padChar, final boolean rightAlign, final boolean chopped,
        final PaddingProcessor paddingProcessor, final StringCellProcessor next) {
    super(next);

    checkPreconditions(size, paddingProcessor);

    this.size = size;
    this.padChar = padChar;
    this.rightAlign = rightAlign;
    this.chopped = chopped;
    this.paddingProcessor = paddingProcessor;
}
 
Example 17
@Override
public Optional<CellProcessor> create(final Optional<CellProcessor> next, final FieldAccessor field,
        final TextFormatter<?> formatter, final Configuration config,
        final BuildCase buildCase, final Class<?>[] groups) {
    
    @SuppressWarnings("unchecked")
    final TextFormatter<T> typeFormatter = (TextFormatter<T>)formatter;
    
    final PrintProcessor<T> processor = next.map(n -> new PrintProcessor<>(typeFormatter, (StringCellProcessor)n))
            .orElseGet(() -> new PrintProcessor<>(typeFormatter));
    
    return Optional.of(processor);
    
}
 
Example 18
Source Project: super-csv-annotation   Source File: Pattern.java    License: Apache License 2.0 4 votes vote down vote up
public Pattern(final java.util.regex.Pattern regexPattern, final String regexDescriptoin, final StringCellProcessor next) {
    super(next);
    checkPreconditions(regexPattern);
    this.pattern = regexPattern;
    this.description = regexDescriptoin;
}
 
Example 19
Source Project: super-csv-annotation   Source File: DefaultValue.java    License: Apache License 2.0 4 votes vote down vote up
public DefaultValue(final String returnValue, final StringCellProcessor next) {
    super(next);
    this.returnValue = returnValue;
}
 
Example 20
Source Project: super-csv-annotation   Source File: WordReplace.java    License: Apache License 2.0 4 votes vote down vote up
public WordReplace(final CharReplacer replacer, final StringCellProcessor next) {
    super(next);
    checkPreconditions(replacer);
    this.replacer = replacer;
}
 
Example 21
Source Project: super-csv-annotation   Source File: Lower.java    License: Apache License 2.0 4 votes vote down vote up
public Lower(final StringCellProcessor next) {
    super(next);
}
 
Example 22
Source Project: super-csv-annotation   Source File: Upper.java    License: Apache License 2.0 4 votes vote down vote up
public Upper(final StringCellProcessor next) {
    super(next);
}
 
Example 23
Source Project: super-csv-annotation   Source File: HalfChar.java    License: Apache License 2.0 4 votes vote down vote up
public HalfChar(final CharCategory[] categories, final StringCellProcessor next) {
    super(next);
    checkPreconditions(categories);
    this.categories = categories;
    this.replacer = new JapaneseCharReplacer(categories);
}
 
Example 24
Source Project: super-csv-annotation   Source File: Truncate.java    License: Apache License 2.0 4 votes vote down vote up
public Truncate(final int maxSize, final String suffix, final StringCellProcessor next) {
    super(next);
    checkPreconditions(maxSize, suffix);
    this.maxSize = maxSize;
    this.suffix = suffix;
}
 
Example 25
Source Project: super-csv-annotation   Source File: FullChar.java    License: Apache License 2.0 4 votes vote down vote up
public FullChar(final CharCategory[] categories, final StringCellProcessor next) {
    super(next);
    checkPreconditions(categories);
    this.categories = categories;
    this.replacer = new JapaneseCharReplacer(categories);
}
 
Example 26
Source Project: super-csv   Source File: StrRegEx.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new <tt>StrRegEx</tt> processor, which ensures that the input data matches the given regular
 * expression, then calls the next processor in the chain.
 * 
 * @param regex
 *            the regular expression to match
 * @param next
 *            the next processor in the chain
 * @throws NullPointerException
 *             if regex is null
 * @throws IllegalArgumentException
 *             if regex is empty
 * @throws PatternSyntaxException
 *             if regex is not a valid regular expression
 */
public StrRegEx(final String regex, final StringCellProcessor next) {
	super(next);
	checkPreconditions(regex);
	this.regexPattern = Pattern.compile(regex);
	this.regex = regex;
}
 
Example 27
Source Project: super-csv   Source File: StrReplace.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new <tt>StrReplace</tt> processor, which replaces each substring of the input that matches the regex
 * with the supplied replacement, then calls the next processor in the chain.
 * 
 * @param regex
 *            the regular expression to match
 * @param replacement
 *            the string to be substituted for each match
 * @param next
 *            the next processor in the chain
 * @throws IllegalArgumentException
 *             if regex is empty
 * @throws NullPointerException
 *             if regex or replacement is null
 * @throws PatternSyntaxException
 *             if regex is not a valid regular expression
 */
public StrReplace(final String regex, final String replacement, final StringCellProcessor next) {
	super(next);
	checkPreconditions(regex, replacement);
	this.regexPattern = Pattern.compile(regex);
	this.replacement = replacement;
}
 
Example 28
Source Project: super-csv   Source File: Truncate.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new <tt>Truncate</tt> processor, which truncates a String to ensure it is no longer than the
 * specified size, then appends the <code>suffix</code> String to indicate that the String has been truncated and
 * calls the next processor in the chain.
 * 
 * @param maxSize
 *            the maximum size of the String
 * @param suffix
 *            the String to append if the input is truncated (e.g. "...")
 * @param next
 *            the next processor in the chain
 * @throws IllegalArgumentException
 *             if {@code maxSize <= 0}
 * @throws NullPointerException
 *             if suffix or next is null
 */
public Truncate(final int maxSize, final String suffix, final StringCellProcessor next) {
	super(next);
	checkPreconditions(maxSize, suffix);
	this.maxSize = maxSize;
	this.suffix = suffix;
}
 
Example 29
Source Project: super-csv   Source File: FmtNumber.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new <tt>FmtNumber</tt> processor, which converts a double into a formatted string using the supplied
 * decimal format String, then calls the next processor in the chain. This constructor is thread-safe.
 * 
 * @param decimalFormat
 *            the decimal format String (see {@link DecimalFormat})
 * @param next
 *            the next processor in the chain
 * @throws NullPointerException
 *             if decimalFormat or next is null
 */
public FmtNumber(final String decimalFormat, final StringCellProcessor next) {
	super(next);
	checkPreconditions(decimalFormat);
	this.decimalFormat = decimalFormat;
	this.formatter = null;
}
 
Example 30
Source Project: super-csv   Source File: FmtNumber.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new <tt>FmtNumber</tt> processor, which converts a double into a formatted string using the supplied
 * decimal format, then calls the next processor in the chain. This constructor is not thread-safe.
 * 
 * @param formatter
 *            the DecimalFormat
 * @param next
 *            the next processor in the chain
 * @throws NullPointerException
 *             if formatter or next is null
 */
public FmtNumber(final DecimalFormat formatter, final StringCellProcessor next) {
	super(next);
	checkPreconditions(formatter);
	this.formatter = formatter;
	this.decimalFormat = null;
}