001package org.unix4j.convert;
002
003public class ConcatenatedConverter<V> implements ValueConverter<V> {
004        
005        private final ValueConverter<?> first;
006        private final ValueConverter<V> second;
007        
008        public ConcatenatedConverter(ValueConverter<?> sourceConverter, ValueConverter<V> targetConverter) {
009                this.first = sourceConverter;
010                this.second = targetConverter;
011        }
012        
013        public static <V> ConcatenatedConverter<V> concat(ValueConverter<?> first, ValueConverter<V> second) {
014                return new ConcatenatedConverter<V>(first, second);
015        }
016        public <N> ConcatenatedConverter<N> concat(ValueConverter<N> next) {
017                return concat(this, next);
018        }
019        
020        @Override
021        public V convert(Object value) throws IllegalArgumentException {
022                final Object source = first.convert(value);
023                return second.convert(source);
024        }
025}