org.srplib.conversion.ChainConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of srp-conversion-support Show documentation
Show all versions of srp-conversion-support Show documentation
Single Responsibility Principle (SRP) libraries collection
package org.srplib.conversion;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.srplib.contract.Argument;
/**
* Converter chain converter.
*
* Sequentially invokes aggregated converters.
*
* @author Anton Pechinsky
*/
public class ChainConverter implements Converter {
private List converters = new ArrayList();
public ChainConverter(List converters) {
Argument.checkNotNull(converters, "Converters list should not be null.");
this.converters = converters;
}
public ChainConverter(Converter... converters) {
this(Arrays.asList(converters));
}
@Override
@SuppressWarnings("unchecked")
public O convert(I input) {
Object value = input;
for (Converter converter : converters) {
value = converter.convert(value);
}
return (O) value;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy