org.unix4j.convert.CharacterConverters Maven / Gradle / Ivy
package org.unix4j.convert;
public class CharacterConverters {
public static final ValueConverter INTEGER_TO_CHARACTER = new ValueConverter() {
@Override
public Character convert(Object value) throws IllegalArgumentException {
if (value instanceof Integer) {
return (char)((Integer)value).intValue();
}
return null;
}
};
public static final ValueConverter STRING_TO_CHARACTER = new ValueConverter() {
@Override
public Character convert(Object value) throws IllegalArgumentException {
if (value != null) {
final String s = value.toString();
if (s.length() > 0) {
return s.charAt(0);
}
}
return null;
}
};
public static final ValueConverter DEFAULT = new CompositeValueConverter().add(INTEGER_TO_CHARACTER).add(STRING_TO_CHARACTER);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy