001package org.unix4j.convert;
002
003public class CharacterConverters {
004        public static final ValueConverter<Character> INTEGER_TO_CHARACTER = new ValueConverter<Character>() {
005                @Override
006                public Character convert(Object value) throws IllegalArgumentException {
007                        if (value instanceof Integer) {
008                                return (char)((Integer)value).intValue();
009                        }
010                        return null;
011                }
012        };
013        public static final ValueConverter<Character> STRING_TO_CHARACTER = new ValueConverter<Character>() {
014                @Override
015                public Character convert(Object value) throws IllegalArgumentException {
016                        if (value != null) {
017                                final String s = value.toString();
018                                if (s.length() > 0) {
019                                        return s.charAt(0);
020                                }
021                        }
022                        return null;
023                }
024        };
025        public static final ValueConverter<Character> DEFAULT = new CompositeValueConverter<Character>().add(INTEGER_TO_CHARACTER).add(STRING_TO_CHARACTER);
026}