cdc.util.enums.StringToMask Maven / Gradle / Ivy
package cdc.util.enums;
import java.util.List;
import cdc.util.args.Args;
import cdc.util.args.FormalArg;
import cdc.util.args.FormalArgs;
import cdc.util.args.Necessity;
import cdc.util.converters.Converter;
import cdc.util.converters.defaults.AbstractStringToSequence;
import cdc.util.lang.Introspection;
/**
* Converter from a string to a mask.
*
* @author Damien Carbonne
*
* @param The mask type.
* @param The value type.
*/
public class StringToMask, V> extends AbstractStringToSequence {
private final MaskSupport support;
private final Converter converter;
public static final FormalArg> SUPPORT =
new FormalArg<>("support", Introspection.uncheckedCast(MaskSupport.class), Necessity.MANDATORY);
public static final FormalArg> CONVERTER =
new FormalArg<>("converter", Introspection.uncheckedCast(Converter.class), Necessity.MANDATORY);
public static final FormalArgs FPARAMS =
new FormalArgs(PREFIX,
SEPARATOR,
SUFFIX,
TRIM,
SUPPORT,
CONVERTER);
public StringToMask(MaskSupport maskSupport,
String prefix,
String separator,
String suffix,
Converter converter,
boolean trim) {
super(maskSupport.getMaskClass(), prefix, separator, suffix, trim);
this.support = maskSupport;
this.converter = converter;
}
public final MaskSupport getMaskSupport() {
return support;
}
public final Converter getConverter() {
return converter;
}
@Override
public M apply(String s) {
final List list = toList(s, converter);
return support.create(list);
}
@Override
public Args getParams() {
return Args.builder()
.setArg(PREFIX, getPrefix())
.setArg(SEPARATOR, getSeparator())
.setArg(SUFFIX, getSuffix())
.setArg(TRIM, getTrim())
.setArg(SUPPORT, getMaskSupport())
.setArg(CONVERTER, getConverter())
.build();
}
}