org.supercsv.cellprocessor.ift.StringCellProcessor Java Examples

The following examples show how to use org.supercsv.cellprocessor.ift.StringCellProcessor. 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 File: HalfCharFactory.java    From super-csv-annotation with 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 #2
Source File: TruncateFactory.java    From super-csv-annotation with 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 #3
Source File: MultiPadFactory.java    From super-csv-annotation with 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 #4
Source File: RegexReplaceFactory.java    From super-csv-annotation with 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 #5
Source File: FullCharFactory.java    From super-csv-annotation with 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 #6
Source File: PatternFactory.java    From super-csv-annotation with 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 #7
Source File: LeftPadFactory.java    From super-csv-annotation with 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 #8
Source File: RightPadFactory.java    From super-csv-annotation with 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 #9
Source File: PrintProcessorFactory.java    From super-csv-annotation with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: TrimFactory.java    From super-csv-annotation with 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 #11
Source File: RightPad.java    From super-csv-annotation with 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 File: LeftPad.java    From super-csv-annotation with 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 #13
Source File: NullConvertFactory.java    From super-csv-annotation with 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 #14
Source File: DefaultValueFactory.java    From super-csv-annotation with 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 #15
Source File: LowerFactory.java    From super-csv-annotation with 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 #16
Source File: OneSideTrimFactory.java    From super-csv-annotation with 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 #17
Source File: MultiPad.java    From super-csv-annotation with 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 #18
Source File: DefaultValue.java    From super-csv-annotation with Apache License 2.0 4 votes vote down vote up
public DefaultValue(final String returnValue, final StringCellProcessor next) {
    super(next);
    this.returnValue = returnValue;
}
 
Example #19
Source File: WordReplace.java    From super-csv-annotation with 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 #20
Source File: Pattern.java    From super-csv-annotation with 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 #21
Source File: Lower.java    From super-csv-annotation with Apache License 2.0 4 votes vote down vote up
public Lower(final StringCellProcessor next) {
    super(next);
}
 
Example #22
Source File: Upper.java    From super-csv-annotation with Apache License 2.0 4 votes vote down vote up
public Upper(final StringCellProcessor next) {
    super(next);
}
 
Example #23
Source File: HalfChar.java    From super-csv-annotation with 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 File: FullChar.java    From super-csv-annotation with 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 #25
Source File: Truncate.java    From super-csv-annotation with 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 #26
Source File: NullConvert.java    From super-csv-annotation with Apache License 2.0 3 votes vote down vote up
/**
 * 
 * @param tokens 比較対象の値
 * @param ignoreCase 大文字・小文字の区別を行うかどうか
 * @param next チェインとして次に実行されるCellProcessor
 * @throws NullPointerException {@literal tokens is null.}
 * @throws IllegalArgumentException {@literal tokens size is zero.}
 */
public NullConvert(final Collection<String> tokens, final boolean ignoreCase, final StringCellProcessor next) {
    super(next);
    checkPreconditions(tokens);
    this.tokens.addAll(toIgnoreCase(tokens, ignoreCase));
    this.ignoreCase = ignoreCase;
}
 
Example #27
Source File: StrReplace.java    From super-csv with 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 File: UpperFactory.java    From super-csv-annotation with Apache License 2.0 3 votes vote down vote up
@Override
public Optional<CellProcessor> create(final CsvUpper anno, final Optional<CellProcessor> next,
        final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
    
    final Upper processor = next.map(n ->  new Upper((StringCellProcessor) n))
            .orElseGet(() -> new Upper());
    
    return Optional.of(processor);
    
}
 
Example #29
Source File: RegexReplace.java    From super-csv-annotation with Apache License 2.0 3 votes vote down vote up
/**
 * 正規表現と置換文字を指定してインスタンスを作成するコンストラクタ。
 * 
 * @param pattern コンパイル済みの正規表現。
 * @param replacement 置換文字列
 * @param partialMatched 部分一致で検索するかどうか。
 * @param next チェインの中で呼ばれる次の{@link CellProcessor}.
 * @throws NullPointerException if pattern or replacement is null.
 */
public RegexReplace(final Pattern pattern, final String replacement, final boolean partialMatched,
        final StringCellProcessor next) {
    super(next);
    checkPreconditions(pattern, replacement);
    this.pattern = pattern;
    this.replacement = replacement;
    this.partialMatched = partialMatched;
}
 
Example #30
Source File: FmtNumber.java    From super-csv with 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;
}